Package de.gsi.serializer.spi
Class ByteBuffer
- java.lang.Object
-
- de.gsi.serializer.spi.ByteBuffer
-
- All Implemented Interfaces:
IoBuffer,IoBufferHeader
public class ByteBuffer extends java.lang.Object implements IoBuffer
- Author:
- rstein
-
-
Field Summary
Fields Modifier and Type Field Description static intSIZE_OF_BOOLEANstatic intSIZE_OF_BYTEstatic intSIZE_OF_CHARstatic intSIZE_OF_DOUBLEstatic intSIZE_OF_FLOATstatic intSIZE_OF_INTstatic intSIZE_OF_LONGstatic intSIZE_OF_SHORT
-
Constructor Summary
Constructors Constructor Description ByteBuffer()construct new java.nio.ByteBuffer-based ByteBuffer with DEFAULT_INITIAL_CAPACITYByteBuffer(int nCapacity)construct new java.nio.ByteBuffer-based ByteBuffer with DEFAULT_INITIAL_CAPACITY
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intcapacity()voidclear()Clears this buffer.byte[]elements()voidensureAdditionalCapacity(int capacity)voidensureCapacity(int capacity)voidflip()Flips this buffer.voidforceCapacity(int length, int preserve)Forces buffer to contain the given number of entries, preserving just a part of the array.booleangetBoolean()booleangetBoolean(int position)boolean[]getBooleanArray(boolean[] dst, int length)bytegetByte()bytegetByte(int position)byte[]getByteArray(byte[] dst, int length)chargetChar()chargetChar(int position)char[]getCharArray(char[] dst, int length)doublegetDouble()doublegetDouble(int position)double[]getDoubleArray(double[] dst, int length)floatgetFloat()floatgetFloat(int position)float[]getFloatArray(float[] dst, int length)intgetInt()intgetInt(int position)int[]getIntArray(int[] dst, int length)longgetLong()longgetLong(int position)long[]getLongArray(long[] dst, int length)shortgetShort()shortgetShort(int position)short[]getShortArray(short[] dst, int length)java.lang.StringgetString()java.lang.StringgetString(int position)java.lang.String[]getStringArray(java.lang.String[] dst, int length)java.lang.StringgetStringISO8859()booleanhasRemaining()booleanisEnforceSimpleStringEncoding()booleanisReadOnly()intlimit()voidlimit(int newLimit)Sets this buffer's limit.java.util.concurrent.locks.ReadWriteLocklock()For efficiency/performance reasons the buffer implementation is not required to safe-guard each put/get method independently.intposition()voidposition(int newPosition)Sets this buffer's position.voidputBoolean(boolean value)voidputBoolean(int position, boolean value)voidputBooleanArray(boolean[] src, int n)voidputByte(byte b)voidputByte(int position, byte value)voidputByteArray(byte[] src, int n)voidputChar(char value)voidputChar(int position, char value)voidputCharArray(char[] src, int n)voidputDouble(double value)voidputDouble(int position, double value)voidputDoubleArray(double[] src, int n)voidputFloat(float value)voidputFloat(int position, float value)voidputFloatArray(float[] src, int n)voidputInt(int value)voidputInt(int position, int value)voidputIntArray(int[] src, int n)voidputLong(int position, long value)voidputLong(long value)voidputLongArray(long[] src, int n)voidputShort(int position, short value)voidputShort(short value)voidputShortArray(short[] src, int n)voidputString(int position, java.lang.String value)voidputString(java.lang.String string)voidputStringArray(java.lang.String[] src, int n)voidputStringISO8859(java.lang.String string)intremaining()voidreset()resets the buffer read/write position to zerovoidsetEnforceSimpleStringEncoding(boolean state)voidtrim()Trims the internal buffer array so that the capacity is equal to the size.voidtrim(int requestedCapacity)Trims the internal buffer array if it is too large.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface de.gsi.serializer.IoBuffer
getBooleanArray, getBooleanArray, getByteArray, getByteArray, getCharArray, getCharArray, getDoubleArray, getDoubleArray, getFloatArray, getFloatArray, getIntArray, getIntArray, getLongArray, getLongArray, getShortArray, getShortArray, getStringArray, getStringArray
-
-
-
-
Field Detail
-
SIZE_OF_BOOLEAN
public static final int SIZE_OF_BOOLEAN
- See Also:
- Constant Field Values
-
SIZE_OF_BYTE
public static final int SIZE_OF_BYTE
- See Also:
- Constant Field Values
-
SIZE_OF_SHORT
public static final int SIZE_OF_SHORT
- See Also:
- Constant Field Values
-
SIZE_OF_CHAR
public static final int SIZE_OF_CHAR
- See Also:
- Constant Field Values
-
SIZE_OF_INT
public static final int SIZE_OF_INT
- See Also:
- Constant Field Values
-
SIZE_OF_LONG
public static final int SIZE_OF_LONG
- See Also:
- Constant Field Values
-
SIZE_OF_FLOAT
public static final int SIZE_OF_FLOAT
- See Also:
- Constant Field Values
-
SIZE_OF_DOUBLE
public static final int SIZE_OF_DOUBLE
- See Also:
- Constant Field Values
-
-
Method Detail
-
capacity
public int capacity()
- Specified by:
capacityin interfaceIoBufferHeader- Returns:
- the capacity of this buffer
-
clear
public void clear()
Description copied from interface:IoBufferHeaderClears this buffer. The position is set to zero amd the limit is set to the capacity.Invoke this method before using a sequence of channel-read or put operations to fill this buffer. For example:
buf.clear(); // Prepare buffer for reading in.read(buf); // Read data
This method does not actually erase the data in the buffer, but it is named as if it did because it will most often be used in situations in which that might as well be the case.
- Specified by:
clearin interfaceIoBufferHeader
-
elements
public byte[] elements()
-
ensureAdditionalCapacity
public void ensureAdditionalCapacity(int capacity)
- Specified by:
ensureAdditionalCapacityin interfaceIoBufferHeader
-
ensureCapacity
public void ensureCapacity(int capacity)
- Specified by:
ensureCapacityin interfaceIoBufferHeader
-
flip
public void flip()
Description copied from interface:IoBufferHeaderFlips this buffer. The limit is set to the current position and then the position is set to zero. If the mark is defined then it is discarded.After a sequence of channel-read or put operations, invoke this method to prepare for a sequence of channel-write or relative get operations. For example:
buf.put(magic); // Prepend header in.read(buf); // Read data into rest of buffer buf.flip(); // Flip buffer out.write(buf); // Write header + data to channel
- Specified by:
flipin interfaceIoBufferHeader
-
forceCapacity
public void forceCapacity(int length, int preserve)Description copied from interface:IoBufferHeaderForces buffer to contain the given number of entries, preserving just a part of the array.- Specified by:
forceCapacityin interfaceIoBufferHeader- Parameters:
length- the new minimum length for this array.preserve- the number of elements of the old buffer that shall be preserved in case a new allocation is necessary.
-
getBoolean
public boolean getBoolean()
- Specified by:
getBooleanin interfaceIoBuffer
-
getBoolean
public boolean getBoolean(int position)
- Specified by:
getBooleanin interfaceIoBuffer
-
getBooleanArray
public boolean[] getBooleanArray(boolean[] dst, int length)- Specified by:
getBooleanArrayin interfaceIoBuffer
-
getByteArray
public byte[] getByteArray(byte[] dst, int length)- Specified by:
getByteArrayin interfaceIoBuffer
-
getCharArray
public char[] getCharArray(char[] dst, int length)- Specified by:
getCharArrayin interfaceIoBuffer
-
getDoubleArray
public double[] getDoubleArray(double[] dst, int length)- Specified by:
getDoubleArrayin interfaceIoBuffer
-
getFloatArray
public float[] getFloatArray(float[] dst, int length)- Specified by:
getFloatArrayin interfaceIoBuffer
-
getIntArray
public int[] getIntArray(int[] dst, int length)- Specified by:
getIntArrayin interfaceIoBuffer
-
getLongArray
public long[] getLongArray(long[] dst, int length)- Specified by:
getLongArrayin interfaceIoBuffer
-
getShortArray
public short[] getShortArray(short[] dst, int length)- Specified by:
getShortArrayin interfaceIoBuffer
-
getString
public java.lang.String getString(int position)
-
getStringArray
public java.lang.String[] getStringArray(java.lang.String[] dst, int length)- Specified by:
getStringArrayin interfaceIoBuffer
-
getStringISO8859
public java.lang.String getStringISO8859()
- Specified by:
getStringISO8859in interfaceIoBuffer
-
hasRemaining
public boolean hasRemaining()
- Specified by:
hasRemainingin interfaceIoBufferHeader- Returns:
trueif, and only if, there is at least one element remaining in this buffer
-
isEnforceSimpleStringEncoding
public boolean isEnforceSimpleStringEncoding()
- Specified by:
isEnforceSimpleStringEncodingin interfaceIoBuffer- Returns:
truethe ISO-8859-1 character encoding is being enforced for data fields (better performance), otherwise UTF-8 is being used (more generic encoding)
-
setEnforceSimpleStringEncoding
public void setEnforceSimpleStringEncoding(boolean state)
- Specified by:
setEnforceSimpleStringEncodingin interfaceIoBuffer- Parameters:
state-truethe ISO-8859-1 character encoding is being enforced for data fields (better performance), otherwise UTF-8 is being used (more generic encoding)
-
isReadOnly
public boolean isReadOnly()
- Specified by:
isReadOnlyin interfaceIoBufferHeader- Returns:
trueif, and only if, this buffer is read-only
-
limit
public int limit()
- Specified by:
limitin interfaceIoBufferHeader- Returns:
- the limit of this buffer
-
limit
public void limit(int newLimit)
Description copied from interface:IoBufferHeaderSets this buffer's limit. If the position is larger than the new limit then it is set to the new limit. If the mark is defined and larger than the new limit then it is discarded.- Specified by:
limitin interfaceIoBufferHeader- Parameters:
newLimit- the new limit value; must be non-negative and no larger than this buffer's capacity
-
lock
public java.util.concurrent.locks.ReadWriteLock lock()
Description copied from interface:IoBufferHeaderFor efficiency/performance reasons the buffer implementation is not required to safe-guard each put/get method independently. Thus the user-code should acquire the given lock around a set of put/get appropriately.- Specified by:
lockin interfaceIoBufferHeader- Returns:
- the read-write lock
-
position
public int position()
- Specified by:
positionin interfaceIoBufferHeader- Returns:
- the position of this buffer
-
position
public void position(int newPosition)
Description copied from interface:IoBufferHeaderSets this buffer's position. If the mark is defined and larger than the new position then it is discarded.- Specified by:
positionin interfaceIoBufferHeader- Parameters:
newPosition- the new position value; must be non-negative and no larger than the current limit
-
putBoolean
public void putBoolean(boolean value)
- Specified by:
putBooleanin interfaceIoBuffer
-
putBoolean
public void putBoolean(int position, boolean value)- Specified by:
putBooleanin interfaceIoBuffer
-
putBooleanArray
public void putBooleanArray(boolean[] src, int n)- Specified by:
putBooleanArrayin interfaceIoBuffer
-
putByteArray
public void putByteArray(byte[] src, int n)- Specified by:
putByteArrayin interfaceIoBuffer
-
putCharArray
public void putCharArray(char[] src, int n)- Specified by:
putCharArrayin interfaceIoBuffer
-
putDouble
public void putDouble(int position, double value)
-
putDoubleArray
public void putDoubleArray(double[] src, int n)- Specified by:
putDoubleArrayin interfaceIoBuffer
-
putFloat
public void putFloat(int position, float value)
-
putFloatArray
public void putFloatArray(float[] src, int n)- Specified by:
putFloatArrayin interfaceIoBuffer
-
putIntArray
public void putIntArray(int[] src, int n)- Specified by:
putIntArrayin interfaceIoBuffer
-
putLongArray
public void putLongArray(long[] src, int n)- Specified by:
putLongArrayin interfaceIoBuffer
-
putShort
public void putShort(int position, short value)
-
putShortArray
public void putShortArray(short[] src, int n)- Specified by:
putShortArrayin interfaceIoBuffer
-
putString
public void putString(java.lang.String string)
-
putString
public void putString(int position, java.lang.String value)
-
putStringArray
public void putStringArray(java.lang.String[] src, int n)- Specified by:
putStringArrayin interfaceIoBuffer
-
putStringISO8859
public void putStringISO8859(java.lang.String string)
- Specified by:
putStringISO8859in interfaceIoBuffer
-
remaining
public int remaining()
- Specified by:
remainingin interfaceIoBufferHeader- Returns:
- the number of elements remaining in this buffer
-
reset
public void reset()
Description copied from interface:IoBufferHeaderresets the buffer read/write position to zero- Specified by:
resetin interfaceIoBufferHeader
-
trim
public void trim()
Description copied from interface:IoBufferHeaderTrims the internal buffer array so that the capacity is equal to the size.- Specified by:
trimin interfaceIoBufferHeader- See Also:
ArrayList.trimToSize()
-
trim
public void trim(int requestedCapacity)
Description copied from interface:IoBufferHeaderTrims the internal buffer array if it is too large. If the current array length is smaller than or equal ton, this method does nothing. Otherwise, it trims the array length to the maximum betweenrequestedCapacityandIoBufferHeader.capacity().This method is useful when reusing FastBuffers. Clearing a list leaves the array length untouched. If you are reusing a list many times, you can call this method with a typical size to avoid keeping around a very large array just because of a few large transient lists.
- Specified by:
trimin interfaceIoBufferHeader- Parameters:
requestedCapacity- the threshold for the trimming.
-
-