| author | Thomas Watson | 2011-03-15 15:18:15 (EDT) |
|---|---|---|
| committer | Glyn Normington | 2011-03-15 15:18:15 (EDT) |
| commit | c095ad6432f4459f1e08970bbab6d09652f68196 (patch) (side-by-side diff) | |
| tree | 237a2b8a4194230c3046658de539ca05f5258648 | |
| parent | 71dc59510d788b0753446b4c7fb0539822fbc7c0 (diff) | |
| download | org.eclipse.virgo.kernel-c095ad6432f4459f1e08970bbab6d09652f68196.zip org.eclipse.virgo.kernel-c095ad6432f4459f1e08970bbab6d09652f68196.tar.gz org.eclipse.virgo.kernel-c095ad6432f4459f1e08970bbab6d09652f68196.tar.bz2 | |
Do not close streams on read/write of digraph.
| -rw-r--r-- | org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/internal/StandardRegionDigraphPersistence.java | 61 |
1 files changed, 18 insertions, 43 deletions
diff --git a/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/internal/StandardRegionDigraphPersistence.java b/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/internal/StandardRegionDigraphPersistence.java index 61c5875..cfbe4c6 100644 --- a/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/internal/StandardRegionDigraphPersistence.java +++ b/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/internal/StandardRegionDigraphPersistence.java @@ -46,7 +46,6 @@ final class StandardRegionDigraphPersistence implements RegionDigraphPersistence + digraph.getClass().getName()); Map<Region, Set<FilteredRegion>> filteredRegions = ((StandardRegionDigraph) digraph).getFilteredRegions(); - boolean exception = false; try { // write the number of regions out.writeInt(filteredRegions.size()); @@ -64,16 +63,9 @@ final class StandardRegionDigraphPersistence implements RegionDigraphPersistence writeEdge(out, edges.getKey(), edge.getFilter(), edge.getRegion()); } } - } catch (IOException e) { - exception = true; - throw e; } finally { - try { - out.close(); - } catch (IOException e) { - if (!exception) - throw e; - } + // note that the output is flushed even on exception + out.flush(); } } @@ -116,40 +108,23 @@ final class StandardRegionDigraphPersistence implements RegionDigraphPersistence static RegionDigraph readRegionDigraph(DataInputStream in, BundleContext systemBundleContext, ThreadLocal<Region> threadLocal) throws IOException, InvalidSyntaxException, BundleException { RegionDigraph digraph = new StandardRegionDigraph(systemBundleContext, threadLocal); - boolean exception = false; - try { - // read the number of regions - int numRegions = in.readInt(); - for (int i = 0; i < numRegions; i++) { - readRegion(in, digraph); - } - // read each edge - // read number of tail regions - int numTails = in.readInt(); - for (int i = 0; i < numTails; i++) { - // read the number of edges for this tail - int numEdges = in.readInt(); - for (int j = 0; j < numEdges; j++) { - readEdge(in, digraph); - } - } - } catch (IOException e) { - exception = true; - throw e; - } catch (InvalidSyntaxException e) { - exception = true; - throw e; - } catch (BundleException e) { - exception = true; - throw e; - } finally { - try { - in.close(); - } catch (IOException e) { - if (!exception) - throw e; + + // read the number of regions + int numRegions = in.readInt(); + for (int i = 0; i < numRegions; i++) { + readRegion(in, digraph); + } + // read each edge + // read number of tail regions + int numTails = in.readInt(); + for (int i = 0; i < numTails; i++) { + // read the number of edges for this tail + int numEdges = in.readInt(); + for (int j = 0; j < numEdges; j++) { + readEdge(in, digraph); } } + return digraph; } @@ -214,7 +189,7 @@ final class StandardRegionDigraphPersistence implements RegionDigraphPersistence throw new IllegalStateException("Internal error reading a filter", e); } catch (BundleException e) { // This should never happen since the digraph was valid on save - // propagate as IO ex + // propagate as IllegalStateException throw new IllegalStateException("Internal error creating the digraph", e); } } |

