in src/main/java/com/pastdev/jsch/nio/file/UnixSshFileSystemProvider.java [713:743]
int write( UnixSshPath path, long startIndex, ByteBuffer bytes ) throws IOException {
int bytesPosition = bytes.position();
// TODO cache this buffer for reuse
ByteBuffer temp = ByteBuffer.allocateDirect( bytes.limit() - bytesPosition );
temp.put( bytes );
bytes.position( bytesPosition );
String command = path.getFileSystem().getCommand( "dd" )
+ " conv=notrunc bs=1 seek=" + startIndex
+ " of=" + path.toAbsolutePath().quotedString();
ChannelExecWrapper sshChannel = null;
int written = 0;
try {
sshChannel = path.getFileSystem().getCommandRunner().open( command );
try (OutputStream out = sshChannel.getOutputStream()) {
WritableByteChannel outChannel = Channels.newChannel( out );
temp.flip();
written = outChannel.write( temp );
}
if ( written > 0 ) {
bytes.position( bytesPosition + written );
}
}
finally {
int exitCode = sshChannel.close();
if ( exitCode != 0 ) {
throw new IOException( "dd failed " + exitCode );
}
}
return written;
}