X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fibex%2Fjs%2FDirectory.java;h=a44cc77f226ccd6458a5c76d0da654fd419f61cf;hb=404a953676d6b3bfcd122a42c1d4ea0d8ffb4f74;hp=645de0dfac93e37ea8e352ebb123d445506c6c5c;hpb=73131826a18c93af4fb04672bc3ec820e1197ad1;p=org.ibex.js.git diff --git a/src/org/ibex/js/Directory.java b/src/org/ibex/js/Directory.java index 645de0d..a44cc77 100644 --- a/src/org/ibex/js/Directory.java +++ b/src/org/ibex/js/Directory.java @@ -5,7 +5,6 @@ package org.ibex.js; import org.ibex.util.*; -import java.util.*; import java.io.*; // FEATURE: support for move @@ -38,7 +37,7 @@ import java.io.*; * argument that points to a non-directory File, this class will * delete that file and create a directory! */ -public class Directory extends JS { +public class Directory extends JS.Immutable { File f; @@ -66,21 +65,21 @@ public class Directory extends JS { public void put(JS key0, JS val) throws JSExn { try { if (key0 == null) return; - String key = toString(key0); - File f2 = new File(f.getAbsolutePath() + File.separatorChar + FileNameEncoder.encode(key)); + String key = JSU.toString(key0); + File f2 = new File(f.getAbsolutePath() + File.separatorChar + Encode.toFilename(key)); destroy(f2); if (val == null) return; if (val instanceof JSPrimitive) { OutputStream out = new FileOutputStream(f2); Writer w = new OutputStreamWriter(out); - w.write(toString(val)); + w.write(JSU.toString(val)); w.flush(); out.close(); } else { Directory d2 = new Directory(f2); JS.Enumeration e = val.keys(); - while(e.hasMoreElements()) { - JS k = e.nextElement(); + while(e.hasNext()) { + JS k = e.next(); JS v = val.get(k); d2.put(k, v); } @@ -93,16 +92,16 @@ public class Directory extends JS { public JS get(JS key0) throws JSExn { try { if (key0 == null) return null; - String key = toString(key0); - File f2 = new File(f.getAbsolutePath() + File.separatorChar + FileNameEncoder.encode(key)); + String key = JSU.toString(key0); + File f2 = new File(f.getAbsolutePath() + File.separatorChar + Encode.toFilename(key)); if (!f2.exists()) return null; if (f2.isDirectory()) return new Directory(f2); - char[] chars = new char[((int)f2.length()) * 2]; + char[] chars = new char[((int)f2.length()) * 4 + 10]; int numchars = 0; Reader r = new InputStreamReader(new FileInputStream(f2)); while(true) { int numread = r.read(chars, numchars, chars.length - numchars); - if (numread == -1) return JS.S(new String(chars, 0, numchars)); + if (numread == -1) return JSU.S(new String(chars, 0, numchars)); numchars += numread; } } catch (IOException ioe) { @@ -110,12 +109,12 @@ public class Directory extends JS { } } - public Enumeration keys() { + public JS.Enumeration keys() { final String[] elements = f.list(); - return new Enumeration(null) { + return new JS.Enumeration(null) { int i = 0; - public boolean _hasMoreElements() { return i < elements.length; } - public JS _nextElement() { return JS.S(FileNameEncoder.decode(elements[i++])); } + public boolean _hasNext() { return i < elements.length; } + public JS _next() { return JSU.S(Encode.fromFilename(elements[i++])); } }; } }