filestreams closed on save too

This commit is contained in:
Maxmtg
2013-06-03 22:59:21 +00:00
parent 1bca2ac7ac
commit 1f28e96583

View File

@@ -70,12 +70,10 @@ public final class SLayoutIO {
throw new IllegalThreadStateException("This operation should be independent of the EDT."); throw new IllegalThreadStateException("This operation should be independent of the EDT.");
} }
try { save(f0); } save(f0);
catch (final Exception e) { e.printStackTrace(); }
} }
private synchronized static void save(final File f0) throws Exception { private synchronized static void save(final File f0) {
final String fWriteTo; final String fWriteTo;
FileLocation file = SLayoutIO.getFileForState(Singletons.getControl().getState()); FileLocation file = SLayoutIO.getFileForState(Singletons.getControl().getState());
@@ -90,7 +88,11 @@ public final class SLayoutIO {
} }
final XMLOutputFactory out = XMLOutputFactory.newInstance(); final XMLOutputFactory out = XMLOutputFactory.newInstance();
final XMLEventWriter writer = out.createXMLEventWriter(new FileOutputStream(fWriteTo)); FileOutputStream fos = null;
XMLEventWriter writer = null;
try {
fos = new FileOutputStream(fWriteTo);
writer = out.createXMLEventWriter(fos);
final List<DragCell> cells = FView.SINGLETON_INSTANCE.getDragCells(); final List<DragCell> cells = FView.SINGLETON_INSTANCE.getDragCells();
writer.add(EF.createStartDocument()); writer.add(EF.createStartDocument());
@@ -118,10 +120,21 @@ public final class SLayoutIO {
writer.add(EF.createEndElement("", "", "cell")); writer.add(EF.createEndElement("", "", "cell"));
writer.add(NEWLINE); writer.add(NEWLINE);
} }
writer.add(EF.createEndDocument());
writer.flush(); writer.flush();
writer.close(); writer.add(EF.createEndDocument());
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block ignores the exception, but sends it to System.err and probably forge.log.
e.printStackTrace();
} catch (XMLStreamException e) {
// TODO Auto-generated catch block ignores the exception, but sends it to System.err and probably forge.log.
e.printStackTrace();
} finally {
if ( writer != null )
try { writer.close(); } catch (XMLStreamException e) {}
if ( fos != null )
try { fos.close(); } catch (IOException e) {}
}
} }
public static void loadLayout(final File f) { public static void loadLayout(final File f) {