/** * Set the output stream by means of which input can be sent to the child. */ public void setChildInputStream(final OutputStream out) { assert out != null; if (streams.in != null) { inputPump = createInputPump(streams.in, out, true); } else { Closer.close(out); } }
protected void loadScript(final File file) throws Exception { assert file != null; log.debug("Loading script: {}", file); BufferedReader reader = new BufferedReader(new FileReader(file)); try { String line; while ((line = reader.readLine()) != null) { execute(line); } } finally { Closer.close(reader); } }
Closer.close(out);
protected List<CommandsDescriptor> discoverDescriptors() throws Exception { List<CommandsDescriptor> list = new LinkedList<CommandsDescriptor>(); for (String location : getDescriptorSearchPath()) { log.debug("Discovering commands descriptors; location={}", location); ClassLoader cl = Thread.currentThread().getContextClassLoader(); Enumeration<URL> resources = cl.getResources(location); if (resources != null && resources.hasMoreElements()) { log.debug("Discovered:"); while (resources.hasMoreElements()) { URL url = resources.nextElement(); log.debug(" {}", url); CommandsXpp3Reader reader = new CommandsXpp3Reader(); InputStream input = url.openStream(); try { CommandsDescriptor config = reader.read(input); list.add(config); } finally { Closer.close(input); } } } } return list; } }
public Object execute(final CommandContext context) throws Exception { assert context != null; Shell shell = context.getShell(); URL url; try { url = new URL(path); } catch (MalformedURLException e) { url = new File(path).toURI().toURL(); } BufferedReader reader = openReader(url); try { String line; while ((line = reader.readLine()) != null) { shell.execute(line); } } finally { Closer.close(reader); } return Result.SUCCESS; }
public CommandLine parse(final String line) throws Exception { assert line != null; log.trace("Building command-line for: {}", line); Reader reader = new StringReader(line); final ASTCommandLine root; try { root = parser.parse(reader); } finally { Closer.close(reader); } // If trace is enabled, the log the parse tree if (log.isTraceEnabled()) { root.jjtAccept(new LoggingVisitor(log), null); } return new CommandLine() { public Object execute(final Shell shell, final CommandExecutor executor) throws Exception { ExecutingVisitor visitor = new ExecutingVisitor(shell, executor); return root.jjtAccept(visitor, null); } }; } }
private String load(final String name, final Locale locale, final ClassLoader loader) throws MissingContentException, IOException { log.debug("Loading help content for {} ({})", name, locale); URL resource = findResource(name, locale, loader); if (resource == null) { throw new MissingContentException(name); } log.debug("Using resource: {}", resource); BufferedReader input = new BufferedReader(new InputStreamReader(resource.openStream())); PrintBuffer buff; try { buff = new PrintBuffer(); String line; while ((line = input.readLine()) != null) { // Ignore lines starting with #, these are comments if (!line.startsWith("#")) { buff.println(line); } } } finally { Closer.close(input); } return buff.toString(); }
public String getContent() throws IOException { URL url = getUrl(); if (url == null) { return null; } PrintBuffer buff = new PrintBuffer(); InputStream input = url.openStream(); try { Copier.copy(input, buff); } finally { Closer.close(input); } return buff.toString(); } }
Closer.close(out); io.println("Saved {} [{}]",outputFile, outputFile.length()); // TODO: i18n return outputFile;