|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.nio.Buffer java.nio.ByteBuffer java.nio.HeapByteBuffer java.nio.HeapByteBufferR
A read-only HeapByteBuffer. This class extends the corresponding
read/write class, overriding the mutation methods to throw a ReadOnlyBufferException
and overriding the view-buffer methods to return an
instance of this class rather than of the superclass.
Field Summary |
Fields inherited from class java.nio.ByteBuffer |
bigEndian, hb, isReadOnly, nativeByteOrder, offset |
Fields inherited from class java.nio.Buffer |
address |
Constructor Summary | |
(package private) |
HeapByteBufferR(byte[] buf,
int off,
int len)
|
protected |
HeapByteBufferR(byte[] buf,
int mark,
int pos,
int lim,
int cap,
int off)
|
(package private) |
HeapByteBufferR(int cap,
int lim)
|
Method Summary | |
(package private) byte |
_get(int i)
|
(package private) void |
_put(int i,
byte b)
|
CharBuffer |
asCharBuffer()
Creates a view of this byte buffer as a char buffer. |
DoubleBuffer |
asDoubleBuffer()
Creates a view of this byte buffer as a double buffer. |
FloatBuffer |
asFloatBuffer()
Creates a view of this byte buffer as a float buffer. |
IntBuffer |
asIntBuffer()
Creates a view of this byte buffer as an int buffer. |
LongBuffer |
asLongBuffer()
Creates a view of this byte buffer as a long buffer. |
ByteBuffer |
asReadOnlyBuffer()
Creates a new, read-only byte buffer that shares this buffer's content. |
ShortBuffer |
asShortBuffer()
Creates a view of this byte buffer as a short buffer. |
ByteBuffer |
compact()
Compacts this buffer (optional operation). |
ByteBuffer |
duplicate()
Creates a new byte buffer that shares this buffer's content. |
byte |
get()
Relative get method. |
ByteBuffer |
get(byte[] dst,
int offset,
int length)
Relative bulk get method. |
byte |
get(int i)
Absolute get method. |
char |
getChar()
Relative get method for reading a char value. |
char |
getChar(int i)
Absolute get method for reading a char value. |
double |
getDouble()
Relative get method for reading a double value. |
double |
getDouble(int i)
Absolute get method for reading a double value. |
float |
getFloat()
Relative get method for reading a float value. |
float |
getFloat(int i)
Absolute get method for reading a float value. |
int |
getInt()
Relative get method for reading an int value. |
int |
getInt(int i)
Absolute get method for reading an int value. |
long |
getLong()
Relative get method for reading a long value. |
long |
getLong(int i)
Absolute get method for reading a long value. |
short |
getShort()
Relative get method for reading a short value. |
short |
getShort(int i)
Absolute get method for reading a short value. |
boolean |
isDirect()
Tells whether or not this byte buffer is direct. |
boolean |
isReadOnly()
Tells whether or not this buffer is read-only. |
protected int |
ix(int i)
|
ByteBuffer |
put(byte x)
Relative put method (optional operation). |
ByteBuffer |
put(byte[] src,
int offset,
int length)
Relative bulk put method (optional operation). |
ByteBuffer |
put(ByteBuffer src)
Relative bulk put method (optional operation). |
ByteBuffer |
put(int i,
byte x)
Absolute put method (optional operation). |
ByteBuffer |
putChar(char x)
Relative put method for writing a char value (optional operation). |
ByteBuffer |
putChar(int i,
char x)
Absolute put method for writing a char value (optional operation). |
ByteBuffer |
putDouble(double x)
Relative put method for writing a double value (optional operation). |
ByteBuffer |
putDouble(int i,
double x)
Absolute put method for writing a double value (optional operation). |
ByteBuffer |
putFloat(float x)
Relative put method for writing a float value (optional operation). |
ByteBuffer |
putFloat(int i,
float x)
Absolute put method for writing a float value (optional operation). |
ByteBuffer |
putInt(int x)
Relative put method for writing an int value (optional operation). |
ByteBuffer |
putInt(int i,
int x)
Absolute put method for writing an int value (optional operation). |
ByteBuffer |
putLong(int i,
long x)
Absolute put method for writing a long value (optional operation). |
ByteBuffer |
putLong(long x)
Relative put method for writing a long value (optional operation). |
ByteBuffer |
putShort(int i,
short x)
Absolute put method for writing a short value (optional operation). |
ByteBuffer |
putShort(short x)
Relative put method for writing a short value (optional operation). |
ByteBuffer |
slice()
Creates a new byte buffer whose content is a shared subsequence of this buffer's content. |
Methods inherited from class java.nio.ByteBuffer |
allocate, allocateDirect, array, arrayOffset, compareTo, equals, get, hasArray, hashCode, order, order, put, toString, wrap, wrap |
Methods inherited from class java.nio.Buffer |
capacity, checkBounds, checkIndex, checkIndex, clear, flip, hasRemaining, limit, limit, mark, markValue, nextGetIndex, nextGetIndex, nextPutIndex, nextPutIndex, position, position, remaining, reset, rewind |
Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
HeapByteBufferR(int cap, int lim)
HeapByteBufferR(byte[] buf, int off, int len)
protected HeapByteBufferR(byte[] buf, int mark, int pos, int lim, int cap, int off)
Method Detail |
public ByteBuffer slice()
ByteBuffer
The content of the new buffer will start at this buffer's current position. Changes to this buffer's content will be visible in the new buffer, and vice versa; the two buffers' position, limit, and mark values will be independent.
The new buffer's position will be zero, its capacity and its limit will be the number of bytes remaining in this buffer, and its mark will be undefined. The new buffer will be direct if, and only if, this buffer is direct, and it will be read-only if, and only if, this buffer is read-only.
slice
in class HeapByteBuffer
public ByteBuffer duplicate()
ByteBuffer
The content of the new buffer will be that of this buffer. Changes to this buffer's content will be visible in the new buffer, and vice versa; the two buffers' position, limit, and mark values will be independent.
The new buffer's capacity, limit, position, and mark values will be identical to those of this buffer. The new buffer will be direct if, and only if, this buffer is direct, and it will be read-only if, and only if, this buffer is read-only.
duplicate
in class HeapByteBuffer
public ByteBuffer asReadOnlyBuffer()
ByteBuffer
The content of the new buffer will be that of this buffer. Changes to this buffer's content will be visible in the new buffer; the new buffer itself, however, will be read-only and will not allow the shared content to be modified. The two buffers' position, limit, and mark values will be independent.
The new buffer's capacity, limit, position, and mark values will be identical to those of this buffer.
If this buffer is itself read-only then this method behaves in
exactly the same way as the duplicate
method.
asReadOnlyBuffer
in class HeapByteBuffer
public boolean isReadOnly()
Buffer
isReadOnly
in class HeapByteBuffer
public ByteBuffer put(byte x)
ByteBuffer
Writes the given byte into this buffer at the current position, and then increments the position.
put
in class HeapByteBuffer
public ByteBuffer put(int i, byte x)
ByteBuffer
Writes the given byte into this buffer at the given index.
put
in class HeapByteBuffer
public ByteBuffer put(byte[] src, int offset, int length)
ByteBuffer
This method transfers bytes into this buffer from the given
source array. If there are more bytes to be copied from the array
than remain in this buffer, that is, if
length > remaining(), then no
bytes are transferred and a BufferOverflowException
is
thrown.
Otherwise, this method copies length bytes from the given array into this buffer, starting at the given offset in the array and at the current position of this buffer. The position of this buffer is then incremented by length.
In other words, an invocation of this method of the form dst.put(src, off, len) has exactly the same effect as the loop
for (int i = off; i < off + len; i++) dst.put(a[i]);except that it first checks that there is sufficient space in this buffer and it is potentially much more efficient.
put
in class HeapByteBuffer
public ByteBuffer put(ByteBuffer src)
ByteBuffer
This method transfers the bytes remaining in the given source
buffer into this buffer. If there are more bytes remaining in the
source buffer than in this buffer, that is, if
src.remaining() > remaining(),
then no bytes are transferred and a BufferOverflowException
is thrown.
Otherwise, this method copies n = src.remaining() bytes from the given buffer into this buffer, starting at each buffer's current position. The positions of both buffers are then incremented by n.
In other words, an invocation of this method of the form dst.put(src) has exactly the same effect as the loop
while (src.hasRemaining()) dst.put(src.get());except that it first checks that there is sufficient space in this buffer and it is potentially much more efficient.
put
in class HeapByteBuffer
public ByteBuffer compact()
ByteBuffer
The bytes between the buffer's current position and its limit, if any, are copied to the beginning of the buffer. That is, the byte at index p = position() is copied to index zero, the byte at index p + 1 is copied to index one, and so forth until the byte at index limit() - 1 is copied to index n = limit() - 1 - p. The buffer's position is then set to n+1 and its limit is set to its capacity. The mark, if defined, is discarded.
The buffer's position is set to the number of bytes copied, rather than to zero, so that an invocation of this method can be followed immediately by an invocation of another relative put method.
Invoke this method after writing data from a buffer in case the write was incomplete. The following loop, for example, copies bytes from one channel to another via the buffer buf:
buf.clear(); // Prepare buffer for use for (;;) { if (in.read(buf) < 0 && !buf.hasRemaining()) break; // No more bytes to transfer buf.flip(); out.write(buf); buf.compact(); // In case of partial write }
compact
in class HeapByteBuffer
byte _get(int i)
_get
in class HeapByteBuffer
void _put(int i, byte b)
_put
in class HeapByteBuffer
public ByteBuffer putChar(char x)
ByteBuffer
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.
putChar
in class HeapByteBuffer
public ByteBuffer putChar(int i, char x)
ByteBuffer
Writes two bytes containing the given char value, in the current byte order, into this buffer at the given index.
putChar
in class HeapByteBuffer
public CharBuffer asCharBuffer()
ByteBuffer
The content of the new buffer will start at this buffer's current position. Changes to this buffer's content will be visible in the new buffer, and vice versa; the two buffers' position, limit, and mark values will be independent.
The new buffer's position will be zero, its capacity and its limit will be the number of bytes remaining in this buffer divided by two, and its mark will be undefined. The new buffer will be direct if, and only if, this buffer is direct, and it will be read-only if, and only if, this buffer is read-only.
asCharBuffer
in class HeapByteBuffer
public ByteBuffer putShort(short x)
ByteBuffer
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.
putShort
in class HeapByteBuffer
public ByteBuffer putShort(int i, short x)
ByteBuffer
Writes two bytes containing the given short value, in the current byte order, into this buffer at the given index.
putShort
in class HeapByteBuffer
public ShortBuffer asShortBuffer()
ByteBuffer
The content of the new buffer will start at this buffer's current position. Changes to this buffer's content will be visible in the new buffer, and vice versa; the two buffers' position, limit, and mark values will be independent.
The new buffer's position will be zero, its capacity and its limit will be the number of bytes remaining in this buffer divided by two, and its mark will be undefined. The new buffer will be direct if, and only if, this buffer is direct, and it will be read-only if, and only if, this buffer is read-only.
asShortBuffer
in class HeapByteBuffer
public ByteBuffer putInt(int x)
ByteBuffer
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.
putInt
in class HeapByteBuffer
public ByteBuffer putInt(int i, int x)
ByteBuffer
Writes four bytes containing the given int value, in the current byte order, into this buffer at the given index.
putInt
in class HeapByteBuffer
public IntBuffer asIntBuffer()
ByteBuffer
The content of the new buffer will start at this buffer's current position. Changes to this buffer's content will be visible in the new buffer, and vice versa; the two buffers' position, limit, and mark values will be independent.
The new buffer's position will be zero, its capacity and its limit will be the number of bytes remaining in this buffer divided by four, and its mark will be undefined. The new buffer will be direct if, and only if, this buffer is direct, and it will be read-only if, and only if, this buffer is read-only.
asIntBuffer
in class HeapByteBuffer
public ByteBuffer putLong(long x)
ByteBuffer
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.
putLong
in class HeapByteBuffer
public ByteBuffer putLong(int i, long x)
ByteBuffer
Writes eight bytes containing the given long value, in the current byte order, into this buffer at the given index.
putLong
in class HeapByteBuffer
public LongBuffer asLongBuffer()
ByteBuffer
The content of the new buffer will start at this buffer's current position. Changes to this buffer's content will be visible in the new buffer, and vice versa; the two buffers' position, limit, and mark values will be independent.
The new buffer's position will be zero, its capacity and its limit will be the number of bytes remaining in this buffer divided by eight, and its mark will be undefined. The new buffer will be direct if, and only if, this buffer is direct, and it will be read-only if, and only if, this buffer is read-only.
asLongBuffer
in class HeapByteBuffer
public ByteBuffer putFloat(float x)
ByteBuffer
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.
putFloat
in class HeapByteBuffer
public ByteBuffer putFloat(int i, float x)
ByteBuffer
Writes four bytes containing the given float value, in the current byte order, into this buffer at the given index.
putFloat
in class HeapByteBuffer
public FloatBuffer asFloatBuffer()
ByteBuffer
The content of the new buffer will start at this buffer's current position. Changes to this buffer's content will be visible in the new buffer, and vice versa; the two buffers' position, limit, and mark values will be independent.
The new buffer's position will be zero, its capacity and its limit will be the number of bytes remaining in this buffer divided by four, and its mark will be undefined. The new buffer will be direct if, and only if, this buffer is direct, and it will be read-only if, and only if, this buffer is read-only.
asFloatBuffer
in class HeapByteBuffer
public ByteBuffer putDouble(double x)
ByteBuffer
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.
putDouble
in class HeapByteBuffer
public ByteBuffer putDouble(int i, double x)
ByteBuffer
Writes eight bytes containing the given double value, in the current byte order, into this buffer at the given index.
putDouble
in class HeapByteBuffer
public DoubleBuffer asDoubleBuffer()
ByteBuffer
The content of the new buffer will start at this buffer's current position. Changes to this buffer's content will be visible in the new buffer, and vice versa; the two buffers' position, limit, and mark values will be independent.
The new buffer's position will be zero, its capacity and its limit will be the number of bytes remaining in this buffer divided by eight, and its mark will be undefined. The new buffer will be direct if, and only if, this buffer is direct, and it will be read-only if, and only if, this buffer is read-only.
asDoubleBuffer
in class HeapByteBuffer
protected int ix(int i)
public byte get()
ByteBuffer
get
in class ByteBuffer
public byte get(int i)
ByteBuffer
get
in class ByteBuffer
i
- The index from which the byte will be read
public ByteBuffer get(byte[] dst, int offset, int length)
ByteBuffer
This method transfers bytes from this buffer into the given
destination array. If there are fewer bytes remaining in the
buffer than are required to satisfy the request, that is, if
length > remaining(), then no
bytes are transferred and a BufferUnderflowException
is
thrown.
Otherwise, this method copies length bytes from this buffer into the given array, starting at the current position of this buffer and at the given offset in the array. The position of this buffer is then incremented by length.
In other words, an invocation of this method of the form src.get(dst, off, len) has exactly the same effect as the loop
for (int i = off; i < off + len; i++) dst[i] = src.get();except that it first checks that there are sufficient bytes in this buffer and it is potentially much more efficient.
get
in class ByteBuffer
dst
- The array into which bytes are to be writtenoffset
- The offset within the array of the first byte to be
written; must be non-negative and no larger than
dst.lengthlength
- The maximum number of bytes to be written to the given
array; must be non-negative and no larger than
dst.length - offset
public boolean isDirect()
ByteBuffer
isDirect
in class ByteBuffer
public char getChar()
ByteBuffer
Reads the next two bytes at this buffer's current position, composing them into a char value according to the current byte order, and then increments the position by two.
getChar
in class ByteBuffer
public char getChar(int i)
ByteBuffer
Reads two bytes at the given index, composing them into a char value according to the current byte order.
getChar
in class ByteBuffer
i
- The index from which the bytes will be read
public short getShort()
ByteBuffer
Reads the next two bytes at this buffer's current position, composing them into a short value according to the current byte order, and then increments the position by two.
getShort
in class ByteBuffer
public short getShort(int i)
ByteBuffer
Reads two bytes at the given index, composing them into a short value according to the current byte order.
getShort
in class ByteBuffer
i
- The index from which the bytes will be read
public int getInt()
ByteBuffer
Reads the next four bytes at this buffer's current position, composing them into an int value according to the current byte order, and then increments the position by four.
getInt
in class ByteBuffer
public int getInt(int i)
ByteBuffer
Reads four bytes at the given index, composing them into a int value according to the current byte order.
getInt
in class ByteBuffer
i
- The index from which the bytes will be read
public long getLong()
ByteBuffer
Reads the next eight bytes at this buffer's current position, composing them into a long value according to the current byte order, and then increments the position by eight.
getLong
in class ByteBuffer
public long getLong(int i)
ByteBuffer
Reads eight bytes at the given index, composing them into a long value according to the current byte order.
getLong
in class ByteBuffer
i
- The index from which the bytes will be read
public float getFloat()
ByteBuffer
Reads the next four bytes at this buffer's current position, composing them into a float value according to the current byte order, and then increments the position by four.
getFloat
in class ByteBuffer
public float getFloat(int i)
ByteBuffer
Reads four bytes at the given index, composing them into a float value according to the current byte order.
getFloat
in class ByteBuffer
i
- The index from which the bytes will be read
public double getDouble()
ByteBuffer
Reads the next eight bytes at this buffer's current position, composing them into a double value according to the current byte order, and then increments the position by eight.
getDouble
in class ByteBuffer
public double getDouble(int i)
ByteBuffer
Reads eight bytes at the given index, composing them into a double value according to the current byte order.
getDouble
in class ByteBuffer
i
- The index from which the bytes will be read
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |