fix nasty bug in numerical comparison in Interpreter
[org.ibex.js.git] / src / org / ibex / js / Directory.java
index 0c0fc73..0a77f41 100644 (file)
@@ -5,6 +5,7 @@
 package org.ibex.js; 
 
 import org.ibex.util.*; 
+import org.ibex.io.*;
 import java.io.*;
 
 // FEATURE: support for move
@@ -65,14 +66,19 @@ public class Directory extends JS.Immutable {
     public void put(JS key0, JS val) throws JSExn {
         try {
             if (key0 == null) return;
-            String key = Script.toString(key0);
+            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) {
+            if (val instanceof org.ibex.io.Fountain) {
+                Stream stream = ((org.ibex.io.Fountain)val).getStream();
+                Stream out = new Stream(null, new FileOutputStream(f2));
+                stream.transcribe(out);
+                out.close();
+            } else if (val instanceof JSPrimitive) {
                 OutputStream out = new FileOutputStream(f2);
                 Writer w = new OutputStreamWriter(out);
-                w.write(Script.toString(val));
+                w.write(JSU.toString(val));
                 w.flush();
                 out.close();
             } else {
@@ -92,16 +98,16 @@ public class Directory extends JS.Immutable {
     public JS get(JS key0) throws JSExn {
         try {
             if (key0 == null) return null;
-            String key = Script.toString(key0);
+            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 Script.S(new String(chars, 0, numchars));
+                if (numread == -1) return JSU.S(new String(chars, 0, numchars));
                 numchars += numread;
             }
         } catch (IOException ioe) {
@@ -114,7 +120,7 @@ public class Directory extends JS.Immutable {
         return new JS.Enumeration(null) {
                 int i = 0;
                 public boolean _hasNext() { return i < elements.length; }
-                public JS _next() { return Script.S(Encode.fromFilename(elements[i++])); }
+                public JS _next() { return JSU.S(Encode.fromFilename(elements[i++])); }
             };
     }
 }