Mon 23 Oct 2006
CharBuffer charBuffer = CharBuffer.wrap (”Hello World”); The three-argument
Posted by sales under techniquesCharBuffer charBuffer = CharBuffer.wrap (”Hello World”); The three-argument form takes start and end index positions describing a subsequence of the given CharSequence. This is a convenience pass-through to CharSequence.subsequence(). The start argument is the first character in the sequence to use; end is the last position of the character plus one. 2.3 Duplicating Buffers As we just discussed, buffer objects can be created that describe data elements stored externally in an array. But buffers are not limited to managing external data in arrays. They can also manage data externally in other buffers. When a buffer that manages data elements contained in another buffer is created, it’s known as a view buffer. Most view buffers are views of ByteBuffers (see Section 2.4.3). Before moving on to the specifics of byte buffers, we’ll concentrate on the views that are common to all buffer types. View buffers are always created by calling methods on an existing buffer instance. Using a factory method on an existing buffer instance means that the view object will be privy to internal implementation details of the original buffer. It will be able to access the data elements directly, whether they are stored in an array or by some other means, rather than going through the get()/put() API of the original buffer object. If the original buffer is direct, views of that buffer will have the same efficiency advantages. Likewise for mapped buffers (discussed in Chapter 3). In this section, we’ll again use CharBuffer as an example, but the same operations can be done on any of the primary buffer types (see Figure 2-1). public abstract class CharBuffer extends Buffer implements CharSequence, Comparable { // This is a partial API listing public abstract CharBuffer duplicate(); public abstract CharBuffer asReadOnlyBuffer(); public abstract CharBuffer slice(); } The duplicate() method creates a new buffer that is just like the original. Both buffers share the data elements and have the same capacity, but each buffer will have its own position, limit, and mark. Changes made to data elements in one buffer will be reflected in the other. The duplicate buffer has the same view of the data as the original buffer. If the original buffer is read-only, or direct, the new buffer will inherit those attributes. Direct buffers are discussed in Section 2.4.2. Duplicating a buffer creates a new Buffer object but does not make a copy of the data. Both the original buffer and the copy will act upon the same data elements. 44
Note: If you are looking for inexpensive but high quality provider to host and run your jsp application check Astra jsp hosting services