Given a FileChannel
with length x
and a Bytebuffer
also of length of x
.
What are the circunstances where I read less than x
bytes from the file system ?. Considering that the position of the channel will be always zero (there will be always data to be read) and size of x
can vary from few bytes to whatever big number you can think of.
The only scenario I could identify was when you try to read into an empty buffer / array. My question is more specifically about the underlying JVM / OS behavior.
Sample code
int x = 100;
RandomAccessFile raf = new RandomAccessFile(new File("test"), "rw");
raf.setLength(x);
FileChannel channel = raf.getChannel();
ByteBuffer bb = ByteBuffer.allocate(x);
int read = channel.read(bb, 0);