Java-Byte Ordering

Byte Ordering All primitive types are composed of several bytes: a character or a short integer occupies 2 bytes, a 32-bit integer or a floating-point value occupies 4 bytes, and a long integer or a double precision floating-point value occupies 8 bytes. Each value of one of these multibyte types is stored in a sequence of contiguous memory locations. … Read more…

Java-ByteBuffer to Primitive Buffer

ByteBuffer to Primitive Buffer When doing high-volume Input/Output, odds are you’ll be using ByteBuffers to read in files, receive data from network connections, etc. Once the data has arrived in your ByteBuffer, you’ll need to look at it to decide what to do or manipulate it before sending it along. The ByteBuffer class provides a … Read more…

Java-Lexicographic Comparisons

Lexicographic Comparisons Buffers also support lexicographic comparisons with the compareTo( ) method. This method returns an integer that is negative, zero, or positive if the buffer argument is less than, equal to or greater than, respectively, the object instance on which compareTo( ) was invoked. Like equals( ), compareTo( ) does not allow comparisons between … Read more…

Java-Comparing Elements

Comparing Elements It’s occasionally necessary to compare the data contained in one buffer with that in another buffer. All buffers provide a custom equals( ) method for testing the equality of two buffers. The following example shows you how to compare the byte buffers buf1 and buf2 for equality : The equals() contract for ByteBuffer … Read more…

Java-Slice Buffer

Slice Buffer Slicing a buffer is similar to duplicating, but slice( ) creates a new buffer that starts at the original buffer’s current position and whose capacity is the number of elements remaining in the original buffer (limit – position). The new buffer shares a subsequence of the data elements of the original buffer. The … Read more…

Java-View Buffer

View Buffer Buffers can manage data stored in other buffers. When you create a buffer that manages another buffer’s data, the created buffer is known as view buffer. Changes made in either buffer are reflected in the other. View buffers are created by calling a Buffer subclass’s duplicate( ) method. The resulting view buffer is equivalent … Read more…