io2 = (RubyIO) arg2;
} else {
throw runtime.newTypeError("Should be String or IO");
}
ChannelDescriptor d1 = io1.openFile.getMainStreamSafe().getDescriptor();
ChannelDescriptor d2 = io2.openFile.getMainStreamSafe().getDescriptor();
if (!d1.isReadable()) throw runtime.newIOError("from IO is not readable");
if (!d2.isWritable()) throw runtime.newIOError("from IO is not writable");
try {
long size = 0;
if (!d1.isSeekable()) {
if (!d2.isSeekable()) {
throw context.runtime.newTypeError("only supports to file or from file copy");
} else {
ReadableByteChannel from = (ReadableByteChannel)d1.getChannel();
FileChannel to = (FileChannel)d2.getChannel();
size = transfer(from, to);
}
} else {
FileChannel from = (FileChannel)d1.getChannel();
WritableByteChannel to = (WritableByteChannel)d2.getChannel();
size = transfer(from, to);
}
return context.runtime.newFixnum(size);