*/
public static void copy(Bucket src, Bucket dst) throws IOException {
OutputStream out = dst.getOutputStreamUnbuffered();
InputStream in = src.getInputStreamUnbuffered();
ReadableByteChannel readChannel = Channels.newChannel(in);
WritableByteChannel writeChannel = Channels.newChannel(out);
try {
// No benefit to allocateDirect() as we're wrapping streams anyway, and worse, it'd be a memory leak.
ByteBuffer buffer = ByteBuffer.allocate(BUFFER_SIZE);
while (readChannel.read(buffer) != -1) {
buffer.flip();
while(buffer.hasRemaining())
writeChannel.write(buffer);
buffer.clear();
}
} finally {
writeChannel.close();
readChannel.close();
}
}