in src/main/java/com/pastdev/jsch/IOUtils.java [52:66]
public static void copy( InputStream from, OutputStream to ) throws IOException {
ReadableByteChannel in = Channels.newChannel( from );
WritableByteChannel out = Channels.newChannel( to );
final ByteBuffer buffer = ByteBuffer.allocateDirect( 16 * 1024 );
while ( in.read( buffer ) != -1 ) {
buffer.flip();
out.write( buffer );
buffer.compact();
}
buffer.flip();
while ( buffer.hasRemaining() ) {
out.write( buffer );
}
}