Class AbstractIoBuffer
- java.lang.Object
-
- com.google.code.yanf4j.buffer.IoBuffer
-
- com.google.code.yanf4j.buffer.AbstractIoBuffer
-
- All Implemented Interfaces:
java.lang.Comparable<IoBuffer>
- Direct Known Subclasses:
CachedBufferAllocator.CachedBuffer,SimpleBufferAllocator.SimpleBuffer
public abstract class AbstractIoBuffer extends IoBuffer
A base implementation ofIoBuffer. This implementation assumes thatIoBuffer.buf()always returns a correct NIOByteBufferinstance. Most implementations could extend this class and implement their own buffer management mechanism.- Version:
- $Rev: 748210 $, $Date: 2009-02-26 18:05:40 +0100 (Thu, 26 Feb 2009) $
- See Also:
IoBufferAllocator
-
-
Field Summary
Fields Modifier and Type Field Description private booleanautoExpandA flag set to true if the buffer can extend automaticallyprivate booleanautoShrinkA flag set to true if the buffer can shrink automaticallyprivate static longBYTE_MASKA mask for a byteprivate booleanderivedTells if a buffer has been created from an existing bufferprivate static longINT_MASKA mask for an intprivate intmarkWe don't have any access to Buffer.markValue(), so we need to track it down, which will cause small extra overhead.private intminimumCapacityThe minimum number of bytes the IoBuffer can holdprivate booleanrecapacityAllowedTells if a buffer can be expandedprivate static longSHORT_MASKA mask for a short
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractIoBuffer(AbstractIoBuffer parent)Creates a new derived buffer.protectedAbstractIoBuffer(IoBufferAllocator allocator, int initialCapacity)Creates a new parent buffer.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description java.nio.CharBufferasCharBuffer()java.nio.DoubleBufferasDoubleBuffer()java.nio.FloatBufferasFloatBuffer()java.io.InputStreamasInputStream()Returns anInputStreamthat reads the data from this buffer.java.nio.IntBufferasIntBuffer()java.nio.LongBufferasLongBuffer()java.io.OutputStreamasOutputStream()Returns anOutputStreamthat appends the data into this buffer.IoBufferasReadOnlyBuffer()protected abstract IoBufferasReadOnlyBuffer0()Implement this method to return the unexpandable read only version of this buffer.java.nio.ShortBufferasShortBuffer()private IoBufferautoExpand(int expectedRemaining)This method forwards the call toexpand(int)only when autoExpand property is true.private IoBufferautoExpand(int pos, int expectedRemaining)This method forwards the call toexpand(int)only when autoExpand property is true.protected abstract voidbuf(java.nio.ByteBuffer newBuf)Sets the underlying NIO buffer instance.intcapacity()IoBuffercapacity(int newCapacity)Increases the capacity of this buffer.private static voidcheckFieldSize(int fieldSize)IoBufferclear()IoBuffercompact()intcompareTo(IoBuffer that)IoBufferduplicate()protected abstract IoBufferduplicate0()Implement this method to return the unexpandable duplicate of this buffer.private java.lang.StringenumConversionErrorMessage(java.lang.Enum<?> e, java.lang.String type)booleanequals(java.lang.Object o)IoBufferexpand(int expectedRemaining)Changes the capacity and limit of this buffer so this buffer get the specified expectedRemaining room from the current position.private IoBufferexpand(int expectedRemaining, boolean autoExpand)IoBufferexpand(int pos, int expectedRemaining)Changes the capacity and limit of this buffer so this buffer get the specified expectedRemaining room from the specified position.private IoBufferexpand(int pos, int expectedRemaining, boolean autoExpand)IoBufferfill(byte value, int size)Fills this buffer with the specified value.IoBufferfill(int size)Fills this buffer withNUL (0x00).IoBufferfillAndReset(byte value, int size)Fills this buffer with the specified value.IoBufferfillAndReset(int size)Fills this buffer withNUL (0x00).IoBufferflip()byteget()IoBufferget(byte[] dst)IoBufferget(byte[] dst, int offset, int length)byteget(int index)chargetChar()chargetChar(int index)doublegetDouble()doublegetDouble(int index)<E extends java.lang.Enum<E>>
EgetEnum(int index, java.lang.Class<E> enumClass)Reads a byte from the buffer and returns the correlating enum constant defined by the specified enum type.<E extends java.lang.Enum<E>>
EgetEnum(java.lang.Class<E> enumClass)Reads a byte from the buffer and returns the correlating enum constant defined by the specified enum type.<E extends java.lang.Enum<E>>
EgetEnumInt(int index, java.lang.Class<E> enumClass)Reads an int from the buffer and returns the correlating enum constant defined by the specified enum type.<E extends java.lang.Enum<E>>
EgetEnumInt(java.lang.Class<E> enumClass)Reads an int from the buffer and returns the correlating enum constant defined by the specified enum type.<E extends java.lang.Enum<E>>
java.util.EnumSet<E>getEnumSet(int index, java.lang.Class<E> enumClass)Reads a byte sized bit vector and converts it to anEnumSet.<E extends java.lang.Enum<E>>
java.util.EnumSet<E>getEnumSet(java.lang.Class<E> enumClass)Reads a byte sized bit vector and converts it to anEnumSet.<E extends java.lang.Enum<E>>
java.util.EnumSet<E>getEnumSetInt(int index, java.lang.Class<E> enumClass)Reads an int sized bit vector and converts it to anEnumSet.<E extends java.lang.Enum<E>>
java.util.EnumSet<E>getEnumSetInt(java.lang.Class<E> enumClass)Reads an int sized bit vector and converts it to anEnumSet.<E extends java.lang.Enum<E>>
java.util.EnumSet<E>getEnumSetLong(int index, java.lang.Class<E> enumClass)Reads a long sized bit vector and converts it to anEnumSet.<E extends java.lang.Enum<E>>
java.util.EnumSet<E>getEnumSetLong(java.lang.Class<E> enumClass)Reads a long sized bit vector and converts it to anEnumSet.<E extends java.lang.Enum<E>>
java.util.EnumSet<E>getEnumSetShort(int index, java.lang.Class<E> enumClass)Reads a short sized bit vector and converts it to anEnumSet.<E extends java.lang.Enum<E>>
java.util.EnumSet<E>getEnumSetShort(java.lang.Class<E> enumClass)Reads a short sized bit vector and converts it to anEnumSet.<E extends java.lang.Enum<E>>
EgetEnumShort(int index, java.lang.Class<E> enumClass)Reads a short from the buffer and returns the correlating enum constant defined by the specified enum type.<E extends java.lang.Enum<E>>
EgetEnumShort(java.lang.Class<E> enumClass)Reads a short from the buffer and returns the correlating enum constant defined by the specified enum type.floatgetFloat()floatgetFloat(int index)java.lang.StringgetHexDump()Returns hexdump of this buffer.java.lang.StringgetHexDump(int lengthLimit)Return hexdump of this buffer with limited length.intgetInt()intgetInt(int index)longgetLong()longgetLong(int index)intgetMediumInt()Relative get method for reading a medium int value.private intgetMediumInt(byte b1, byte b2, byte b3)intgetMediumInt(int index)Absolute get method for reading a medium int value.java.lang.ObjectgetObject()Reads a Java object from the buffer using the contextClassLoaderof the current thread.java.lang.ObjectgetObject(java.lang.ClassLoader classLoader)Reads a Java object from the buffer using the specified classLoader.java.lang.StringgetPrefixedString(int prefixLength, java.nio.charset.CharsetDecoder decoder)Reads a string which has a length field before the actual encoded string, using the specifieddecoderand returns it.java.lang.StringgetPrefixedString(java.nio.charset.CharsetDecoder decoder)Reads a string which has a 16-bit length field before the actual encoded string, using the specifieddecoderand returns it.shortgetShort()shortgetShort(int index)IoBuffergetSlice(int length)TODO document me.IoBuffergetSlice(int index, int length)TODO document me.java.lang.StringgetString(int fieldSize, java.nio.charset.CharsetDecoder decoder)Reads aNUL-terminated string from this buffer using the specifieddecoderand returns it.java.lang.StringgetString(java.nio.charset.CharsetDecoder decoder)Reads aNUL-terminated string from this buffer using the specifieddecoderand returns it.shortgetUnsigned()Reads one unsigned byte as a short integer.shortgetUnsigned(int index)Reads one byte as an unsigned short integer.longgetUnsignedInt()Reads four bytes unsigned integer.longgetUnsignedInt(int index)Reads four bytes unsigned integer.intgetUnsignedMediumInt()Relative get method for reading an unsigned medium int value.intgetUnsignedMediumInt(int index)Absolute get method for reading an unsigned medium int value.intgetUnsignedShort()Reads two bytes unsigned integer.intgetUnsignedShort(int index)Reads two bytes unsigned integer.inthashCode()booleanhasRemaining()intindexOf(byte b)Returns the first occurence position of the specified byte from the current position to the current limit.booleanisAutoExpand()Returns true if and only if autoExpand is turned on.booleanisAutoShrink()Returns true if and only if autoShrink is turned on.booleanisDerived()returns true if and only if this buffer is derived from other buffer viaIoBuffer.duplicate(),IoBuffer.slice()orIoBuffer.asReadOnlyBuffer().booleanisDirect()booleanisReadOnly()intlimit()IoBufferlimit(int newLimit)IoBuffermark()intmarkValue()Returns the position of the current mark.intminimumCapacity()Returns the minimum capacity of this buffer which is used to determine the new capacity of the buffer shrunk byIoBuffer.compact()andIoBuffer.shrink()operation.IoBufferminimumCapacity(int minimumCapacity)Sets the minimum capacity of this buffer which is used to determine the new capacity of the buffer shrunk byIoBuffer.compact()andIoBuffer.shrink()operation.java.nio.ByteOrderorder()IoBufferorder(java.nio.ByteOrder bo)intposition()IoBufferposition(int newPosition)booleanprefixedDataAvailable(int prefixLength)Returns true if this buffer contains a data which has a data length as a prefix and the buffer has remaining data as enough as specified in the data length field.booleanprefixedDataAvailable(int prefixLength, int maxDataLength)Returns true if this buffer contains a data which has a data length as a prefix and the buffer has remaining data as enough as specified in the data length field.IoBufferput(byte b)IoBufferput(byte[] src)IoBufferput(byte[] src, int offset, int length)IoBufferput(int index, byte b)IoBufferput(IoBuffer src)Writes the content of the specified src into this buffer.IoBufferput(java.nio.ByteBuffer src)Writes the content of the specified src into this buffer.IoBufferputChar(char value)IoBufferputChar(int index, char value)IoBufferputDouble(double value)IoBufferputDouble(int index, double value)IoBufferputEnum(int index, java.lang.Enum<?> e)Writes an enum's ordinal value to the buffer as a byte.IoBufferputEnum(java.lang.Enum<?> e)Writes an enum's ordinal value to the buffer as a byte.IoBufferputEnumInt(int index, java.lang.Enum<?> e)Writes an enum's ordinal value to the buffer as an integer.IoBufferputEnumInt(java.lang.Enum<?> e)Writes an enum's ordinal value to the buffer as an integer.<E extends java.lang.Enum<E>>
IoBufferputEnumSet(int index, java.util.Set<E> set)Writes the specifiedSetto the buffer as a byte sized bit vector.<E extends java.lang.Enum<E>>
IoBufferputEnumSet(java.util.Set<E> set)Writes the specifiedSetto the buffer as a byte sized bit vector.<E extends java.lang.Enum<E>>
IoBufferputEnumSetInt(int index, java.util.Set<E> set)Writes the specifiedSetto the buffer as an int sized bit vector.<E extends java.lang.Enum<E>>
IoBufferputEnumSetInt(java.util.Set<E> set)Writes the specifiedSetto the buffer as an int sized bit vector.<E extends java.lang.Enum<E>>
IoBufferputEnumSetLong(int index, java.util.Set<E> set)Writes the specifiedSetto the buffer as a long sized bit vector.<E extends java.lang.Enum<E>>
IoBufferputEnumSetLong(java.util.Set<E> set)Writes the specifiedSetto the buffer as a long sized bit vector.<E extends java.lang.Enum<E>>
IoBufferputEnumSetShort(int index, java.util.Set<E> set)Writes the specifiedSetto the buffer as a short sized bit vector.<E extends java.lang.Enum<E>>
IoBufferputEnumSetShort(java.util.Set<E> set)Writes the specifiedSetto the buffer as a short sized bit vector.IoBufferputEnumShort(int index, java.lang.Enum<?> e)Writes an enum's ordinal value to the buffer as a short.IoBufferputEnumShort(java.lang.Enum<?> e)Writes an enum's ordinal value to the buffer as a short.IoBufferputFloat(float value)IoBufferputFloat(int index, float value)IoBufferputInt(int value)IoBufferputInt(int index, int value)IoBufferputLong(int index, long value)IoBufferputLong(long value)IoBufferputMediumInt(int value)Relative put method for writing a medium int value.IoBufferputMediumInt(int index, int value)Absolute put method for writing a medium int value.IoBufferputObject(java.lang.Object o)Writes the specified Java object to the buffer.IoBufferputPrefixedString(java.lang.CharSequence val, int prefixLength, int padding, byte padValue, java.nio.charset.CharsetEncoder encoder)Writes the content ofininto this buffer as a string which has a 16-bit length field before the actual encoded string, using the specifiedencoder.IoBufferputPrefixedString(java.lang.CharSequence in, int prefixLength, int padding, java.nio.charset.CharsetEncoder encoder)Writes the content ofininto this buffer as a string which has a 16-bit length field before the actual encoded string, using the specifiedencoder.IoBufferputPrefixedString(java.lang.CharSequence in, int prefixLength, java.nio.charset.CharsetEncoder encoder)Writes the content ofininto this buffer as a string which has a 16-bit length field before the actual encoded string, using the specifiedencoder.IoBufferputPrefixedString(java.lang.CharSequence in, java.nio.charset.CharsetEncoder encoder)Writes the content ofininto this buffer as a string which has a 16-bit length field before the actual encoded string, using the specifiedencoder.IoBufferputShort(int index, short value)IoBufferputShort(short value)IoBufferputString(java.lang.CharSequence val, int fieldSize, java.nio.charset.CharsetEncoder encoder)Writes the content ofininto this buffer as aNUL-terminated string using the specifiedencoder.IoBufferputString(java.lang.CharSequence val, java.nio.charset.CharsetEncoder encoder)Writes the content ofininto this buffer using the specifiedencoder.intremaining()IoBufferreset()IoBufferrewind()IoBuffersetAutoExpand(boolean autoExpand)Turns on or off autoExpand.IoBuffersetAutoShrink(boolean autoShrink)Turns on or off autoShrink.IoBuffershrink()Changes the capacity of this buffer so this buffer occupies as less memory as possible while retaining the position, limit and the buffer content between the position and limit.IoBufferskip(int size)Forwards the position of this buffer as the specifiedsizebytes.IoBufferslice()protected abstract IoBufferslice0()Implement this method to return the unexpandable slice of this buffer.IoBuffersweep()Clears this buffer and fills its content with NUL.IoBuffersweep(byte value)double Clears this buffer and fills its content with value.private <E> EtoEnum(java.lang.Class<E> enumClass, int i)private <E extends java.lang.Enum<E>>
java.util.EnumSet<E>toEnumSet(java.lang.Class<E> clazz, long vector)private <E extends java.lang.Enum<E>>
longtoLong(java.util.Set<E> set)java.lang.StringtoString()-
Methods inherited from class com.google.code.yanf4j.buffer.IoBuffer
allocate, allocate, array, arrayOffset, buf, free, getAllocator, hasArray, isUseDirectBuffer, normalizeCapacity, setAllocator, setUseDirectBuffer, wrap, wrap, wrap
-
-
-
-
Field Detail
-
derived
private final boolean derived
Tells if a buffer has been created from an existing buffer
-
autoExpand
private boolean autoExpand
A flag set to true if the buffer can extend automatically
-
autoShrink
private boolean autoShrink
A flag set to true if the buffer can shrink automatically
-
recapacityAllowed
private boolean recapacityAllowed
Tells if a buffer can be expanded
-
minimumCapacity
private int minimumCapacity
The minimum number of bytes the IoBuffer can hold
-
BYTE_MASK
private static final long BYTE_MASK
A mask for a byte- See Also:
- Constant Field Values
-
SHORT_MASK
private static final long SHORT_MASK
A mask for a short- See Also:
- Constant Field Values
-
INT_MASK
private static final long INT_MASK
A mask for an int- See Also:
- Constant Field Values
-
mark
private int mark
We don't have any access to Buffer.markValue(), so we need to track it down, which will cause small extra overhead.
-
-
Constructor Detail
-
AbstractIoBuffer
protected AbstractIoBuffer(IoBufferAllocator allocator, int initialCapacity)
Creates a new parent buffer.- Parameters:
allocator- The allocator to use to create new buffersinitialCapacity- The initial buffer capacity when created
-
AbstractIoBuffer
protected AbstractIoBuffer(AbstractIoBuffer parent)
Creates a new derived buffer. A derived buffer uses an existing buffer properties - the allocator and capacity -.- Parameters:
parent- The buffer we get the properties from
-
-
Method Detail
-
isDirect
public final boolean isDirect()
-
isReadOnly
public final boolean isReadOnly()
- Specified by:
isReadOnlyin classIoBuffer- See Also:
Buffer.isReadOnly()
-
buf
protected abstract void buf(java.nio.ByteBuffer newBuf)
Sets the underlying NIO buffer instance.- Parameters:
newBuf- The buffer to store within this IoBuffer
-
minimumCapacity
public final int minimumCapacity()
Returns the minimum capacity of this buffer which is used to determine the new capacity of the buffer shrunk byIoBuffer.compact()andIoBuffer.shrink()operation. The default value is the initial capacity of the buffer.- Specified by:
minimumCapacityin classIoBuffer
-
minimumCapacity
public final IoBuffer minimumCapacity(int minimumCapacity)
Sets the minimum capacity of this buffer which is used to determine the new capacity of the buffer shrunk byIoBuffer.compact()andIoBuffer.shrink()operation. The default value is the initial capacity of the buffer.- Specified by:
minimumCapacityin classIoBuffer
-
capacity
public final int capacity()
-
capacity
public final IoBuffer capacity(int newCapacity)
Increases the capacity of this buffer. If the new capacity is less than or equal to the current capacity, this method returns silently. If the new capacity is greater than the current capacity, the buffer is reallocated while retaining the position, limit, mark and the content of the buffer.
-
isAutoExpand
public final boolean isAutoExpand()
Returns true if and only if autoExpand is turned on.- Specified by:
isAutoExpandin classIoBuffer
-
isAutoShrink
public final boolean isAutoShrink()
Returns true if and only if autoShrink is turned on.- Specified by:
isAutoShrinkin classIoBuffer
-
isDerived
public final boolean isDerived()
returns true if and only if this buffer is derived from other buffer viaIoBuffer.duplicate(),IoBuffer.slice()orIoBuffer.asReadOnlyBuffer().
-
setAutoExpand
public final IoBuffer setAutoExpand(boolean autoExpand)
Turns on or off autoExpand.- Specified by:
setAutoExpandin classIoBuffer
-
setAutoShrink
public final IoBuffer setAutoShrink(boolean autoShrink)
Turns on or off autoShrink.- Specified by:
setAutoShrinkin classIoBuffer
-
expand
public final IoBuffer expand(int expectedRemaining)
Changes the capacity and limit of this buffer so this buffer get the specified expectedRemaining room from the current position. This method works even if you didn't set autoExpand to true.
-
expand
private IoBuffer expand(int expectedRemaining, boolean autoExpand)
-
expand
public final IoBuffer expand(int pos, int expectedRemaining)
Changes the capacity and limit of this buffer so this buffer get the specified expectedRemaining room from the specified position. This method works even if you didn't set autoExpand to true.
-
expand
private IoBuffer expand(int pos, int expectedRemaining, boolean autoExpand)
-
shrink
public final IoBuffer shrink()
Changes the capacity of this buffer so this buffer occupies as less memory as possible while retaining the position, limit and the buffer content between the position and limit. The capacity of the buffer never becomes less thanIoBuffer.minimumCapacity(). The mark is discarded once the capacity changes.
-
position
public final int position()
-
position
public final IoBuffer position(int newPosition)
-
limit
public final IoBuffer limit(int newLimit)
-
markValue
public final int markValue()
Returns the position of the current mark. This method returns -1 if no mark is set.
-
sweep
public final IoBuffer sweep()
Clears this buffer and fills its content with NUL. The position is set to zero, the limit is set to the capacity, and the mark is discarded.
-
sweep
public final IoBuffer sweep(byte value)
double Clears this buffer and fills its content with value. The position is set to zero, the limit is set to the capacity, and the mark is discarded.
-
rewind
public final IoBuffer rewind()
-
remaining
public final int remaining()
-
hasRemaining
public final boolean hasRemaining()
- Specified by:
hasRemainingin classIoBuffer- See Also:
Buffer.hasRemaining()
-
getUnsigned
public final short getUnsigned()
Reads one unsigned byte as a short integer.- Specified by:
getUnsignedin classIoBuffer
-
put
public final IoBuffer put(byte b)
-
get
public final byte get(int index)
-
getUnsigned
public final short getUnsigned(int index)
Reads one byte as an unsigned short integer.- Specified by:
getUnsignedin classIoBuffer
-
put
public final IoBuffer put(int index, byte b)
-
get
public final IoBuffer get(byte[] dst, int offset, int length)
-
put
public final IoBuffer put(java.nio.ByteBuffer src)
Writes the content of the specified src into this buffer.
-
put
public final IoBuffer put(byte[] src, int offset, int length)
-
compact
public final IoBuffer compact()
-
order
public final java.nio.ByteOrder order()
-
order
public final IoBuffer order(java.nio.ByteOrder bo)
-
getChar
public final char getChar()
-
putChar
public final IoBuffer putChar(char value)
-
getChar
public final char getChar(int index)
-
putChar
public final IoBuffer putChar(int index, char value)
-
asCharBuffer
public final java.nio.CharBuffer asCharBuffer()
- Specified by:
asCharBufferin classIoBuffer- See Also:
ByteBuffer.asCharBuffer()
-
getShort
public final short getShort()
-
putShort
public final IoBuffer putShort(short value)
-
getShort
public final short getShort(int index)
-
putShort
public final IoBuffer putShort(int index, short value)
-
asShortBuffer
public final java.nio.ShortBuffer asShortBuffer()
- Specified by:
asShortBufferin classIoBuffer- See Also:
ByteBuffer.asShortBuffer()
-
getInt
public final int getInt()
-
putInt
public final IoBuffer putInt(int value)
-
getInt
public final int getInt(int index)
-
putInt
public final IoBuffer putInt(int index, int value)
-
asIntBuffer
public final java.nio.IntBuffer asIntBuffer()
- Specified by:
asIntBufferin classIoBuffer- See Also:
ByteBuffer.asIntBuffer()
-
getLong
public final long getLong()
-
putLong
public final IoBuffer putLong(long value)
-
getLong
public final long getLong(int index)
-
putLong
public final IoBuffer putLong(int index, long value)
-
asLongBuffer
public final java.nio.LongBuffer asLongBuffer()
- Specified by:
asLongBufferin classIoBuffer- See Also:
ByteBuffer.asLongBuffer()
-
getFloat
public final float getFloat()
-
putFloat
public final IoBuffer putFloat(float value)
-
getFloat
public final float getFloat(int index)
-
putFloat
public final IoBuffer putFloat(int index, float value)
-
asFloatBuffer
public final java.nio.FloatBuffer asFloatBuffer()
- Specified by:
asFloatBufferin classIoBuffer- See Also:
ByteBuffer.asFloatBuffer()
-
getDouble
public final double getDouble()
-
putDouble
public final IoBuffer putDouble(double value)
-
getDouble
public final double getDouble(int index)
-
putDouble
public final IoBuffer putDouble(int index, double value)
-
asDoubleBuffer
public final java.nio.DoubleBuffer asDoubleBuffer()
- Specified by:
asDoubleBufferin classIoBuffer- See Also:
ByteBuffer.asDoubleBuffer()
-
asReadOnlyBuffer
public final IoBuffer asReadOnlyBuffer()
- Specified by:
asReadOnlyBufferin classIoBuffer- See Also:
ByteBuffer.asReadOnlyBuffer()
-
asReadOnlyBuffer0
protected abstract IoBuffer asReadOnlyBuffer0()
Implement this method to return the unexpandable read only version of this buffer.
-
duplicate
public final IoBuffer duplicate()
-
duplicate0
protected abstract IoBuffer duplicate0()
Implement this method to return the unexpandable duplicate of this buffer.
-
slice
public final IoBuffer slice()
-
getSlice
public final IoBuffer getSlice(int index, int length)
TODO document me.
-
getSlice
public final IoBuffer getSlice(int length)
TODO document me.
-
slice0
protected abstract IoBuffer slice0()
Implement this method to return the unexpandable slice of this buffer.
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
compareTo
public int compareTo(IoBuffer that)
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
get
public IoBuffer get(byte[] dst)
-
put
public IoBuffer put(byte[] src)
-
getUnsignedShort
public int getUnsignedShort()
Reads two bytes unsigned integer.- Specified by:
getUnsignedShortin classIoBuffer
-
getUnsignedShort
public int getUnsignedShort(int index)
Reads two bytes unsigned integer.- Specified by:
getUnsignedShortin classIoBuffer
-
getUnsignedInt
public long getUnsignedInt()
Reads four bytes unsigned integer.- Specified by:
getUnsignedIntin classIoBuffer
-
getMediumInt
public int getMediumInt()
Relative get method for reading a medium int value.Reads the next three 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 three.
- Specified by:
getMediumIntin classIoBuffer- Returns:
- The medium int value at the buffer's current position
-
getUnsignedMediumInt
public int getUnsignedMediumInt()
Relative get method for reading an unsigned medium int value.Reads the next three 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 three.
- Specified by:
getUnsignedMediumIntin classIoBuffer- Returns:
- The unsigned medium int value at the buffer's current position
-
getMediumInt
public int getMediumInt(int index)
Absolute get method for reading a medium int value.Reads the next three bytes at this buffer's current position, composing them into an int value according to the current byte order.
- Specified by:
getMediumIntin classIoBuffer- Parameters:
index- The index from which the medium int will be read- Returns:
- The medium int value at the given index
-
getUnsignedMediumInt
public int getUnsignedMediumInt(int index)
Absolute get method for reading an unsigned medium int value.Reads the next three bytes at this buffer's current position, composing them into an int value according to the current byte order.
- Specified by:
getUnsignedMediumIntin classIoBuffer- Parameters:
index- The index from which the unsigned medium int will be read- Returns:
- The unsigned medium int value at the given index
-
getMediumInt
private int getMediumInt(byte b1, byte b2, byte b3)
-
putMediumInt
public IoBuffer putMediumInt(int value)
Relative put method for writing a medium int value.Writes three bytes containing the given int value, in the current byte order, into this buffer at the current position, and then increments the position by three.
- Specified by:
putMediumIntin classIoBuffer- Parameters:
value- The medium int value to be written- Returns:
- This buffer
-
putMediumInt
public IoBuffer putMediumInt(int index, int value)
Absolute put method for writing a medium int value.Writes three bytes containing the given int value, in the current byte order, into this buffer at the given index.
- Specified by:
putMediumIntin classIoBuffer- Parameters:
index- The index at which the bytes will be writtenvalue- The medium int value to be written- Returns:
- This buffer
-
getUnsignedInt
public long getUnsignedInt(int index)
Reads four bytes unsigned integer.- Specified by:
getUnsignedIntin classIoBuffer
-
asInputStream
public java.io.InputStream asInputStream()
Returns anInputStreamthat reads the data from this buffer.InputStream.read()returns -1 if the buffer position reaches to the limit.- Specified by:
asInputStreamin classIoBuffer
-
asOutputStream
public java.io.OutputStream asOutputStream()
Returns anOutputStreamthat appends the data into this buffer. Please note that theOutputStream.write(int)will throw aBufferOverflowExceptioninstead of anIOExceptionin case of buffer overflow. Please set autoExpand property by callingIoBuffer.setAutoExpand(boolean)to prevent the unexpected runtime exception.- Specified by:
asOutputStreamin classIoBuffer
-
getHexDump
public java.lang.String getHexDump()
Returns hexdump of this buffer. The data and pointer are not changed as a result of this method call.- Specified by:
getHexDumpin classIoBuffer- Returns:
- hexidecimal representation of this buffer
-
getHexDump
public java.lang.String getHexDump(int lengthLimit)
Return hexdump of this buffer with limited length.- Specified by:
getHexDumpin classIoBuffer- Parameters:
lengthLimit- The maximum number of bytes to dump from the current buffer position.- Returns:
- hexidecimal representation of this buffer
-
getString
public java.lang.String getString(java.nio.charset.CharsetDecoder decoder) throws java.nio.charset.CharacterCodingExceptionReads aNUL-terminated string from this buffer using the specifieddecoderand returns it. This method reads until the limit of this buffer if no NUL is found.
-
getString
public java.lang.String getString(int fieldSize, java.nio.charset.CharsetDecoder decoder) throws java.nio.charset.CharacterCodingExceptionReads aNUL-terminated string from this buffer using the specifieddecoderand returns it.
-
putString
public IoBuffer putString(java.lang.CharSequence val, java.nio.charset.CharsetEncoder encoder) throws java.nio.charset.CharacterCodingException
Writes the content ofininto this buffer using the specifiedencoder. This method doesn't terminate string with NUL. You have to do it by yourself.
-
putString
public IoBuffer putString(java.lang.CharSequence val, int fieldSize, java.nio.charset.CharsetEncoder encoder) throws java.nio.charset.CharacterCodingException
Writes the content ofininto this buffer as aNUL-terminated string using the specifiedencoder.If the charset name of the encoder is UTF-16, you cannot specify odd
fieldSize, and this method will append twoNULs as a terminator.Please note that this method doesn't terminate with
NULif the input string is longer than fieldSize.
-
getPrefixedString
public java.lang.String getPrefixedString(java.nio.charset.CharsetDecoder decoder) throws java.nio.charset.CharacterCodingExceptionReads a string which has a 16-bit length field before the actual encoded string, using the specifieddecoderand returns it. This method is a shortcut for getPrefixedString(2, decoder).- Specified by:
getPrefixedStringin classIoBuffer- Throws:
java.nio.charset.CharacterCodingException
-
getPrefixedString
public java.lang.String getPrefixedString(int prefixLength, java.nio.charset.CharsetDecoder decoder) throws java.nio.charset.CharacterCodingExceptionReads a string which has a length field before the actual encoded string, using the specifieddecoderand returns it.- Specified by:
getPrefixedStringin classIoBuffer- Parameters:
prefixLength- the length of the length field (1, 2, or 4)decoder- the decoder to use for decoding the string- Returns:
- the prefixed string
- Throws:
java.nio.charset.CharacterCodingException- when decoding failsjava.nio.BufferUnderflowException- when there is not enough data available
-
putPrefixedString
public IoBuffer putPrefixedString(java.lang.CharSequence in, java.nio.charset.CharsetEncoder encoder) throws java.nio.charset.CharacterCodingException
Writes the content ofininto this buffer as a string which has a 16-bit length field before the actual encoded string, using the specifiedencoder. This method is a shortcut for putPrefixedString(in, 2, 0, encoder).- Specified by:
putPrefixedStringin classIoBuffer- Throws:
java.nio.charset.CharacterCodingException
-
putPrefixedString
public IoBuffer putPrefixedString(java.lang.CharSequence in, int prefixLength, java.nio.charset.CharsetEncoder encoder) throws java.nio.charset.CharacterCodingException
Writes the content ofininto this buffer as a string which has a 16-bit length field before the actual encoded string, using the specifiedencoder. This method is a shortcut for putPrefixedString(in, prefixLength, 0, encoder).- Specified by:
putPrefixedStringin classIoBufferprefixLength- the length of the length field (1, 2, or 4)- Throws:
java.nio.charset.CharacterCodingException
-
putPrefixedString
public IoBuffer putPrefixedString(java.lang.CharSequence in, int prefixLength, int padding, java.nio.charset.CharsetEncoder encoder) throws java.nio.charset.CharacterCodingException
Writes the content ofininto this buffer as a string which has a 16-bit length field before the actual encoded string, using the specifiedencoder. This method is a shortcut for putPrefixedString(in, prefixLength, padding, ( byte ) 0, encoder) .- Specified by:
putPrefixedStringin classIoBufferprefixLength- the length of the length field (1, 2, or 4)padding- the number of padded NULs (1 (or 0), 2, or 4)- Throws:
java.nio.charset.CharacterCodingException
-
putPrefixedString
public IoBuffer putPrefixedString(java.lang.CharSequence val, int prefixLength, int padding, byte padValue, java.nio.charset.CharsetEncoder encoder) throws java.nio.charset.CharacterCodingException
Writes the content ofininto this buffer as a string which has a 16-bit length field before the actual encoded string, using the specifiedencoder.- Specified by:
putPrefixedStringin classIoBufferprefixLength- the length of the length field (1, 2, or 4)padding- the number of padded bytes (1 (or 0), 2, or 4)padValue- the value of padded bytes- Throws:
java.nio.charset.CharacterCodingException
-
getObject
public java.lang.Object getObject() throws java.lang.ClassNotFoundExceptionReads a Java object from the buffer using the contextClassLoaderof the current thread.
-
getObject
public java.lang.Object getObject(java.lang.ClassLoader classLoader) throws java.lang.ClassNotFoundExceptionReads a Java object from the buffer using the specified classLoader.
-
putObject
public IoBuffer putObject(java.lang.Object o)
Writes the specified Java object to the buffer.
-
prefixedDataAvailable
public boolean prefixedDataAvailable(int prefixLength)
Returns true if this buffer contains a data which has a data length as a prefix and the buffer has remaining data as enough as specified in the data length field. This method is identical with prefixedDataAvailable( prefixLength, Integer.MAX_VALUE ). Please not that using this method can allow DoS (Denial of Service) attack in case the remote peer sends too big data length value. It is recommended to useIoBuffer.prefixedDataAvailable(int, int)instead.- Specified by:
prefixedDataAvailablein classIoBuffer- Parameters:
prefixLength- the length of the prefix field (1, 2, or 4)
-
prefixedDataAvailable
public boolean prefixedDataAvailable(int prefixLength, int maxDataLength)Returns true if this buffer contains a data which has a data length as a prefix and the buffer has remaining data as enough as specified in the data length field.- Specified by:
prefixedDataAvailablein classIoBuffer- Parameters:
prefixLength- the length of the prefix field (1, 2, or 4)maxDataLength- the allowed maximum of the read data length
-
indexOf
public int indexOf(byte b)
Returns the first occurence position of the specified byte from the current position to the current limit.
-
skip
public IoBuffer skip(int size)
Forwards the position of this buffer as the specifiedsizebytes.
-
fill
public IoBuffer fill(byte value, int size)
Fills this buffer with the specified value. This method moves buffer position forward.
-
fillAndReset
public IoBuffer fillAndReset(byte value, int size)
Fills this buffer with the specified value. This method does not change buffer position.- Specified by:
fillAndResetin classIoBuffer
-
fill
public IoBuffer fill(int size)
Fills this buffer withNUL (0x00). This method moves buffer position forward.
-
fillAndReset
public IoBuffer fillAndReset(int size)
Fills this buffer withNUL (0x00). This method does not change buffer position.- Specified by:
fillAndResetin classIoBuffer
-
getEnum
public <E extends java.lang.Enum<E>> E getEnum(java.lang.Class<E> enumClass)
Reads a byte from the buffer and returns the correlating enum constant defined by the specified enum type.
-
getEnum
public <E extends java.lang.Enum<E>> E getEnum(int index, java.lang.Class<E> enumClass)Reads a byte from the buffer and returns the correlating enum constant defined by the specified enum type.
-
getEnumShort
public <E extends java.lang.Enum<E>> E getEnumShort(java.lang.Class<E> enumClass)
Reads a short from the buffer and returns the correlating enum constant defined by the specified enum type.- Specified by:
getEnumShortin classIoBuffer- Type Parameters:
E- The enum type to return- Parameters:
enumClass- The enum's class object
-
getEnumShort
public <E extends java.lang.Enum<E>> E getEnumShort(int index, java.lang.Class<E> enumClass)Reads a short from the buffer and returns the correlating enum constant defined by the specified enum type.- Specified by:
getEnumShortin classIoBuffer- Type Parameters:
E- The enum type to return- Parameters:
index- the index from which the bytes will be readenumClass- The enum's class object
-
getEnumInt
public <E extends java.lang.Enum<E>> E getEnumInt(java.lang.Class<E> enumClass)
Reads an int from the buffer and returns the correlating enum constant defined by the specified enum type.- Specified by:
getEnumIntin classIoBuffer- Type Parameters:
E- The enum type to return- Parameters:
enumClass- The enum's class object
-
getEnumInt
public <E extends java.lang.Enum<E>> E getEnumInt(int index, java.lang.Class<E> enumClass)Reads an int from the buffer and returns the correlating enum constant defined by the specified enum type.- Specified by:
getEnumIntin classIoBuffer- Type Parameters:
E- The enum type to return- Parameters:
index- the index from which the bytes will be readenumClass- The enum's class object
-
putEnum
public IoBuffer putEnum(java.lang.Enum<?> e)
Writes an enum's ordinal value to the buffer as a byte.
-
putEnum
public IoBuffer putEnum(int index, java.lang.Enum<?> e)
Writes an enum's ordinal value to the buffer as a byte.
-
putEnumShort
public IoBuffer putEnumShort(java.lang.Enum<?> e)
Writes an enum's ordinal value to the buffer as a short.- Specified by:
putEnumShortin classIoBuffer- Parameters:
e- The enum to write to the buffer
-
putEnumShort
public IoBuffer putEnumShort(int index, java.lang.Enum<?> e)
Writes an enum's ordinal value to the buffer as a short.- Specified by:
putEnumShortin classIoBuffer- Parameters:
index- The index at which the bytes will be writtene- The enum to write to the buffer
-
putEnumInt
public IoBuffer putEnumInt(java.lang.Enum<?> e)
Writes an enum's ordinal value to the buffer as an integer.- Specified by:
putEnumIntin classIoBuffer- Parameters:
e- The enum to write to the buffer
-
putEnumInt
public IoBuffer putEnumInt(int index, java.lang.Enum<?> e)
Writes an enum's ordinal value to the buffer as an integer.- Specified by:
putEnumIntin classIoBuffer- Parameters:
index- The index at which the bytes will be writtene- The enum to write to the buffer
-
toEnum
private <E> E toEnum(java.lang.Class<E> enumClass, int i)
-
enumConversionErrorMessage
private java.lang.String enumConversionErrorMessage(java.lang.Enum<?> e, java.lang.String type)
-
getEnumSet
public <E extends java.lang.Enum<E>> java.util.EnumSet<E> getEnumSet(java.lang.Class<E> enumClass)
Reads a byte sized bit vector and converts it to anEnumSet.Each bit is mapped to a value in the specified enum. The least significant bit maps to the first entry in the specified enum and each subsequent bit maps to each subsequent bit as mapped to the subsequent enum value.
- Specified by:
getEnumSetin classIoBuffer- Type Parameters:
E- the enum type- Parameters:
enumClass- the enum class used to create the EnumSet- Returns:
- the EnumSet representation of the bit vector
-
getEnumSet
public <E extends java.lang.Enum<E>> java.util.EnumSet<E> getEnumSet(int index, java.lang.Class<E> enumClass)Reads a byte sized bit vector and converts it to anEnumSet.- Specified by:
getEnumSetin classIoBuffer- Type Parameters:
E- the enum type- Parameters:
index- the index from which the byte will be readenumClass- the enum class used to create the EnumSet- Returns:
- the EnumSet representation of the bit vector
- See Also:
IoBuffer.getEnumSet(Class)
-
getEnumSetShort
public <E extends java.lang.Enum<E>> java.util.EnumSet<E> getEnumSetShort(java.lang.Class<E> enumClass)
Reads a short sized bit vector and converts it to anEnumSet.- Specified by:
getEnumSetShortin classIoBuffer- Type Parameters:
E- the enum type- Parameters:
enumClass- the enum class used to create the EnumSet- Returns:
- the EnumSet representation of the bit vector
- See Also:
IoBuffer.getEnumSet(Class)
-
getEnumSetShort
public <E extends java.lang.Enum<E>> java.util.EnumSet<E> getEnumSetShort(int index, java.lang.Class<E> enumClass)Reads a short sized bit vector and converts it to anEnumSet.- Specified by:
getEnumSetShortin classIoBuffer- Type Parameters:
E- the enum type- Parameters:
index- the index from which the bytes will be readenumClass- the enum class used to create the EnumSet- Returns:
- the EnumSet representation of the bit vector
- See Also:
IoBuffer.getEnumSet(Class)
-
getEnumSetInt
public <E extends java.lang.Enum<E>> java.util.EnumSet<E> getEnumSetInt(java.lang.Class<E> enumClass)
Reads an int sized bit vector and converts it to anEnumSet.- Specified by:
getEnumSetIntin classIoBuffer- Type Parameters:
E- the enum type- Parameters:
enumClass- the enum class used to create the EnumSet- Returns:
- the EnumSet representation of the bit vector
- See Also:
IoBuffer.getEnumSet(Class)
-
getEnumSetInt
public <E extends java.lang.Enum<E>> java.util.EnumSet<E> getEnumSetInt(int index, java.lang.Class<E> enumClass)Reads an int sized bit vector and converts it to anEnumSet.- Specified by:
getEnumSetIntin classIoBuffer- Type Parameters:
E- the enum type- Parameters:
index- the index from which the bytes will be readenumClass- the enum class used to create the EnumSet- Returns:
- the EnumSet representation of the bit vector
- See Also:
IoBuffer.getEnumSet(Class)
-
getEnumSetLong
public <E extends java.lang.Enum<E>> java.util.EnumSet<E> getEnumSetLong(java.lang.Class<E> enumClass)
Reads a long sized bit vector and converts it to anEnumSet.- Specified by:
getEnumSetLongin classIoBuffer- Type Parameters:
E- the enum type- Parameters:
enumClass- the enum class used to create the EnumSet- Returns:
- the EnumSet representation of the bit vector
- See Also:
IoBuffer.getEnumSet(Class)
-
getEnumSetLong
public <E extends java.lang.Enum<E>> java.util.EnumSet<E> getEnumSetLong(int index, java.lang.Class<E> enumClass)Reads a long sized bit vector and converts it to anEnumSet.- Specified by:
getEnumSetLongin classIoBuffer- Type Parameters:
E- the enum type- Parameters:
index- the index from which the bytes will be readenumClass- the enum class used to create the EnumSet- Returns:
- the EnumSet representation of the bit vector
- See Also:
IoBuffer.getEnumSet(Class)
-
toEnumSet
private <E extends java.lang.Enum<E>> java.util.EnumSet<E> toEnumSet(java.lang.Class<E> clazz, long vector)
-
putEnumSet
public <E extends java.lang.Enum<E>> IoBuffer putEnumSet(java.util.Set<E> set)
Writes the specifiedSetto the buffer as a byte sized bit vector.- Specified by:
putEnumSetin classIoBuffer- Type Parameters:
E- the enum type of the Set- Parameters:
set- the enum set to write to the buffer
-
putEnumSet
public <E extends java.lang.Enum<E>> IoBuffer putEnumSet(int index, java.util.Set<E> set)
Writes the specifiedSetto the buffer as a byte sized bit vector.- Specified by:
putEnumSetin classIoBuffer- Type Parameters:
E- the enum type of the Set- Parameters:
index- the index at which the byte will be writtenset- the enum set to write to the buffer
-
putEnumSetShort
public <E extends java.lang.Enum<E>> IoBuffer putEnumSetShort(java.util.Set<E> set)
Writes the specifiedSetto the buffer as a short sized bit vector.- Specified by:
putEnumSetShortin classIoBuffer- Type Parameters:
E- the enum type of the Set- Parameters:
set- the enum set to write to the buffer
-
putEnumSetShort
public <E extends java.lang.Enum<E>> IoBuffer putEnumSetShort(int index, java.util.Set<E> set)
Writes the specifiedSetto the buffer as a short sized bit vector.- Specified by:
putEnumSetShortin classIoBuffer- Type Parameters:
E- the enum type of the Set- Parameters:
index- the index at which the bytes will be writtenset- the enum set to write to the buffer
-
putEnumSetInt
public <E extends java.lang.Enum<E>> IoBuffer putEnumSetInt(java.util.Set<E> set)
Writes the specifiedSetto the buffer as an int sized bit vector.- Specified by:
putEnumSetIntin classIoBuffer- Type Parameters:
E- the enum type of the Set- Parameters:
set- the enum set to write to the buffer
-
putEnumSetInt
public <E extends java.lang.Enum<E>> IoBuffer putEnumSetInt(int index, java.util.Set<E> set)
Writes the specifiedSetto the buffer as an int sized bit vector.- Specified by:
putEnumSetIntin classIoBuffer- Type Parameters:
E- the enum type of the Set- Parameters:
index- the index at which the bytes will be writtenset- the enum set to write to the buffer
-
putEnumSetLong
public <E extends java.lang.Enum<E>> IoBuffer putEnumSetLong(java.util.Set<E> set)
Writes the specifiedSetto the buffer as a long sized bit vector.- Specified by:
putEnumSetLongin classIoBuffer- Type Parameters:
E- the enum type of the Set- Parameters:
set- the enum set to write to the buffer
-
putEnumSetLong
public <E extends java.lang.Enum<E>> IoBuffer putEnumSetLong(int index, java.util.Set<E> set)
Writes the specifiedSetto the buffer as a long sized bit vector.- Specified by:
putEnumSetLongin classIoBuffer- Type Parameters:
E- the enum type of the Set- Parameters:
index- the index at which the bytes will be writtenset- the enum set to write to the buffer
-
toLong
private <E extends java.lang.Enum<E>> long toLong(java.util.Set<E> set)
-
autoExpand
private IoBuffer autoExpand(int expectedRemaining)
This method forwards the call toexpand(int)only when autoExpand property is true.
-
autoExpand
private IoBuffer autoExpand(int pos, int expectedRemaining)
This method forwards the call toexpand(int)only when autoExpand property is true.
-
checkFieldSize
private static void checkFieldSize(int fieldSize)
-
-