public RemoteChannelLaunchCallable(@Nonnull String[] cmd, @Nonnull Pipe out, @Nonnull OutputStream err, @CheckForNull String workDir, @Nonnull Map<String,String> envOverrides) { this.cmd = cmd; this.out = out; this.err = new RemoteOutputStream(err); this.workDir = workDir; this.envOverrides = envOverrides; }
public int execute(List<String> args, InputStream stdin, OutputStream stdout, OutputStream stderr) { return entryPoint.main(args, Locale.getDefault(), new RemoteInputStream(stdin), new RemoteOutputStream(stdout), new RemoteOutputStream(stderr)); }
@Override public OutputStream invoke(File f, VirtualChannel channel) throws IOException, InterruptedException { f = f.getAbsoluteFile(); mkdirs(f.getParentFile()); return new RemoteOutputStream(Files.newOutputStream(fileToPath(writing(f)))); } }
private void writeObject(ObjectOutputStream out) throws IOException { out.writeObject(new RemoteOutputStream(new CloseProofOutputStream(this.out))); out.writeObject(charset==null? null : charset.name()); }
public OutputStream call() throws IOException { Process p = Runtime.getRuntime().exec(cmd, Util.mapToEnv(inherit(envOverrides)), workDir == null ? null : new File(workDir)); List<String> cmdLines = Arrays.asList(cmd); new StreamCopyThread("stdin copier for remote agent on "+cmdLines, p.getInputStream(), out.getOut()).start(); new StreamCopyThread("stderr copier for remote agent on "+cmdLines, p.getErrorStream(), err).start(); // TODO: don't we need to join? return new RemoteOutputStream(p.getOutputStream()); }
/** * Archives this directory into the specified archive format, to the given {@link OutputStream}, by using * {@link DirScanner} to choose what files to include. * * @return * number of files/directories archived. This is only really useful to check for a situation where nothing * is archived. */ public int archive(final ArchiverFactory factory, OutputStream os, final DirScanner scanner) throws IOException, InterruptedException { final OutputStream out = (channel!=null)?new RemoteOutputStream(os):os; return act(new Archive(factory, out, scanner)); } private class Archive extends SecureFileCallable<Integer> {
/** * Sends the contents of this file into the given {@link OutputStream}. */ public void copyTo(OutputStream os) throws IOException, InterruptedException { final OutputStream out = new RemoteOutputStream(os); act(new CopyTo(out)); // make sure the writes fully got delivered to 'os' before we return. // this is needed because I/O operation is asynchronous syncIO(); } private class CopyTo extends SecureFileCallable<Void> {
public Proc launch(ProcStarter ps) throws IOException { final OutputStream out = ps.stdout == null || ps.stdoutListener != null ? null : new RemoteOutputStream(new CloseProofOutputStream(ps.stdout)); final OutputStream err = ps.stderr==null ? null : new RemoteOutputStream(new CloseProofOutputStream(ps.stderr)); final InputStream in = (ps.stdin==null || ps.stdin==NULL_INPUT_STREAM) ? null : new RemoteInputStream(ps.stdin,false); final FilePath psPwd = ps.pwd; final String workDir = psPwd==null ? null : psPwd.getRemote(); try { return new ProcImpl(getChannel().call(new RemoteLaunchCallable(ps.commands, ps.masks, ps.envs, in, ps.reverseStdin, out, ps.reverseStdout, err, ps.reverseStderr, ps.quiet, workDir, listener, ps.stdoutListener))); } catch (InterruptedException e) { throw (IOException)new InterruptedIOException().initCause(e); } }
public IOTriplet getIOtriplet() { IOTriplet r = new IOTriplet(); if (reverseStdout) r.stdout = new RemoteInputStream(p.getStdout()); if (reverseStderr) r.stderr = new RemoteInputStream(p.getStderr()); if (reverseStdin) r.stdin = new RemoteOutputStream(p.getStdin()); return r; } });
public RemoteChannelLaunchCallable(String[] cmd, Pipe out, OutputStream err, String workDir, Map<String,String> envOverrides) { this.cmd = cmd; this.out = out; this.err = new RemoteOutputStream(err); this.workDir = workDir; this.envOverrides = envOverrides; }
public RemoteChannelLaunchCallable(String[] cmd, Pipe out, OutputStream err, String workDir, Map<String,String> envOverrides) { this.cmd = cmd; this.out = out; this.err = new RemoteOutputStream(err); this.workDir = workDir; this.envOverrides = envOverrides; }
public OutputStream invoke(File f, VirtualChannel channel) throws IOException, InterruptedException { f = f.getAbsoluteFile(); mkdirs(f.getParentFile()); try { OutputStream fos = Files.newOutputStream(writing(f).toPath()); return new RemoteOutputStream(fos); } catch (InvalidPathException e) { throw new IOException(e); } } });
public RemoteChannelLaunchCallable(@Nonnull String[] cmd, @Nonnull Pipe out, @Nonnull OutputStream err, @CheckForNull String workDir, @Nonnull Map<String,String> envOverrides) { this.cmd = cmd; this.out = out; this.err = new RemoteOutputStream(err); this.workDir = workDir; this.envOverrides = envOverrides; }
public static Pipe createRemoteToLocal(Launcher launcher) throws IOException { PipedInputStream is = new PipedInputStream(); PipedOutputStream pos = new PipedOutputStream(is); boolean isLocal = launcher instanceof Launcher.LocalLauncher; OutputStream os = isLocal ? pos : new RemoteOutputStream(pos); return new Pipe(is, os); } }
/** * Executed on remote, returns connection wrapper with remote streams. */ private Object writeReplace() { return new ConnectionImpl(new RemoteInputStream(input), new RemoteOutputStream(output)); }
/** * Executed on remote, returns connection wrapper with remote streams. */ private Object writeReplace() { return new ConnectionImpl(new RemoteInputStream(input), new RemoteOutputStream(output)); }
public OutputStream call() throws IOException { Process p = Runtime.getRuntime().exec(cmd, Util.mapToEnv(inherit(envOverrides)), workDir == null ? null : new File(workDir)); List<String> cmdLines = Arrays.asList(cmd); new StreamCopyThread("stdin copier for remote agent on "+cmdLines, p.getInputStream(), out.getOut()).start(); new StreamCopyThread("stderr copier for remote agent on "+cmdLines, p.getErrorStream(), err).start(); // TODO: don't we need to join? return new RemoteOutputStream(p.getOutputStream()); }
public OutputStream connect(OutputStream out) throws IOException { Socket s = new Socket(remoteHost, remotePort); new CopyThread(String.format("Copier to %s:%d", remoteHost, remotePort), new SocketInputStream(s), out).start(); return new RemoteOutputStream(new SocketOutputStream(s)); }
public Proc launch(ProcStarter ps) throws IOException { final OutputStream out = ps.stdout == null ? null : new RemoteOutputStream(new CloseProofOutputStream(ps.stdout)); final OutputStream err = ps.stderr==null ? null : new RemoteOutputStream(new CloseProofOutputStream(ps.stderr)); final InputStream in = (ps.stdin==null || ps.stdin==NULL_INPUT_STREAM) ? null : new RemoteInputStream(ps.stdin,false); final FilePath psPwd = ps.pwd; final String workDir = psPwd==null ? null : psPwd.getRemote(); try { return new ProcImpl(getChannel().call(new RemoteLaunchCallable(ps.commands, ps.masks, ps.envs, in, ps.reverseStdin, out, ps.reverseStdout, err, ps.reverseStderr, ps.quiet, workDir, listener))); } catch (InterruptedException e) { throw (IOException)new InterruptedIOException().initCause(e); } }
public void run() { try { final OutputStream out = forwarder.connect(new RemoteOutputStream(new SocketOutputStream(s))); new CopyThread("Copier for "+s.getRemoteSocketAddress(), new SocketInputStream(s), out).start(); } catch (IOException e) { // this happens if the socket connection is terminated abruptly. LOGGER.log(FINE,"Port forwarding session was shut down abnormally",e); } } }.start();