ByteBuffer buffer = ByteBuffer.allocate ((int) count); read (buffer, position); buffer.flip(); return target.write (buffer);
final int pageSize = 65536; long total = 0;  while (count > 0) { int transferred = smallTransferTo (position, (int)Math.min (count, pageSize), target); if (transferred < 0) break; total += transferred; position += transferred; count -= transferred; }  return total;
  public long transferTo (long position, long count, WritableByteChannel target)    throws IOException  {    if (position < 0        || count < 0)      throw new IllegalArgumentException ();    if (!isOpen ())      throw new ClosedChannelException ();    if ((mode & READ) == 0)       throw new NonReadableChannelException ();       // XXX: count needs to be casted from long to int. Dataloss ?    ByteBuffer buffer = ByteBuffer.allocate ((int) count);    read (buffer, position);    buffer.flip();    return target.write (buffer);  }