long transferFromRemote(StreamCopier.Listener listener, OutputStream dest, long length) throws IOException { return new StreamCopier(scp.getInputStream(), dest, loggerFactory) .bufSize(scp.getLocalMaxPacketSize()).length(length) .keepFlushing(false) .listener(listener) .copy(); }
public Event<IOException> spawnDaemon(String name) { return spawn(name, true); }
protected void start() throws IOException { socket.setSendBufferSize(getLocalMaxPacketSize()); socket.setReceiveBufferSize(getRemoteMaxPacketSize()); final Event<IOException> soc2chan = new StreamCopier(socket.getInputStream(), getOutputStream(), loggerFactory) .bufSize(getRemoteMaxPacketSize()) .spawnDaemon("soc2chan"); final Event<IOException> chan2soc = new StreamCopier(getInputStream(), socket.getOutputStream(), loggerFactory) .bufSize(getLocalMaxPacketSize()) .spawnDaemon("chan2soc"); SocketStreamCopyMonitor.monitor(5, TimeUnit.SECONDS, soc2chan, chan2soc, this, socket); }
public static ByteArrayOutputStream readFully(InputStream stream, LoggerFactory loggerFactory) throws IOException { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); new StreamCopier(stream, baos, loggerFactory).copy(); return baos; }
private void logIntoIp(String ipAddress) throws IOException, InterruptedException { final SSHClient ssh = new SSHClient(); OpenSSHKeyFile k = new OpenSSHKeyFile(); k.init(new File(dotHaruhi, keyPairName + ".pem")); ssh.addHostKeyVerifier(new PromiscuousVerifier()); ssh.connect(ipAddress); try { ssh.authPublickey(clusterUsername, k); Session that = ssh.startSession(); try { that.allocateDefaultPTY(); Session.Shell shell = that.startShell(); new StreamCopier(shell.getInputStream(), System.out) .bufSize(shell.getLocalMaxPacketSize()) .spawn("stdout"); new StreamCopier(shell.getErrorStream(), System.err) .bufSize(shell.getLocalMaxPacketSize()) .spawn("stderr"); new StreamCopier(System.in, shell.getOutputStream()) .bufSize(shell.getRemoteMaxPacketSize()) .copy(); } finally { that.close(); } } finally { ssh.close(); } }
@Override public void run() { try { log.debug("Will copy from {} to {}", in, out); copy(); log.debug("Done copying from {}", in); doneEvent.set(); } catch (IOException ioe) { log.error(String.format("In pipe from %1$s to %2$s", in.toString(), out.toString()), ioe); doneEvent.deliverError(ioe); } } }.start();
public long copy() throws IOException { final byte[] buf = new byte[bufSize]; long count = 0; int read = 0; final long startTime = System.currentTimeMillis(); if (length == -1) { while ((read = in.read(buf)) != -1) { count += write(buf, count, read); } } else { while (count < length && (read = in.read(buf, 0, (int) Math.min(bufSize, length - count))) != -1) { count += write(buf, count, read); } } if (!keepFlushing) out.flush(); final double timeSeconds = (System.currentTimeMillis() - startTime) / 1000.0; final double sizeKiB = count / 1024.0; log.debug(String.format("%1$,.1f KiB transferred in %2$,.1f seconds (%3$,.2f KiB/s)", sizeKiB, timeSeconds, (sizeKiB / timeSeconds))); if (length != -1 && read == -1) throw new IOException("Encountered EOF, could not transfer " + length + " bytes"); return count; }
public static ByteArrayOutputStream readFully(InputStream stream, LoggerFactory loggerFactory) throws IOException { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); new StreamCopier(stream, baos, loggerFactory).copy(); return baos; }
@Override public void run() { try { log.debug("Will copy from {} to {}", in, out); copy(); log.debug("Done copying from {}", in); doneEvent.set(); } catch (IOException ioe) { log.error(String.format("In pipe from %1$s to %2$s", in.toString(), out.toString()), ioe); doneEvent.deliverError(ioe); } } }.start();
public long copy() throws IOException { final byte[] buf = new byte[bufSize]; long count = 0; int read = 0; final long startTime = System.currentTimeMillis(); if (length == -1) { while ((read = in.read(buf)) != -1) count = write(buf, count, read); } else { while (count < length && (read = in.read(buf, 0, (int) Math.min(bufSize, length - count))) != -1) count = write(buf, count, read); } if (!keepFlushing) out.flush(); final double timeSeconds = (System.currentTimeMillis() - startTime) / 1000.0; final double sizeKiB = count / 1024.0; log.info("{} KiB transferred in {} seconds ({} KiB/s)", sizeKiB, timeSeconds, (sizeKiB / timeSeconds)); if (length != -1 && read == -1) throw new IOException("Encountered EOF, could not transfer " + length + " bytes"); return count; }
long transferToRemote(StreamCopier.Listener listener, InputStream src, long length) throws IOException { return new StreamCopier(src, scp.getOutputStream(), loggerFactory) .bufSize(scp.getRemoteMaxPacketSize()).length(length) .keepFlushing(false) .listener(listener) .copy(); }
/** On connect, confirm the channel and start forwarding. */ @Override public void gotConnect(Channel.Forwarded chan) throws IOException { chan.getLoggerFactory().getLogger(getClass()).debug("New connection from {}:{}", chan.getOriginatorIP(), chan.getOriginatorPort()); final Socket sock = new Socket(); sock.setSendBufferSize(chan.getLocalMaxPacketSize()); sock.setReceiveBufferSize(chan.getRemoteMaxPacketSize()); sock.connect(addr); // ok so far -- could connect, let's confirm the channel chan.confirm(); final Event<IOException> soc2chan = new StreamCopier(sock.getInputStream(), chan.getOutputStream(), chan.getLoggerFactory()) .bufSize(chan.getRemoteMaxPacketSize()) .spawnDaemon("soc2chan"); final Event<IOException> chan2soc = new StreamCopier(chan.getInputStream(), sock.getOutputStream(), chan.getLoggerFactory()) .bufSize(chan.getLocalMaxPacketSize()) .spawnDaemon("chan2soc"); SocketStreamCopyMonitor.monitor(5, TimeUnit.SECONDS, chan2soc, soc2chan, chan, sock); }
public static ByteArrayOutputStream readFully(InputStream stream) throws IOException { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); new StreamCopier(stream, baos).copy(); return baos; }
public Event<IOException> spawn(String name) { return spawn(name, false); }
@Override public void run() { try { log.debug("Will copy from {} to {}", in, out); copy(); log.debug("Done copying from {}", in); doneEvent.set(); } catch (IOException ioe) { log.error("In pipe from {} to {}: {}", in, out, ioe); doneEvent.deliverError(ioe); } } }.start();
public long copy() throws IOException { final byte[] buf = new byte[bufSize]; long count = 0; int read = 0; final long startTime = System.currentTimeMillis(); if (length == -1) { while ((read = in.read(buf)) != -1) { count += write(buf, count, read); } } else { while (count < length && (read = in.read(buf, 0, (int) Math.min(bufSize, length - count))) != -1) { count += write(buf, count, read); } } if (!keepFlushing) out.flush(); final double timeSeconds = (System.currentTimeMillis() - startTime) / 1000.0; final double sizeKiB = count / 1024.0; log.debug(String.format("%1$,.1f KiB transferred in %2$,.1f seconds (%3$,.2f KiB/s)", sizeKiB, timeSeconds, (sizeKiB / timeSeconds))); if (length != -1 && read == -1) throw new IOException("Encountered EOF, could not transfer " + length + " bytes"); return count; }
private LocalDestFile downloadFile(final StreamCopier.Listener listener, final RemoteResourceInfo remote, final LocalDestFile local) throws IOException { final LocalDestFile adjusted = local.getTargetFile(remote.getName()); final RemoteFile rf = engine.open(remote.getPath()); try { final RemoteFile.ReadAheadRemoteFileInputStream rfis = rf.new ReadAheadRemoteFileInputStream(16); final OutputStream os = adjusted.getOutputStream(); try { new StreamCopier(rfis, os, engine.getLoggerFactory()) .bufSize(engine.getSubsystem().getLocalMaxPacketSize()) .keepFlushing(false) .listener(listener) .copy(); } finally { rfis.close(); os.close(); } } finally { rf.close(); } return adjusted; }
protected void start() throws IOException { socket.setSendBufferSize(getLocalMaxPacketSize()); socket.setReceiveBufferSize(getRemoteMaxPacketSize()); final Event<IOException> soc2chan = new StreamCopier(socket.getInputStream(), getOutputStream(), loggerFactory) .bufSize(getRemoteMaxPacketSize()) .spawnDaemon("soc2chan"); final Event<IOException> chan2soc = new StreamCopier(getInputStream(), socket.getOutputStream(), loggerFactory) .bufSize(getLocalMaxPacketSize()) .spawnDaemon("chan2soc"); SocketStreamCopyMonitor.monitor(5, TimeUnit.SECONDS, soc2chan, chan2soc, this, socket); }
public Event<IOException> spawn(String name) { return spawn(name, false); }
fis = local.getInputStream(); rfos = rf.new RemoteFileOutputStream(0, 16); new StreamCopier(fis, rfos, engine.getLoggerFactory()) .bufSize(engine.getSubsystem().getRemoteMaxPacketSize() - rf.getOutgoingPacketOverhead()) .keepFlushing(false) .listener(listener) .copy(); } finally { if (rf != null) {