Can anybody please tell me why there is no copy(Large) methods, for channels, in IOUtils class?
Are those functionalities implemented in any other class? Or is it unnecessary?
Or is it just that those methods are not defined yet?
I'm not particularly a fan of 3rd party utilities and, consequently, using another library, such as Guava, is not an option.
Moreover, I'm asking about the functionalities just because Commons-IO is, transitively, on my classpath.
static long copy1(ReadableByteChannel source, WritableByteChannel target,
ByteBuffer buffer) {
long count = 0L;
while (source.read(buffer) != -1) {
for (buffer.flip(); buffer.hasRemaining();) {
count += target.write(buffer);
}
buffer.clear();
}
return count;
}
static long copy2(ReadableByteChannel source, WritableByteChannel target,
ByteBuffer buffer) {
long count = 0L;
while (source.read(buffer) != -1) {
buffer.flip();
count += target.write(buffer);
buffer.compact();
}
for (buffer.flip(); buffer.hasRemaining(); ) {
target.write(buffer);
}
return count;
}