This
- The type of this power buffer.public abstract class PowerBuffer<This extends PowerBuffer<This>> extends Object implements Comparable<This>, Cloneable
ByteBuffer
to provide an enhanced API, e.g. for reading
unsigned integers.
This class is a drop-in replacement for ByteBuffer
, so you can use
a PowerBuffer
wherever you would otherwise use a
ByteBuffer
.Modifier and Type | Method and Description |
---|---|
static PowerBuffer<?> |
allocate(int capacity) |
static PowerBuffer<?> |
allocateDirect(int capacity) |
byte[] |
array() |
int |
arrayOffset() |
CharBuffer |
asCharBuffer() |
DoubleBuffer |
asDoubleBuffer() |
FloatBuffer |
asFloatBuffer() |
abstract ImmutableBuffer |
asImmutableBuffer()
Returns an immutable buffer view of the adapted byte buffer.
|
IntBuffer |
asIntBuffer() |
LongBuffer |
asLongBuffer() |
abstract MutableBuffer |
asMutableBuffer()
Returns a mutable buffer view of the adapted byte buffer.
|
abstract This |
asReadOnlyBuffer() |
ShortBuffer |
asShortBuffer() |
This |
bigEndian()
Sets the byte order to big endian.
|
ByteBuffer |
buffer()
Returns the adapted byte buffer.
|
int |
capacity() |
This |
clear() |
This |
clone()
Like
duplicate() but retains the byte oder, too. |
This |
compact() |
int |
compareTo(This that)
Obtains the adapted byte
buffer() from the given power buffer
and forwards the call to ByteBuffer.compareTo(ByteBuffer) . |
abstract This |
duplicate() |
boolean |
equals(Object that)
Returns
true if and only if the given object is an instance of
this class and this power buffer's adapted byte buffer compares
equal with that power buffer's
adapted byte buffer. |
This |
flip() |
byte |
get() |
This |
get(byte[] dst) |
This |
get(byte[] dst,
int offset,
int length) |
byte |
get(int index) |
char |
getChar() |
char |
getChar(int index) |
double |
getDouble() |
double |
getDouble(int index) |
float |
getFloat() |
float |
getFloat(int index) |
int |
getInt() |
int |
getInt(int index) |
long |
getLong() |
long |
getLong(int index) |
short |
getShort() |
short |
getShort(int index) |
int |
getUByte()
Reads an unsigned byte from the current position.
|
int |
getUByte(int index)
Reads an unsigned byte from the given position.
|
long |
getUInt()
Reads an unsigned int from the current position.
|
long |
getUInt(int index)
Reads an unsigned int from the given position.
|
int |
getUShort()
Reads an unsigned short from the current position.
|
int |
getUShort(int index)
Reads an unsigned short from the given position.
|
boolean |
hasArray() |
int |
hashCode() |
boolean |
hasRemaining() |
boolean |
isDirect() |
abstract boolean |
isMutable()
Returns
true if and only if this power buffer is mutable. |
boolean |
isReadOnly() |
int |
limit() |
This |
limit(int newLimit) |
This |
littleEndian()
Sets the byte order to little endian.
|
This |
load(ReadableByteChannel channel)
Marks this buffer, reads all remaining bytes from the given channel and
resets this buffer.
|
This |
mark() |
ByteOrder |
order() |
This |
order(ByteOrder order) |
int |
position() |
This |
position(int newPosition) |
This |
put(byte b) |
This |
put(byte[] src) |
This |
put(byte[] src,
int offset,
int length) |
This |
put(ByteBuffer src) |
This |
put(int index,
byte b) |
This |
put(PowerBuffer<?> src)
Obtains the adapted byte
buffer() from the given power buffer
and forwards the call to put(ByteBuffer) . |
This |
putChar(char value) |
This |
putChar(int index,
char value) |
This |
putDouble(double value) |
This |
putDouble(int index,
double value) |
This |
putFloat(float value) |
This |
putFloat(int index,
float value) |
This |
putInt(int value) |
This |
putInt(int index,
int value) |
This |
putLong(int index,
long value) |
This |
putLong(long value) |
This |
putShort(int index,
short value) |
This |
putShort(short value) |
int |
remaining() |
This |
reset() |
This |
rewind() |
This |
save(WritableByteChannel channel)
Marks this buffer, writes all remaining bytes to the given channel and
resets this buffer.
|
This |
skip(int skip)
Skips the given number of bytes.
|
abstract This |
slice() |
String |
toString()
Returns a string representation of this object for logging and debugging
purposes.
|
static PowerBuffer<?> |
wrap(byte[] array) |
static PowerBuffer<?> |
wrap(byte[] array,
int offset,
int length) |
static PowerBuffer<?> |
wrap(ByteBuffer buffer) |
public static PowerBuffer<?> allocate(int capacity)
MutableBuffer.allocate(int)
public static PowerBuffer<?> allocateDirect(int capacity)
MutableBuffer.allocateDirect(int)
public byte[] array()
ByteBuffer.array()
public final int arrayOffset()
ByteBuffer.arrayOffset()
public final CharBuffer asCharBuffer()
ByteBuffer.asCharBuffer()
public final DoubleBuffer asDoubleBuffer()
ByteBuffer.asDoubleBuffer()
public final FloatBuffer asFloatBuffer()
ByteBuffer.asFloatBuffer()
public abstract ImmutableBuffer asImmutableBuffer()
order()
.public final IntBuffer asIntBuffer()
ByteBuffer.asIntBuffer()
public final LongBuffer asLongBuffer()
ByteBuffer.asLongBuffer()
public abstract MutableBuffer asMutableBuffer()
order()
.public abstract This asReadOnlyBuffer()
ByteBuffer.asReadOnlyBuffer()
public final ShortBuffer asShortBuffer()
ByteBuffer.asShortBuffer()
public This bigEndian()
this
.public ByteBuffer buffer()
public final int capacity()
Buffer.capacity()
public This clear()
Buffer.clear()
public This clone()
duplicate()
but retains the byte oder, too.clone
in class Object
duplicate()
with the same byte order.public This compact()
ByteBuffer.compact()
public final int compareTo(This that)
buffer()
from the given power buffer
and forwards the call to ByteBuffer.compareTo(ByteBuffer)
.compareTo
in interface Comparable<This extends PowerBuffer<This>>
that
- the power buffer to compare with this power buffer.public abstract This duplicate()
ByteBuffer.duplicate()
public final boolean equals(Object that)
true
if and only if the given object is an instance of
this class and this power buffer's adapted byte buffer compares
equal with that power buffer's
adapted byte buffer.public This flip()
Buffer.flip()
public byte get()
ByteBuffer.get()
public This get(byte[] dst)
ByteBuffer.get(byte[])
public This get(byte[] dst, int offset, int length)
ByteBuffer.get(byte[], int, int)
public final byte get(int index)
ByteBuffer.get(int)
public char getChar()
ByteBuffer.getChar()
public final char getChar(int index)
ByteBuffer.getChar(int)
public double getDouble()
ByteBuffer.getDouble()
public final double getDouble(int index)
ByteBuffer.getDouble(int)
public float getFloat()
ByteBuffer.getFloat()
public final float getFloat(int index)
ByteBuffer.getFloat(int)
public int getInt()
ByteBuffer.getInt()
public final int getInt(int index)
ByteBuffer.getInt(int)
public long getLong()
ByteBuffer.getLong()
public final long getLong(int index)
ByteBuffer.getLong(int)
public short getShort()
ByteBuffer.getShort()
public final short getShort(int index)
ByteBuffer.getShort(int)
public int getUByte()
public final int getUByte(int index)
index
- the index position.public long getUInt()
public final long getUInt(int index)
index
- the index position.public int getUShort()
public final int getUShort(int index)
index
- the index position.public final boolean hasArray()
ByteBuffer.hasArray()
public final int hashCode()
hashCode
in class Object
ByteBuffer.hashCode()
public final boolean hasRemaining()
Buffer.hasRemaining()
public final boolean isDirect()
ByteBuffer.isDirect()
public abstract boolean isMutable()
true
if and only if this power buffer is mutable.public final boolean isReadOnly()
Buffer.isReadOnly()
public final int limit()
Buffer.limit()
public This limit(int newLimit)
Buffer.limit(int)
public This littleEndian()
this
.public This load(ReadableByteChannel channel) throws EOFException, IOException
IOException
occurs or the end-of-file is reached before
this buffer has been entirely filled, then it does not get reset and the
IOException
or an EOFException
gets thrown respectively.channel
- the channel.this
.EOFException
- on unexpected end-of-file.IOException
- on any I/O error.public This mark()
Buffer.mark()
public final ByteOrder order()
ByteBuffer.order()
public This order(ByteOrder order)
ByteBuffer.order(ByteOrder)
public final int position()
Buffer.position()
public This position(int newPosition)
Buffer.position(int)
public This put(byte b)
ByteBuffer.put(byte)
public This put(byte[] src)
ByteBuffer.put(byte[])
public This put(byte[] src, int offset, int length)
ByteBuffer.put(byte[], int, int)
public This put(ByteBuffer src)
ByteBuffer.put(ByteBuffer)
public final This put(int index, byte b)
ByteBuffer.put(int, byte)
public final This put(PowerBuffer<?> src)
buffer()
from the given power buffer
and forwards the call to put(ByteBuffer)
.src
- the power buffer with the contents to put into this power
buffer.this
public This putChar(char value)
ByteBuffer.putChar(char)
public final This putChar(int index, char value)
ByteBuffer.putChar(int, char)
public This putDouble(double value)
ByteBuffer.putDouble(double)
public final This putDouble(int index, double value)
ByteBuffer.putDouble(int, double)
public This putFloat(float value)
ByteBuffer.putFloat(float)
public final This putFloat(int index, float value)
ByteBuffer.putFloat(int, float)
public This putInt(int value)
ByteBuffer.putInt(int)
public final This putInt(int index, int value)
ByteBuffer.putInt(int, int)
public final This putLong(int index, long value)
ByteBuffer.putLong(int, long)
public This putLong(long value)
ByteBuffer.putLong(long)
public final This putShort(int index, short value)
ByteBuffer.putShort(int, short)
public This putShort(short value)
ByteBuffer.putShort(short)
public final int remaining()
Buffer.remaining()
public This reset()
Buffer.reset()
public This rewind()
Buffer.rewind()
public This save(WritableByteChannel channel) throws IOException
IOException
occurs, then this buffer does not get reset
and the IOException
gets thrown.channel
- the channel.this
.IOException
- on any I/O error.public This skip(int skip)
skip
- the number of bytes to move forwards.
May be negative to move backwards, too.this
.IllegalArgumentException
- if attempting to move outside the
buffer bounds.public abstract This slice()
ByteBuffer.slice()
public final String toString()
public static PowerBuffer<?> wrap(byte[] array)
MutableBuffer.wrap(byte[])
public static PowerBuffer<?> wrap(byte[] array, int offset, int length)
MutableBuffer.wrap(byte[], int, int)
public static PowerBuffer<?> wrap(ByteBuffer buffer)
MutableBuffer.wrap(ByteBuffer)
Copyright © 2012–2015 Schlichtherle IT Services. All rights reserved.