ByteBuffer class Methods in Java Part- III

java.nio.ByteBuffer

A byte buffer.

This class defines six categories of operations upon byte buffers:

1. Absolute and relative get and put methods that read and write single bytes.

2. Absolute and relative bulk get methods that transfer contiguous sequences of bytes from this buffer into an array.

3. Absolute and Relative bulk put methods that transfer contiguous sequences of bytes from a byte array or some other bytebuffer into this buffer.

4. Absolute and relative get and put methods that read and write values of other primitive types, translating them to and from sequences of bytes in particular byte order.

5.  Methods for creating view buffers, which allow a byte buffer to be viewed as a buffer containing values of some other primitive type.

6. A method for compacting a byte buffer.


Some methods of ByteBuffer class


order()The byte order is used when reading or writing multibyte values, and when creating buffers that are views of this byte buffer. 


position()It returns this buffer's position or This method sets this buffer's position.


put(byte)It writes the given byte into this buffer at the current position and then increments the position.


put(byte[])It transfers the entire content of the given source byte array into this buffer.


put(ByteBuffer): It transfers the bytes remaining in the given source buffer into this buffer.


put(int, byte): It writes the given byte into this buffer at the given index.


put(int , byte[]) It copies bytes into this buffer from the given source array. 


put(byte[], int, int)It transfers bytes into this buffer from the given source array.


put(int, byte[], int, int)It transfers length bytes from the given array, starting at the given offset in the array and at the given index in this buffer.


putChar() It writes two bytes containing the given char value, in the current byte order, into this buffer at the current position, and then increments the position by two.


putDouble()It writes eight bytes containing the given double value, in the current byte order, into this buffer at the current position, and then increments the position by eight.


putFloat() It writes four bytes containing the given float value, in the current byte order, into this buffer at the current position, and then increments the position by four.


putInt(). It writes four bytes containing the given int value, in the current byte order, into this buffer at the current position, and then increments the position by four.


putLong()It writes eight bytes containing the given long value, in the current byte order, into this buffer at the current position, and then increments the position by eight.


putShort() It writes two bytes containing the given short value, in the current byte order, into this buffer at the current position, and then increments the position by two.


remaining()It returns the number of elements between the current position and the limit.


reset()It resets this buffer's position to the previously marked position.


rewind()It rewinds this buffer. The position is set to zero and the mark is discarded.


slice()It creates a new byte buffer whose content is a shared subsequence of this buffer's content.


toString()It returns a string summarizing the state of this buffer.


ByteBuffer.wrap()It wraps a byte array into a buffer.







No comments:

Post a Comment