Package de.gsi.dataset.serializer.spi
Class ByteBuffer
- java.lang.Object
-
- de.gsi.dataset.serializer.spi.ByteBuffer
-
- All Implemented Interfaces:
IoBuffer,IoBufferHeader<IoBuffer>
public class ByteBuffer extends java.lang.Object implements IoBuffer
- Author:
- rstein
-
-
Field Summary
Fields Modifier and Type Field Description static longSIZE_OF_BOOLEANstatic longSIZE_OF_BYTEstatic longSIZE_OF_CHARstatic longSIZE_OF_DOUBLEstatic longSIZE_OF_FLOATstatic longSIZE_OF_INTstatic longSIZE_OF_LONGstatic longSIZE_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()IoBufferclear()Clears this buffer.IoBufferensureAdditionalCapacity(long capacity)IoBufferensureCapacity(long capacity)IoBufferforceCapacity(long length, long preserve)Forces buffer to contain the given number of entries, preserving just a part of the array.booleangetBoolean()boolean[]getBooleanArray(boolean[] dst, long offset, int length)bytegetByte()byte[]getByteArray(byte[] dst, long offset, int length)chargetChar()char[]getCharArray(char[] dst, long offset, int length)doublegetDouble()double[]getDoubleArray(double[] dst, long offset, int length)floatgetFloat()float[]getFloatArray(float[] dst, long offset, int length)intgetInt()int[]getIntArray(int[] dst, long offset, int length)longgetLong()long[]getLongArray(long[] dst, long offset, int length)shortgetShort()short[]getShortArray(short[] dst, long offset, int length)java.lang.StringgetString()java.lang.String[]getStringArray(java.lang.String[] dst, long offset, int length)booleanhasRemaining()booleanisReadOnly()longlimit()IoBufferlimit(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.longposition()IoBufferposition(long newPosition)Sets this buffer's position.IoBufferputBoolean(boolean value)IoBufferputBooleanArray(boolean[] src, long offset, int nToCopy)IoBufferputByte(byte b)IoBufferputByteArray(byte[] src, long offset, int nToCopy)IoBufferputChar(char value)IoBufferputCharArray(char[] src, long offset, int nToCopy)IoBufferputDouble(double value)IoBufferputDoubleArray(double[] src, long offset, int nToCopy)IoBufferputFloat(float value)IoBufferputFloatArray(float[] src, long offset, int nToCopy)IoBufferputInt(int value)IoBufferputIntArray(int[] src, long offset, int nToCopy)IoBufferputLong(long value)IoBufferputLongArray(long[] src, long offset, int nToCopy)IoBufferputShort(short value)IoBufferputShortArray(short[] src, long offset, int nToCopy)IoBufferputString(java.lang.String string)IoBufferputStringArray(java.lang.String[] src, long offset, int nToCopy)longremaining()IoBufferreset()resets the buffer read/write position to zeroIoBuffertrim()Trims the internal buffer array so that the capacity is equal to the size.IoBuffertrim(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.dataset.serializer.IoBuffer
getBooleanArray, getBooleanArray, getByteArray, getByteArray, getCharArray, getCharArray, getDoubleArray, getDoubleArray, getFloatArray, getFloatArray, getIntArray, getIntArray, getLongArray, getLongArray, getShortArray, getShortArray, getStringArray, getStringArray, putBooleanArray, putBooleanArray, putByteArray, putByteArray, putCharArray, putCharArray, putDoubleArray, putDoubleArray, putFloatArray, putFloatArray, putIntArray, putIntArray, putLongArray, putLongArray, putShortArray, putShortArray, putStringArray, putStringArray
-
-
-
-
Field Detail
-
SIZE_OF_BOOLEAN
public static final long SIZE_OF_BOOLEAN
- See Also:
- Constant Field Values
-
SIZE_OF_BYTE
public static final long SIZE_OF_BYTE
- See Also:
- Constant Field Values
-
SIZE_OF_SHORT
public static final long SIZE_OF_SHORT
- See Also:
- Constant Field Values
-
SIZE_OF_CHAR
public static final long SIZE_OF_CHAR
- See Also:
- Constant Field Values
-
SIZE_OF_INT
public static final long SIZE_OF_INT
- See Also:
- Constant Field Values
-
SIZE_OF_LONG
public static final long SIZE_OF_LONG
- See Also:
- Constant Field Values
-
SIZE_OF_FLOAT
public static final long SIZE_OF_FLOAT
- See Also:
- Constant Field Values
-
SIZE_OF_DOUBLE
public static final long SIZE_OF_DOUBLE
- See Also:
- Constant Field Values
-
-
Method Detail
-
capacity
public int capacity()
- Specified by:
capacityin interfaceIoBufferHeader<IoBuffer>- Returns:
- the capacity of this buffer
-
clear
public IoBuffer 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<IoBuffer>- Returns:
- itself (fluent design)
-
ensureAdditionalCapacity
public IoBuffer ensureAdditionalCapacity(long capacity)
- Specified by:
ensureAdditionalCapacityin interfaceIoBufferHeader<IoBuffer>
-
ensureCapacity
public IoBuffer ensureCapacity(long capacity)
- Specified by:
ensureCapacityin interfaceIoBufferHeader<IoBuffer>
-
forceCapacity
public IoBuffer forceCapacity(long length, long 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<IoBuffer>- 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.- Returns:
- itself (fluent design)
-
getBoolean
public boolean getBoolean()
- Specified by:
getBooleanin interfaceIoBuffer
-
getBooleanArray
public boolean[] getBooleanArray(boolean[] dst, long offset, int length)- Specified by:
getBooleanArrayin interfaceIoBuffer
-
getByteArray
public byte[] getByteArray(byte[] dst, long offset, int length)- Specified by:
getByteArrayin interfaceIoBuffer
-
getCharArray
public char[] getCharArray(char[] dst, long offset, int length)- Specified by:
getCharArrayin interfaceIoBuffer
-
getDoubleArray
public double[] getDoubleArray(double[] dst, long offset, int length)- Specified by:
getDoubleArrayin interfaceIoBuffer
-
getFloatArray
public float[] getFloatArray(float[] dst, long offset, int length)- Specified by:
getFloatArrayin interfaceIoBuffer
-
getIntArray
public int[] getIntArray(int[] dst, long offset, int length)- Specified by:
getIntArrayin interfaceIoBuffer
-
getLongArray
public long[] getLongArray(long[] dst, long offset, int length)- Specified by:
getLongArrayin interfaceIoBuffer
-
getShortArray
public short[] getShortArray(short[] dst, long offset, int length)- Specified by:
getShortArrayin interfaceIoBuffer
-
getStringArray
public java.lang.String[] getStringArray(java.lang.String[] dst, long offset, int length)- Specified by:
getStringArrayin interfaceIoBuffer
-
hasRemaining
public boolean hasRemaining()
- Specified by:
hasRemainingin interfaceIoBufferHeader<IoBuffer>- Returns:
trueif, and only if, there is at least one element remaining in this buffer
-
isReadOnly
public boolean isReadOnly()
- Specified by:
isReadOnlyin interfaceIoBufferHeader<IoBuffer>- Returns:
trueif, and only if, this buffer is read-only
-
limit
public long limit()
- Specified by:
limitin interfaceIoBufferHeader<IoBuffer>- Returns:
- the limit of this buffer
-
limit
public IoBuffer 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<IoBuffer>- Parameters:
newLimit- the new limit value; must be non-negative and no larger than this buffer's capacity- Returns:
- itself (fluent design)
-
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<IoBuffer>- Returns:
- the read-write lock
-
position
public long position()
- Specified by:
positionin interfaceIoBufferHeader<IoBuffer>- Returns:
- the position of this buffer
-
position
public IoBuffer position(long 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<IoBuffer>- Parameters:
newPosition- the new position value; must be non-negative and no larger than the current limit- Returns:
- itself (fluent design)
-
putBoolean
public IoBuffer putBoolean(boolean value)
- Specified by:
putBooleanin interfaceIoBuffer
-
putBooleanArray
public IoBuffer putBooleanArray(boolean[] src, long offset, int nToCopy)
- Specified by:
putBooleanArrayin interfaceIoBuffer
-
putByteArray
public IoBuffer putByteArray(byte[] src, long offset, int nToCopy)
- Specified by:
putByteArrayin interfaceIoBuffer
-
putCharArray
public IoBuffer putCharArray(char[] src, long offset, int nToCopy)
- Specified by:
putCharArrayin interfaceIoBuffer
-
putDoubleArray
public IoBuffer putDoubleArray(double[] src, long offset, int nToCopy)
- Specified by:
putDoubleArrayin interfaceIoBuffer
-
putFloatArray
public IoBuffer putFloatArray(float[] src, long offset, int nToCopy)
- Specified by:
putFloatArrayin interfaceIoBuffer
-
putIntArray
public IoBuffer putIntArray(int[] src, long offset, int nToCopy)
- Specified by:
putIntArrayin interfaceIoBuffer
-
putLongArray
public IoBuffer putLongArray(long[] src, long offset, int nToCopy)
- Specified by:
putLongArrayin interfaceIoBuffer
-
putShortArray
public IoBuffer putShortArray(short[] src, long offset, int nToCopy)
- Specified by:
putShortArrayin interfaceIoBuffer
-
putString
public IoBuffer putString(java.lang.String string)
-
putStringArray
public IoBuffer putStringArray(java.lang.String[] src, long offset, int nToCopy)
- Specified by:
putStringArrayin interfaceIoBuffer
-
remaining
public long remaining()
- Specified by:
remainingin interfaceIoBufferHeader<IoBuffer>- Returns:
- the number of elements remaining in this buffer
-
reset
public IoBuffer reset()
Description copied from interface:IoBufferHeaderresets the buffer read/write position to zero- Specified by:
resetin interfaceIoBufferHeader<IoBuffer>- Returns:
- itself (fluent design)
-
trim
public IoBuffer trim()
Description copied from interface:IoBufferHeaderTrims the internal buffer array so that the capacity is equal to the size.- Specified by:
trimin interfaceIoBufferHeader<IoBuffer>- Returns:
- itself (fluent design)
- See Also:
ArrayList.trimToSize()
-
trim
public IoBuffer 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<IoBuffer>- Parameters:
requestedCapacity- the threshold for the trimming.- Returns:
- itself (fluent design)
-
-