X-Git-Url: http://git.megacz.com/?p=org.ibex.js.git;a=blobdiff_plain;f=src%2Forg%2Fibex%2Fjs%2FDirectory.java;h=17adab7e464290a874537303b00b39f35409aa8e;hp=e9f7b955a027b1d7a5d1b34f6a2e70fe7c5ea70c;hb=d111fd7138333e05149dc2bfd486f65d73af60ec;hpb=a9010e65b3e6bcd993faf55ce8f05d73c20ddff0 diff --git a/src/org/ibex/js/Directory.java b/src/org/ibex/js/Directory.java index e9f7b95..17adab7 100644 --- a/src/org/ibex/js/Directory.java +++ b/src/org/ibex/js/Directory.java @@ -76,10 +76,13 @@ public class Directory extends JS { } } else { OutputStream out = new FileOutputStream(f2); - Writer w = new OutputStreamWriter(out); - w.write(toString(val)); - w.flush(); - out.close(); + try { + Writer w = new OutputStreamWriter(out); + w.write(toString(val)); + w.flush(); + } finally { + out.close(); + } } } catch (IOException ioe) { throw new JSExn.IO(ioe); @@ -87,6 +90,7 @@ public class Directory extends JS { } public Object get(Object key0) throws JSExn { + FileInputStream fis = null; try { if (key0 == null) return null; String key = toString(key0); @@ -95,7 +99,8 @@ public class Directory extends JS { if (f2.isDirectory()) return new Directory(f2); char[] chars = new char[((int)f2.length()) * 2]; int numchars = 0; - Reader r = new InputStreamReader(new FileInputStream(f2)); + fis = new FileInputStream(f2); + Reader r = new InputStreamReader(fis); while(true) { int numread = r.read(chars, numchars, chars.length - numchars); if (numread == -1) return new String(chars, 0, numchars); @@ -103,6 +108,12 @@ public class Directory extends JS { } } catch (IOException ioe) { throw new JSExn.IO(ioe); + } finally { + try { + if (fis != null) fis.close(); + } catch (IOException ioe) { + throw new JSExn.IO(ioe); + } } }