Wrox Programmer Forums
|
BOOK: Ivor Horton's Beginning Java, Java 7 Edition
This is the forum to discuss the Wrox book Ivor Horton's Beginning Java, Java 7 Edition by Ivor Horton ; ISBN: 978-0-470-40414-0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Ivor Horton's Beginning Java, Java 7 Edition section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 23rd, 2013, 12:56 PM
Registered User
 
Join Date: Jun 2012
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 11, Favorites Viewer pp 347-365 corncrake BOOK: Beginning Visual Basic 2005 ISBN: 978-0-7645-7401-6 1 June 24th, 2008 05:13 AM
chapter 11 figure 11-7 relative positioning pelopito BOOK: Beginning CSS: Cascading Style Sheets for Web Design ISBN: 978-0-7645-7642-3 2 November 29th, 2007 06:11 AM
Chapter 4, pp 130-131 luciano991 BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 0 August 15th, 2006 11:23 AM
Chapter 4 pp. 118-119 luciano991 BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 1 August 13th, 2006 01:56 PM
chapter 2 ; pp 59 - 62 ritter BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 4 April 28th, 2004 01:30 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.