/** * Read file or url specified by <tt>path</tt>. * @return file or url content as <tt>byte[]</tt> or as <tt>String</tt> if * <tt>convertToString</tt> is true. */ private static Object readFileOrUrl(String path, boolean convertToString) throws IOException { return SourceReader.readFileOrUrl(path, convertToString, shellContextFactory.getCharacterEncoding()); }
static Scriptable getScope(String path) { if (useRequire) { // If CommonJS modules are enabled use a module scope that resolves // relative ids relative to the current URL, file or working directory. URI uri; if (path == null) { // use current directory for shell and -e switch uri = new File(System.getProperty("user.dir")).toURI(); } else { // find out whether this is a file path or a URL if (SourceReader.toUrl(path) != null) { try { uri = new URI(path); } catch (URISyntaxException x) { // fall back to file uri uri = new File(path).toURI(); } } else { uri = new File(path).toURI(); } } return new ModuleScope(global, uri, null); } else { return global; } }
/** * Read file or url specified by <tt>path</tt>. * @return file or url content as <tt>byte[]</tt> or as <tt>String</tt> if * <tt>convertToString</tt> is true. */ private static Object readFileOrUrl(String path, boolean convertToString) throws IOException { return SourceReader.readFileOrUrl(path, convertToString, shellContextFactory.getCharacterEncoding()); }
static Scriptable getScope(String path) { if (useRequire) { // If CommonJS modules are enabled use a module scope that resolves // relative ids relative to the current URL, file or working directory. URI uri; if (path == null) { // use current directory for shell and -e switch uri = new File(System.getProperty("user.dir")).toURI(); } else { // find out whether this is a file path or a URL if (SourceReader.toUrl(path) != null) { try { uri = new URI(path); } catch (URISyntaxException x) { // fall back to file uri uri = new File(path).toURI(); } } else { uri = new File(path).toURI(); } } return new ModuleScope(global, uri, null); } else { return global; } }
private String readSource(File f) { String absPath = f.getAbsolutePath(); if (!f.isFile()) { addError("msg.jsfile.not.found", absPath); return null; } try { return (String)SourceReader.readFileOrUrl(absPath, true, characterEncoding); } catch (FileNotFoundException ex) { addError("msg.couldnt.open", absPath); } catch (IOException ioe) { addFormatedError(ioe.toString()); } return null; }
public static Object readFileOrUrl(String path, boolean convertToString, String defaultEncoding) throws IOException URL url = toUrl(path); InputStream is = null; int capacityHint = 0;
private String readSource(File f) { String absPath = f.getAbsolutePath(); if (!f.isFile()) { addError("msg.jsfile.not.found", absPath); return null; } try { return (String)SourceReader.readFileOrUrl(absPath, true, characterEncoding); } catch (FileNotFoundException ex) { addError("msg.couldnt.open", absPath); } catch (IOException ioe) { addFormatedError(ioe.toString()); } return null; }
/** * Read file or url specified by <tt>path</tt>. * @return file or url content as <tt>byte[]</tt> or as <tt>String</tt> if * <tt>convertToString</tt> is true. */ private static Object readFileOrUrl(String path, boolean convertToString) { try { return SourceReader.readFileOrUrl(path, convertToString, shellContextFactory.getCharacterEncoding()); } catch (IOException ex) { Context.reportError(ToolErrorReporter.getMessage( "msg.couldnt.read.source", path, ex.getMessage())); return null; } } }