Revision: 4644
          http://sourceforge.net/p/vexi/code/4644
Author:   mkpg2
Date:     2014-01-29 16:26:29 +0000 (Wed, 29 Jan 2014)
Log Message:
-----------
Fix. Fountain was inconsistently throwing errors/returning null if unable to 
return an output stream.

Modified Paths:
--------------
    branches/vexi3/org.vexi-library.js/src/main/java/org/ibex/js/Fountain.java
    branches/vexi3/org.vexi-library.js/src/main/java/org/ibex/js/JSU.java
    
branches/vexi3/org.vexi-library.js/src/test/java/org/ibex/js/TestFountain.java

Modified: 
branches/vexi3/org.vexi-library.js/src/main/java/org/ibex/js/Fountain.java
===================================================================
--- branches/vexi3/org.vexi-library.js/src/main/java/org/ibex/js/Fountain.java  
2014-01-26 04:13:49 UTC (rev 4643)
+++ branches/vexi3/org.vexi-library.js/src/main/java/org/ibex/js/Fountain.java  
2014-01-29 16:26:29 UTC (rev 4644)
@@ -144,8 +144,10 @@
        
     abstract protected InputStream _getInputStream() throws IOException;
     
-    public OutputStream getOutputStream() throws IOException{
-       throw new IOException(toString() + " is read only");
+    public OutputStream getOutputStream(boolean expect) throws IOException{
+       if(expect)
+               throw new IOException(toString() + " is read only");
+       return null;
     }
     
     public void addTrap(JS key, JS f) throws JSExn {
@@ -248,7 +250,7 @@
                // if the server doesn't support HTTP/HEAD fallback to get
                catch(HTTPException e){return http.GET(null, null);}
         }*/
-        public OutputStream getOutputStream() throws IOException { 
+        public OutputStream getOutputStream(boolean expect) { 
                // ALL WRONG
                // HACK - we need a way to retrieve the output stream
                // from the http post
@@ -292,7 +294,7 @@
                this.suggested = suggested==null?8192:JSU.toInt(suggested);
         }
         public InputStream _getInputStream() throws IOException { return new 
ByteArrayInputStream(bytes); }
-        public OutputStream getOutputStream() throws IOException {
+        public OutputStream getOutputStream(boolean expect) throws IOException 
{
                return new ByteArrayOutputStream(suggested){
                        public void close() throws IOException {
                                super.close();
@@ -328,10 +330,17 @@
                try{return new FileInputStream(path);
                }catch(FileNotFoundException e){return null;}
         }
-        public OutputStream getOutputStream() throws IOException {
-               if(!writeable) throw new IOException("File readonly: " + 
coerceToString());
-               try{return new FileOutputStream(path);
-               }catch(FileNotFoundException e){return null;}
+        public OutputStream getOutputStream(boolean expect) throws IOException 
{
+               if(!writeable) {
+                       if(expect) throw new IOException("File readonly: " + 
coerceToString());
+                       return null;
+               }
+               java.io.File f = new java.io.File(path);
+               if(!f.isFile()){
+                       if(expect) throw new IOException("Could not find file: 
" + coerceToString());
+                return null;
+               }
+               return new FileOutputStream(path);
         }
         public JS _get(JS key) throws JSExn { return new File(path + 
java.io.File.separatorChar + JSU.toString(key)); }
         public void remove() throws JSExn {
@@ -401,7 +410,7 @@
                final Callable callback = sched.pauseJSThread();
                new java.lang.Thread() { public void run() { 
                        try {
-                                       
IOUtil.pipe(((Fountain)args[0]).getInputStream(), 
((Fountain)args[1]).getOutputStream());
+                               
IOUtil.pipe(((Fountain)args[0]).getInputStream(), 
((Fountain)args[1]).getOutputStream(true));
                                        sched.schedule(callback, null);
                        } catch (IOException e) {
                                sched.schedule(callback, 
JSU.handleFountainExn(e));

Modified: branches/vexi3/org.vexi-library.js/src/main/java/org/ibex/js/JSU.java
===================================================================
--- branches/vexi3/org.vexi-library.js/src/main/java/org/ibex/js/JSU.java       
2014-01-26 04:13:49 UTC (rev 4643)
+++ branches/vexi3/org.vexi-library.js/src/main/java/org/ibex/js/JSU.java       
2014-01-29 16:26:29 UTC (rev 4644)
@@ -66,7 +66,7 @@
     
     static public OutputStream getOutputStream(JS js) throws IOException { 
        Fountain f = getFountain(js);
-       return (f!=null)?f.getOutputStream():null;
+       return (f!=null)?f.getOutputStream(false):null;
     }
     
     // HACK - this is an unideal way to handle it, as it relies

Modified: 
branches/vexi3/org.vexi-library.js/src/test/java/org/ibex/js/TestFountain.java
===================================================================
--- 
branches/vexi3/org.vexi-library.js/src/test/java/org/ibex/js/TestFountain.java  
    2014-01-26 04:13:49 UTC (rev 4643)
+++ 
branches/vexi3/org.vexi-library.js/src/test/java/org/ibex/js/TestFountain.java  
    2014-01-29 16:26:29 UTC (rev 4644)
@@ -28,7 +28,7 @@
                Fountain a = new Fountain.ByteArray((JS)null);
                Fountain b = new Fountain.ByteArray((JS)null);
                Fountain.writeUTF8(new JS[]{a,JSU.S("sausage")});
-               IOUtil.pipe(a.getInputStream(), b.getOutputStream());
+               IOUtil.pipe(a.getInputStream(), b.getOutputStream(true));
                String s = JSU.toString(Fountain.parseUTF8(new JS[]{b}));
                Assert.assertEquals("sausage",s);
        }

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
WatchGuard Dimension instantly turns raw network data into actionable 
security intelligence. It gives you real-time visual feedback on key
security issues and trends.  Skip the complicated setup - simply import
a virtual appliance and go from zero to informed in seconds.
http://pubads.g.doubleclick.net/gampad/clk?id=123612991&iu=/4140/ostg.clktrk
_______________________________________________
Vexi-svn mailing list
Vexi-svn@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/vexi-svn

Reply via email to