Methods Summary |
---|
public static void | close(java.nio.channels.SelectionKey key)
try {
key.channel().close();
} catch (IOException e) {
// nop
}
|
public static java.nio.ByteBuffer | readFully(java.nio.channels.ReadableByteChannel channel, long size)
if (channel instanceof FileChannel && size > 1024 * 1024) {
ByteBuffer bb = ((FileChannel) channel).map(FileChannel.MapMode.READ_ONLY, ((FileChannel) channel).position(), size);
((FileChannel) channel).position(((FileChannel) channel).position() + size);
return bb;
} else {
ByteBuffer buf = ByteBuffer.allocate(l2i(size));
readFully(channel, buf, buf.limit());
buf.rewind();
assert buf.limit() == size;
return buf;
}
|
public static void | readFully(java.nio.channels.ReadableByteChannel channel, java.nio.ByteBuffer buf)
readFully(channel, buf, buf.remaining());
|
public static int | readFully(java.nio.channels.ReadableByteChannel channel, java.nio.ByteBuffer buf, int length)
int n, count = 0;
while (-1 != (n = channel.read(buf))) {
count += n;
if (count == length) {
break;
}
}
if (n == -1) {
throw new EOFException("End of file. No more boxes.");
}
return count;
|
public static void | writeFully(java.nio.channels.WritableByteChannel channel, java.nio.ByteBuffer buf)
do {
int written = channel.write(buf);
if (written < 0) {
throw new EOFException();
}
} while (buf.hasRemaining());
|