X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fibex%2Fjs%2FDirectory.java;h=645de0dfac93e37ea8e352ebb123d445506c6c5c;hb=73131826a18c93af4fb04672bc3ec820e1197ad1;hp=e9f7b955a027b1d7a5d1b34f6a2e70fe7c5ea70c;hpb=b1fa73c17b31f268fca5695d0876d7314fbacce3;p=org.ibex.js.git diff --git a/src/org/ibex/js/Directory.java b/src/org/ibex/js/Directory.java index e9f7b95..645de0d 100644 --- a/src/org/ibex/js/Directory.java +++ b/src/org/ibex/js/Directory.java @@ -1,4 +1,7 @@ -// Copyright 2004 Adam Megacz, see the COPYING file for licensing [GPL] +// Copyright 2000-2005 the Contributors, as shown in the revision logs. +// Licensed under the Apache Public Source License 2.0 ("the License"). +// You may not use this file except in compliance with the License. + package org.ibex.js; import org.ibex.util.*; @@ -43,6 +46,7 @@ public class Directory extends JS { * Create the directory object. Existing directories will be * preserved; if a file is present it will be obliterated. */ + public Directory(File f) throws IOException { this.f = f; if (!f.exists()) new Directory(new File(f.getParent())); @@ -59,34 +63,34 @@ public class Directory extends JS { f.delete(); } - public void put(Object key0, Object val) throws JSExn { + 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)); destroy(f2); if (val == null) return; - if (val instanceof JS) { - Directory d2 = new Directory(f2); - Enumeration e = ((JS)val).keys(); - while(e.hasMoreElements()) { - String k = (String)e.nextElement(); - Object v = ((JS)val).get(k); - d2.put(k, v); - } - } else { + if (val instanceof JSPrimitive) { OutputStream out = new FileOutputStream(f2); Writer w = new OutputStreamWriter(out); w.write(toString(val)); w.flush(); out.close(); + } else { + Directory d2 = new Directory(f2); + JS.Enumeration e = val.keys(); + while(e.hasMoreElements()) { + JS k = e.nextElement(); + JS v = val.get(k); + d2.put(k, v); + } } } catch (IOException ioe) { throw new JSExn.IO(ioe); } } - public Object get(Object key0) throws JSExn { + public JS get(JS key0) throws JSExn { try { if (key0 == null) return null; String key = toString(key0); @@ -98,7 +102,7 @@ public class Directory extends JS { Reader r = new InputStreamReader(new FileInputStream(f2)); while(true) { int numread = r.read(chars, numchars, chars.length - numchars); - if (numread == -1) return new String(chars, 0, numchars); + if (numread == -1) return JS.S(new String(chars, 0, numchars)); numchars += numread; } } catch (IOException ioe) { @@ -108,10 +112,10 @@ public class Directory extends JS { public Enumeration keys() { final String[] elements = f.list(); - return new Enumeration() { + return new Enumeration(null) { int i = 0; - public boolean hasMoreElements() { return i < elements.length; } - public Object nextElement() { return FileNameEncoder.decode(elements[i++]); } + public boolean _hasMoreElements() { return i < elements.length; } + public JS _nextElement() { return JS.S(FileNameEncoder.decode(elements[i++])); } }; } }