Pro Java 7 NIO.2 by Anghel Leonard

Pro Java 7 NIO.2 by Anghel Leonard

Author:Anghel Leonard [Leonard, Anghel]
Language: eng
Format: epub, pdf
ISBN: 9781430240112
Publisher: Apress
Published: 2011-11-28T05:00:00+00:00


Figure 7-3 Java buffer representation (c)

Next, suppose that we read 2 bytes of data into our buffer. The 2 bytes of data go into the buffer starting at position 0. Therefore, the first 2 bytes are filled and the position goes to the third byte, as shown in Figure 7-4.

Figure 7-4 Java buffer representation (d)

Continuing with a second read, another 3 bytes go into the buffer. The position is increased to 5 (slot 6), as you can see in Figure 7-5.

Figure 7-5 Java buffer representation (e)

At this point, suppose that we are not reading into the buffer anymore and want to write from the buffer. To do this, we first need to call the flip() method before we write any bytes. This will set the limit to the current position, and set the position to 0. After the flip, the buffer appears as shown in Figure 7-6.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.