Chapter 11, PP 431: Compacting a buffer.
I am having difficulty understanding this code, more specifically understanding the first nested if statements being the double buffer and reading into the compacting buffer. At what value would the file stop reading into the buffer? Would EOF be encountered at the space that is between the double value being read into the compacted buffer and the string(contents of the file primes.txt)? I understand the first if statement being fulfilled with buf.remaining() being 0 at first. But then, with the String buffer if-statement, being if(buf.remaining()< 2*strLength), the remaining bytes would be 248, which is not less than the current string length. Wouldnt this mean that the nested if statement following this(the read statement) would not be executed because its parent if-statement is not fulfilled? I am having difficulty understanding the explanation given. I need to understand how this code works by having these doubts answered. Thank you, all help is much appreciated, but a direct explanation would be of greater help.
My book shows the first nested if-statements as such:
if(buf.remaining < 8)
if(inCh.read(buf.compact())== -1)
|