in jsign-core/src/main/java/net/jsign/ChannelUtils.java [49:69]
public static void copy(SeekableByteChannel src, SeekableByteChannel dest, long length) throws IOException {
ByteBuffer buffer = ByteBuffer.allocate(1024 * 1024);
long remaining = length;
long destOffset = dest.position();
long srcOffset = src.position();
while (remaining > 0) {
int avail = (int) Math.min(remaining, buffer.capacity());
buffer.clear();
buffer.limit(avail);
src.position(srcOffset);
src.read(buffer);
buffer.flip();
dest.position(destOffset);
dest.write(buffer);
remaining -= buffer.position();
srcOffset += buffer.position();
destOffset += buffer.position();
}
}