Revision: 4645 http://sourceforge.net/p/vexi/code/4645 Author: mkpg2 Date: 2014-01-30 08:03:19 +0000 (Thu, 30 Jan 2014) Log Message: ----------- Fix regression in last commit. Fix. Add expect to Fountain.getInputStream(), to avoid NPEs and unexplained missing streams. Improve error response for desktop file operations.
Modified Paths: -------------- branches/vexi3/org.vexi-core.main/src/main/java/org/vexi/core/Main.java branches/vexi3/org.vexi-core.main/src/main/java/org/vexi/core/Resources.java branches/vexi3/org.vexi-core.main/src/main/java/org/vexi/plat/Desktop.java 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/main/jpp/org/ibex/js/XMLRPC.jpp branches/vexi3/org.vexi-library.js/src/main/jpp/org/vexi/js/VexiJS.jpp branches/vexi3/org.vexi-library.js/src/poke/java/org/ibex/js/RunJS.java branches/vexi3/org.vexi-library.js/src/poke/java/perf/PerfMultipleStream.java branches/vexi3/org.vexi-library.js/src/test/java/org/ibex/js/TestFountain.java branches/vexi3/org.vexi-library.js/src/test/java/test/js/parse/TestParse.java Modified: branches/vexi3/org.vexi-core.main/src/main/java/org/vexi/core/Main.java =================================================================== --- branches/vexi3/org.vexi-core.main/src/main/java/org/vexi/core/Main.java 2014-01-29 16:26:29 UTC (rev 4644) +++ branches/vexi3/org.vexi-core.main/src/main/java/org/vexi/core/Main.java 2014-01-30 08:03:19 UTC (rev 4645) @@ -311,7 +311,7 @@ this.data = data; this.name = name; } - public InputStream _getInputStream() throws IOException { + public InputStream _getInputStream(boolean expect) throws IOException { return Encode.JavaSourceCode.decode(data); } public String coerceToString() { Modified: branches/vexi3/org.vexi-core.main/src/main/java/org/vexi/core/Resources.java =================================================================== --- branches/vexi3/org.vexi-core.main/src/main/java/org/vexi/core/Resources.java 2014-01-29 16:26:29 UTC (rev 4644) +++ branches/vexi3/org.vexi-core.main/src/main/java/org/vexi/core/Resources.java 2014-01-30 08:03:19 UTC (rev 4645) @@ -107,7 +107,7 @@ static final DotVexi dotvexi = new DotVexi(null) { protected InputStream getInputStream(Object fountain, Object principal) throws IOException { Fountain.HTTP http = (Fountain.HTTP) fountain; - return http.getInputStream(); + return http.getInputStream(true); } protected long getRemoteDate(Object fountain, Object principal) { @@ -341,10 +341,10 @@ return cache._get(key); } - public InputStream _getInputStream() throws IOException { + public InputStream _getInputStream(boolean expect) throws IOException { // First download we check and potentially update the cache cache(this); // FIXME - should take principal as argument? - return cache.getInputStream(); + return cache.getInputStream(expect); } /** pull the specified file from a URL and store it in a temporary local .vexi file @@ -388,12 +388,12 @@ this.url = url; } - public InputStream _getInputStream() throws IOException { + public InputStream _getInputStream(boolean expect) throws IOException { // First download we check and potentially update the cache if (cache == null) { cache(this); } - return cache.getInputStream(); + return cache.getInputStream(expect); } /** pull the specified file from a URL and store it in a temporary local .vexi file @@ -467,12 +467,12 @@ JS key = E.next(); Fountain f = (Fountain) cached.get(key); // Find out font name from .ttf - InputStream is = f.getInputStream(); + InputStream is = f.getInputStream(true); Font font = Font.createFont(Font.TRUETYPE_FONT, is); String filename = font.getName(); is.close(); // Copy .ttf to font directory - is = f.getInputStream(); + is = f.getInputStream(true); streamToFile(new File(DIR_FONTS,filename+".ttf"), is); Log.user.warn(Resources.class, "Installing font " + filename); } Modified: branches/vexi3/org.vexi-core.main/src/main/java/org/vexi/plat/Desktop.java =================================================================== --- branches/vexi3/org.vexi-core.main/src/main/java/org/vexi/plat/Desktop.java 2014-01-29 16:26:29 UTC (rev 4644) +++ branches/vexi3/org.vexi-core.main/src/main/java/org/vexi/plat/Desktop.java 2014-01-30 08:03:19 UTC (rev 4645) @@ -50,18 +50,23 @@ desktop.mail(expectURI(arg)); return null; } - if("edit".equals(method)) { - desktop.edit(expectFile(arg)); - return null; + try{ + if("edit".equals(method)) { + desktop.edit(expectFile(arg)); + return null; + } + if("open".equals(method)) { + desktop.open(expectFile(arg)); + return null; + } + if("print".equals(method)) { + desktop.print(expectFile(arg)); + return null; + } + }catch(Exception e){ + File f = expectFile(arg); + throw new JSExn("Unable to "+method+" file '"+f.getName()+"'. Probably this computer/device does not know how to handle this operation for the files' type/suffix", JSU.S("handled")); } - if("open".equals(method)) { - desktop.open(expectFile(arg)); - return null; - } - if("print".equals(method)) { - desktop.print(expectFile(arg)); - return null; - } }catch(IOException e){ throw new JSExn("Could not run method: "+method,e); } 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-29 16:26:29 UTC (rev 4644) +++ branches/vexi3/org.vexi-library.js/src/main/java/org/ibex/js/Fountain.java 2014-01-30 08:03:19 UTC (rev 4645) @@ -78,13 +78,13 @@ return r==null?null:r.findWrite(); } - final public InputStream getInputStream() throws IOException{ return getInputStream(this); } - final public InputStream getInputStream(final Fountain principal) throws IOException { + final public InputStream getInputStream(boolean expect) throws IOException{ return getInputStream(this, expect); } + final public InputStream getInputStream(final Fountain principal, boolean expect) throws IOException { try{ // HACK - there is some race potential here, but only if // the programmer decides to try and remove/change these traps // after accessing the stream. - InputStream is = _getInputStream(); + InputStream is = _getInputStream(expect); if(is==null) return is; Trap startTrap = principal.wtrap(SC_start); final Trap progressTrap = principal.wtrap(SC_progress); @@ -142,7 +142,7 @@ } } - abstract protected InputStream _getInputStream() throws IOException; + abstract protected InputStream _getInputStream(boolean expect) throws IOException; public OutputStream getOutputStream(boolean expect) throws IOException{ if(expect) @@ -235,7 +235,7 @@ return readInfo(responseInfo); } //public String getCacheKey(Vec path) throws NotCacheableException { return url; } - public InputStream _getInputStream() throws IOException { + public InputStream _getInputStream(boolean expect) throws IOException { if(responseStream==null){ HTTPResponse response = http().GET(); responseStream = response.body; @@ -281,7 +281,7 @@ public static class Resource extends Fountain { private final URL res; public Resource(URL res) { this.res = res; } - public InputStream _getInputStream() throws IOException { return res.openStream(); } + public InputStream _getInputStream(boolean expect) throws IOException { return res.openStream(); } public String coerceToString(){ return res.toString(); } } @@ -293,7 +293,7 @@ public ByteArray(JS suggested) throws JSExn { this.suggested = suggested==null?8192:JSU.toInt(suggested); } - public InputStream _getInputStream() throws IOException { return new ByteArrayInputStream(bytes); } + public InputStream _getInputStream(boolean expect) throws IOException { return new ByteArrayInputStream(bytes); } public OutputStream getOutputStream(boolean expect) throws IOException { return new ByteArrayOutputStream(suggested){ public void close() throws IOException { @@ -326,9 +326,13 @@ r.putSafe(SC_name, JSU.S(canonical())); return r; } - public InputStream _getInputStream() throws IOException { - try{return new FileInputStream(path); - }catch(FileNotFoundException e){return null;} + public InputStream _getInputStream(boolean expect) throws IOException { + try{ + return new FileInputStream(path); + }catch(FileNotFoundException e){ + if(expect) throw e; + return null; + } } public OutputStream getOutputStream(boolean expect) throws IOException { if(!writeable) { @@ -336,10 +340,6 @@ 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)); } @@ -410,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(true)); + IOUtil.pipe(((Fountain)args[0]).getInputStream(true), ((Fountain)args[1]).getOutputStream(true)); sched.schedule(callback, null); } catch (IOException e) { sched.schedule(callback, JSU.handleFountainExn(e)); @@ -471,7 +471,7 @@ } //public String getCacheKey() throws NotCacheableException { return parent.getCacheKey() + "!zip:"; } public JS _get(JS key) throws JSExn { return new ZipFile(parent, path==null?JSU.toString(key):path+'/'+JSU.toString(key)); } - public InputStream _getInputStream() throws IOException { + public InputStream _getInputStream(boolean expect) throws IOException { ZipEntry entry = parent.getEntry(path); if (entry == null) throw new IOException("requested file (" + path + ") not found in archive"); return parent.getInputStream(entry); @@ -524,8 +524,8 @@ } //public String getCacheKey() throws NotCacheableException { return parent.getCacheKey() + "!zip:"; } public JS _get(JS key) throws JSExn { return new ZipStream(parent, path==null?JSU.toString(key):path+'/'+JSU.toString(key)); } - public InputStream _getInputStream() throws IOException { - InputStream pis = parent.getInputStream(); + public InputStream _getInputStream(boolean expect) throws IOException { + InputStream pis = parent.getInputStream(expect); ZipInputStream zis = new ZipInputStream(pis); ZipEntry ze = zis.getNextEntry(); while(ze != null && !ze.getName().equals(path)) ze = zis.getNextEntry(); @@ -539,7 +539,7 @@ };*/ } Set _getKeySet() throws IOException{ - InputStream pis = parent.getInputStream(); + InputStream pis = parent.getInputStream(true); ZipInputStream zis = new ZipInputStream(pis); ZipEntry ze = zis.getNextEntry(); String path = this.path==null?"":this.path; @@ -611,14 +611,14 @@ throw new JSExn(e.getMessage());} return new Multiple(fountains, key, path); } - public InputStream _getInputStream() throws IOException { + public InputStream _getInputStream(boolean expect) throws IOException { InputStream is; // FIXME: consider not doing loop when chosen!=null for (int i=0; i< fountains.size(); i++) { Fountain stream = (Fountain)fountains.elementAt(i); if (stream!=null) { try { - is = stream.getInputStream(this); + is = stream.getInputStream(this, expect); } catch (FileNotFoundException e) { is=null; } catch (IOException e) { is=null; } 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-29 16:26:29 UTC (rev 4644) +++ branches/vexi3/org.vexi-library.js/src/main/java/org/ibex/js/JSU.java 2014-01-30 08:03:19 UTC (rev 4645) @@ -61,7 +61,7 @@ static public InputStream getInputStream(JS js) throws IOException { Fountain f = getFountain(js); - return (f!=null)?f.getInputStream():null; + return (f!=null)?f.getInputStream(false):null; } static public OutputStream getOutputStream(JS js) throws IOException { Modified: branches/vexi3/org.vexi-library.js/src/main/jpp/org/ibex/js/XMLRPC.jpp =================================================================== --- branches/vexi3/org.vexi-library.js/src/main/jpp/org/ibex/js/XMLRPC.jpp 2014-01-29 16:26:29 UTC (rev 4644) +++ branches/vexi3/org.vexi-library.js/src/main/jpp/org/ibex/js/XMLRPC.jpp 2014-01-30 08:03:19 UTC (rev 4645) @@ -246,7 +246,7 @@ } else if (o instanceof Fountain) { try { sb.append(" <value><base64>\n"); - InputStream is = ((Fountain)o).getInputStream(); + InputStream is = ((Fountain)o).getInputStream(true); byte[] buf = new byte[54]; while (true) { int numread = is.read(buf, 0, 54); Modified: branches/vexi3/org.vexi-library.js/src/main/jpp/org/vexi/js/VexiJS.jpp =================================================================== --- branches/vexi3/org.vexi-library.js/src/main/jpp/org/vexi/js/VexiJS.jpp 2014-01-29 16:26:29 UTC (rev 4644) +++ branches/vexi3/org.vexi-library.js/src/main/jpp/org/vexi/js/VexiJS.jpp 2014-01-30 08:03:19 UTC (rev 4645) @@ -743,7 +743,7 @@ Fountain f = (Fountain)args[0]; final BufferedReader r; try { - InputStream is = f.getInputStream(); + InputStream is = f.getInputStream(false); if (is == null) { is = new ByteArrayInputStream(new byte[0]); } Modified: branches/vexi3/org.vexi-library.js/src/poke/java/org/ibex/js/RunJS.java =================================================================== --- branches/vexi3/org.vexi-library.js/src/poke/java/org/ibex/js/RunJS.java 2014-01-29 16:26:29 UTC (rev 4644) +++ branches/vexi3/org.vexi-library.js/src/poke/java/org/ibex/js/RunJS.java 2014-01-30 08:03:19 UTC (rev 4645) @@ -98,7 +98,7 @@ public Reader getReaderForFile(String filename) throws JSExn{ InputStream is; try { - is = getFountainForFile(filename).getInputStream(); + is = getFountainForFile(filename).getInputStream(true); } catch (IOException e) { throw new JSExn(e); } Modified: branches/vexi3/org.vexi-library.js/src/poke/java/perf/PerfMultipleStream.java =================================================================== --- branches/vexi3/org.vexi-library.js/src/poke/java/perf/PerfMultipleStream.java 2014-01-29 16:26:29 UTC (rev 4644) +++ branches/vexi3/org.vexi-library.js/src/poke/java/perf/PerfMultipleStream.java 2014-01-30 08:03:19 UTC (rev 4645) @@ -105,7 +105,7 @@ JS k = en.next(); Fountain f = (Fountain) dir.get(k); - BufferedReader r = new BufferedReader(new InputStreamReader(f.getInputStream())); + BufferedReader r = new BufferedReader(new InputStreamReader(f.getInputStream(true))); String l; int c = 0; while((l=r.readLine())!=null){ @@ -123,7 +123,7 @@ for(int j=0; j<files_per_archive; j++){ //String filename = "a/b/package"+i+"/file"+j; Fountain f = (Fountain) multiple.get(JSU.S("a")).get(JSU.S("b")).get(JSU.S("package"+i)).get(JSU.S("file"+j)); - BufferedReader r = new BufferedReader(new InputStreamReader(f.getInputStream())); + BufferedReader r = new BufferedReader(new InputStreamReader(f.getInputStream(true))); String l; int c = 0; 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-29 16:26:29 UTC (rev 4644) +++ branches/vexi3/org.vexi-library.js/src/test/java/org/ibex/js/TestFountain.java 2014-01-30 08:03:19 UTC (rev 4645) @@ -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(true)); + IOUtil.pipe(a.getInputStream(true), b.getOutputStream(true)); String s = JSU.toString(Fountain.parseUTF8(new JS[]{b})); Assert.assertEquals("sausage",s); } Modified: branches/vexi3/org.vexi-library.js/src/test/java/test/js/parse/TestParse.java =================================================================== --- branches/vexi3/org.vexi-library.js/src/test/java/test/js/parse/TestParse.java 2014-01-29 16:26:29 UTC (rev 4644) +++ branches/vexi3/org.vexi-library.js/src/test/java/test/js/parse/TestParse.java 2014-01-30 08:03:19 UTC (rev 4645) @@ -32,7 +32,7 @@ private Function parseFile(String filename) throws Exception { - return DevUtil.parseJS(((Fountain)jspath.get(JSU.S(filename))).getInputStream(),filename); + return DevUtil.parseJS(((Fountain)jspath.get(JSU.S(filename))).getInputStream(true),filename); } public void testWierd() throws Throwable{ 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