Class JavaByteBuffer
- java.lang.Object
-
- es.bsc.dataclay.serialization.buffer.JavaByteBuffer
-
- All Implemented Interfaces:
DataClayByteBuffer
public final class JavaByteBuffer extends Object implements DataClayByteBuffer
Java byte buffer to be used while no communication is nedded.
-
-
Constructor Summary
Constructors Constructor Description JavaByteBuffer()
Constructor used for codificationJavaByteBuffer(byte[] newBuffer)
Constructor used for decodificationJavaByteBuffer(ByteBuffer data)
Constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
Clear the buffervoid
discardSomeReadBytes()
Discard the bytes available to be read.byte[]
getArray()
Gets the byte array used by this bufferio.grpc.netty.shaded.io.netty.buffer.ByteBuf
getBuffer()
Gets the netty buffervoid
increaseBufferSize(int newBufferSize)
Increase the buffer size to a new size providedboolean
isReadable()
Check if the buffer has some bytes to readint
maxCapacity()
Gets the maximum capacity of the bufferint
readableBytes()
Get the number of bytes available to be read.boolean
readBoolean()
Get a boolean from the byte bufferboolean[]
readBooleans(int size)
Get an array of booleans.byte
readByte()
Get a byte from the byte bufferbyte[]
readByteArray()
Get a byte array from the byte bufferbyte[][]
readByteArrays(int size)
Get an array of byte arrays.void
readBytes(byte[] values)
Get an array of bytes into the variable provided.byte[]
readBytes(int size)
Get an array of bytes.char
readChar()
Get a char from the byte bufferchar[]
readChars(int size)
Get an array of chars.double
readDouble()
Get a double from the byte bufferdouble[]
readDoubles(int size)
Get an array of doubles.int
readerIndex()
Get the index in buffer of the reader pointerfloat
readFloat()
Get a float from the byte bufferfloat[]
readFloats(int size)
Get an array of floats.int
readInt()
Get an integer from the byte bufferint[]
readInts(int size)
Get an array of integers from the byte bufferlong
readLong()
Get a long from the byte bufferlong[]
readLongs(int size)
Get an array of longs.short
readShort()
Get a short from the byte buffershort[]
readShorts(int size)
Get an array of shorts.String
readString()
Get a string from the byte bufferString[]
readStrings(int size)
Get an array of strings.int
readVLQInt()
Get a variable length integer from the byte buffer.void
release()
Release the buffervoid
rewind()
Rewind the buffer.void
setBuffer(io.grpc.netty.shaded.io.netty.buffer.ByteBuf byteBuf)
Sets the netty buffervoid
setReaderIndex(int index)
Sets the reader index to the position with index providedvoid
setWriterIndex(int index)
Sets the writer index to the position with index providedvoid
wrapBytes(byte[] newBuffer)
Wrap bytes to avoid copying them.void
writeBoolean(boolean value)
Put a boolean into the byte buffer.void
writeBooleans(boolean[] values)
Put an array of booleans into the byte buffer.void
writeByte(byte value)
Put a byte into the byte buffer.void
writeByteArray(byte[] value)
Put a byte array into the byte buffer.void
writeByteArrays(byte[][] values)
Put an array of byte arrays into the byte buffer.void
writeBytes(byte[] values)
Put an array of bytes into the byte buffer.void
writeBytes(DataClayByteBuffer binBuffer)
Copy all bytes from the buffer providedvoid
writeChar(char value)
Put a char into the byte buffer.void
writeChars(char[] values)
Put an array of chars into the byte buffer.void
writeDouble(double value)
Put a double into the byte buffer.void
writeDoubles(double[] values)
Put an array of doubles into the byte buffer.void
writeFloat(float value)
Put a float into the byte buffer.void
writeFloats(float[] values)
Put an array of floats into the byte buffer.void
writeInt(int value)
Put an integer into the byte buffer.void
writeInts(int[] values)
Put an array of integers into the byte buffervoid
writeLong(long value)
Put a long into the byte buffer.void
writeLongs(long[] values)
Put an array of longs into the byte buffer.int
writerIndex()
Get the index in buffer of the writer pointervoid
writeShort(short value)
Put a short into the byte buffer.void
writeShorts(short[] values)
Put an array of shorts into the byte buffer.void
writeString(String value)
Put a string into the byte buffer.void
writeStrings(String[] values)
Put an array of strings into the byte buffer.void
writeVLQInt(int value)
Put a variable length integer into the byte buffer.
-
-
-
Constructor Detail
-
JavaByteBuffer
public JavaByteBuffer(byte[] newBuffer)
Constructor used for decodification- Parameters:
newBuffer
- The byte array to deserialize
-
JavaByteBuffer
public JavaByteBuffer()
Constructor used for codification
-
JavaByteBuffer
public JavaByteBuffer(ByteBuffer data)
Constructor- Parameters:
data
- ByteBuffer containing data
-
-
Method Detail
-
rewind
public void rewind()
Description copied from interface:DataClayByteBuffer
Rewind the buffer.- Specified by:
rewind
in interfaceDataClayByteBuffer
-
wrapBytes
public void wrapBytes(byte[] newBuffer)
Description copied from interface:DataClayByteBuffer
Wrap bytes to avoid copying them.- Specified by:
wrapBytes
in interfaceDataClayByteBuffer
- Parameters:
newBuffer
- The byte array to deserialize
-
isReadable
public boolean isReadable()
Description copied from interface:DataClayByteBuffer
Check if the buffer has some bytes to read- Specified by:
isReadable
in interfaceDataClayByteBuffer
- Returns:
- TRUE if the buffer has some bytes to read. FALSE otherwise.
-
readableBytes
public int readableBytes()
Description copied from interface:DataClayByteBuffer
Get the number of bytes available to be read.- Specified by:
readableBytes
in interfaceDataClayByteBuffer
- Returns:
- The number of bytes available to be read.
-
readerIndex
public int readerIndex()
Description copied from interface:DataClayByteBuffer
Get the index in buffer of the reader pointer- Specified by:
readerIndex
in interfaceDataClayByteBuffer
- Returns:
- The index in buffer of the reader pointer
-
writerIndex
public int writerIndex()
Description copied from interface:DataClayByteBuffer
Get the index in buffer of the writer pointer- Specified by:
writerIndex
in interfaceDataClayByteBuffer
- Returns:
- The index in buffer of the writer pointer
-
clear
public void clear()
Description copied from interface:DataClayByteBuffer
Clear the buffer- Specified by:
clear
in interfaceDataClayByteBuffer
-
setReaderIndex
public void setReaderIndex(int index)
Description copied from interface:DataClayByteBuffer
Sets the reader index to the position with index provided- Specified by:
setReaderIndex
in interfaceDataClayByteBuffer
- Parameters:
index
- the new reader position
-
setWriterIndex
public void setWriterIndex(int index)
Description copied from interface:DataClayByteBuffer
Sets the writer index to the position with index provided- Specified by:
setWriterIndex
in interfaceDataClayByteBuffer
- Parameters:
index
- the new writer position
-
maxCapacity
public int maxCapacity()
Description copied from interface:DataClayByteBuffer
Gets the maximum capacity of the buffer- Specified by:
maxCapacity
in interfaceDataClayByteBuffer
- Returns:
- the maximum capacity of the buffer
-
release
public void release()
Description copied from interface:DataClayByteBuffer
Release the buffer- Specified by:
release
in interfaceDataClayByteBuffer
-
increaseBufferSize
public void increaseBufferSize(int newBufferSize)
Description copied from interface:DataClayByteBuffer
Increase the buffer size to a new size provided- Specified by:
increaseBufferSize
in interfaceDataClayByteBuffer
- Parameters:
newBufferSize
- The new buffer size
-
discardSomeReadBytes
public void discardSomeReadBytes()
Description copied from interface:DataClayByteBuffer
Discard the bytes available to be read.- Specified by:
discardSomeReadBytes
in interfaceDataClayByteBuffer
-
getBuffer
public io.grpc.netty.shaded.io.netty.buffer.ByteBuf getBuffer()
Description copied from interface:DataClayByteBuffer
Gets the netty buffer- Specified by:
getBuffer
in interfaceDataClayByteBuffer
- Returns:
- The netty buffer
-
setBuffer
public void setBuffer(io.grpc.netty.shaded.io.netty.buffer.ByteBuf byteBuf)
Description copied from interface:DataClayByteBuffer
Sets the netty buffer- Specified by:
setBuffer
in interfaceDataClayByteBuffer
- Parameters:
byteBuf
- the netty buffer to set
-
getArray
public byte[] getArray()
Description copied from interface:DataClayByteBuffer
Gets the byte array used by this buffer- Specified by:
getArray
in interfaceDataClayByteBuffer
- Returns:
- the byte array used by this buffer
-
writeInt
public void writeInt(int value)
Description copied from interface:DataClayByteBuffer
Put an integer into the byte buffer.- Specified by:
writeInt
in interfaceDataClayByteBuffer
- Parameters:
value
- Integer to add.
-
readInt
public int readInt()
Description copied from interface:DataClayByteBuffer
Get an integer from the byte buffer- Specified by:
readInt
in interfaceDataClayByteBuffer
- Returns:
- integer from the array.
-
writeVLQInt
public void writeVLQInt(int value)
Description copied from interface:DataClayByteBuffer
Put a variable length integer into the byte buffer.- Specified by:
writeVLQInt
in interfaceDataClayByteBuffer
- Parameters:
value
- Integer to represent.
-
readVLQInt
public int readVLQInt()
Description copied from interface:DataClayByteBuffer
Get a variable length integer from the byte buffer.- Specified by:
readVLQInt
in interfaceDataClayByteBuffer
- Returns:
- integer represented in byte array.
-
writeInts
public void writeInts(int[] values)
Description copied from interface:DataClayByteBuffer
Put an array of integers into the byte buffer- Specified by:
writeInts
in interfaceDataClayByteBuffer
- Parameters:
values
- Array of integers to add.
-
readInts
public int[] readInts(int size)
Description copied from interface:DataClayByteBuffer
Get an array of integers from the byte buffer- Specified by:
readInts
in interfaceDataClayByteBuffer
- Parameters:
size
- Number of ints to read- Returns:
- Array of integers read
-
writeByte
public void writeByte(byte value)
Description copied from interface:DataClayByteBuffer
Put a byte into the byte buffer.- Specified by:
writeByte
in interfaceDataClayByteBuffer
- Parameters:
value
- Integer to add.
-
readByte
public byte readByte()
Description copied from interface:DataClayByteBuffer
Get a byte from the byte buffer- Specified by:
readByte
in interfaceDataClayByteBuffer
- Returns:
- byte from the arrray.
-
writeBytes
public void writeBytes(byte[] values)
Description copied from interface:DataClayByteBuffer
Put an array of bytes into the byte buffer.- Specified by:
writeBytes
in interfaceDataClayByteBuffer
- Parameters:
values
- Array of bytes to add.
-
writeBytes
public void writeBytes(DataClayByteBuffer binBuffer)
Description copied from interface:DataClayByteBuffer
Copy all bytes from the buffer provided- Specified by:
writeBytes
in interfaceDataClayByteBuffer
- Parameters:
binBuffer
- Binary buffer from which to copy bytes
-
readBytes
public void readBytes(byte[] values)
Description copied from interface:DataClayByteBuffer
Get an array of bytes into the variable provided.- Specified by:
readBytes
in interfaceDataClayByteBuffer
- Parameters:
values
- destination byte array.
-
writeLong
public void writeLong(long value)
Description copied from interface:DataClayByteBuffer
Put a long into the byte buffer.- Specified by:
writeLong
in interfaceDataClayByteBuffer
- Parameters:
value
- Long to add.
-
readLong
public long readLong()
Description copied from interface:DataClayByteBuffer
Get a long from the byte buffer- Specified by:
readLong
in interfaceDataClayByteBuffer
- Returns:
- long from the array.
-
writeLongs
public void writeLongs(long[] values)
Description copied from interface:DataClayByteBuffer
Put an array of longs into the byte buffer.- Specified by:
writeLongs
in interfaceDataClayByteBuffer
- Parameters:
values
- Array of longs to add.
-
readLongs
public long[] readLongs(int size)
Description copied from interface:DataClayByteBuffer
Get an array of longs.- Specified by:
readLongs
in interfaceDataClayByteBuffer
- Parameters:
size
- number of longs to read- Returns:
- An array of longs.
-
readBytes
public byte[] readBytes(int size)
Description copied from interface:DataClayByteBuffer
Get an array of bytes.- Specified by:
readBytes
in interfaceDataClayByteBuffer
- Parameters:
size
- number of bytes to read- Returns:
- An array of bytes.
-
writeFloat
public void writeFloat(float value)
Description copied from interface:DataClayByteBuffer
Put a float into the byte buffer.- Specified by:
writeFloat
in interfaceDataClayByteBuffer
- Parameters:
value
- float to add.
-
readFloat
public float readFloat()
Description copied from interface:DataClayByteBuffer
Get a float from the byte buffer- Specified by:
readFloat
in interfaceDataClayByteBuffer
- Returns:
- float from the array.
-
writeFloats
public void writeFloats(float[] values)
Description copied from interface:DataClayByteBuffer
Put an array of floats into the byte buffer.- Specified by:
writeFloats
in interfaceDataClayByteBuffer
- Parameters:
values
- Array of floats to add.
-
readFloats
public float[] readFloats(int size)
Description copied from interface:DataClayByteBuffer
Get an array of floats.- Specified by:
readFloats
in interfaceDataClayByteBuffer
- Parameters:
size
- number of floats to read- Returns:
- An array of floats.
-
writeDouble
public void writeDouble(double value)
Description copied from interface:DataClayByteBuffer
Put a double into the byte buffer.- Specified by:
writeDouble
in interfaceDataClayByteBuffer
- Parameters:
value
- double to add.
-
readDouble
public double readDouble()
Description copied from interface:DataClayByteBuffer
Get a double from the byte buffer- Specified by:
readDouble
in interfaceDataClayByteBuffer
- Returns:
- double from the array.
-
writeDoubles
public void writeDoubles(double[] values)
Description copied from interface:DataClayByteBuffer
Put an array of doubles into the byte buffer.- Specified by:
writeDoubles
in interfaceDataClayByteBuffer
- Parameters:
values
- Array of doubles to add.
-
readDoubles
public double[] readDoubles(int size)
Description copied from interface:DataClayByteBuffer
Get an array of doubles.- Specified by:
readDoubles
in interfaceDataClayByteBuffer
- Parameters:
size
- number of doubles to read- Returns:
- An array of doubles.
-
writeBoolean
public void writeBoolean(boolean value)
Description copied from interface:DataClayByteBuffer
Put a boolean into the byte buffer.- Specified by:
writeBoolean
in interfaceDataClayByteBuffer
- Parameters:
value
- boolean to add.
-
readBoolean
public boolean readBoolean()
Description copied from interface:DataClayByteBuffer
Get a boolean from the byte buffer- Specified by:
readBoolean
in interfaceDataClayByteBuffer
- Returns:
- boolean from the array.
-
writeBooleans
public void writeBooleans(boolean[] values)
Description copied from interface:DataClayByteBuffer
Put an array of booleans into the byte buffer.- Specified by:
writeBooleans
in interfaceDataClayByteBuffer
- Parameters:
values
- Array of booleans to add.
-
readBooleans
public boolean[] readBooleans(int size)
Description copied from interface:DataClayByteBuffer
Get an array of booleans.- Specified by:
readBooleans
in interfaceDataClayByteBuffer
- Parameters:
size
- number of booleans to read- Returns:
- An array of booleans.
-
writeChar
public void writeChar(char value)
Description copied from interface:DataClayByteBuffer
Put a char into the byte buffer.- Specified by:
writeChar
in interfaceDataClayByteBuffer
- Parameters:
value
- char to add.
-
readChar
public char readChar()
Description copied from interface:DataClayByteBuffer
Get a char from the byte buffer- Specified by:
readChar
in interfaceDataClayByteBuffer
- Returns:
- char from the array.
-
writeChars
public void writeChars(char[] values)
Description copied from interface:DataClayByteBuffer
Put an array of chars into the byte buffer.- Specified by:
writeChars
in interfaceDataClayByteBuffer
- Parameters:
values
- Array of chars to add.
-
readChars
public char[] readChars(int size)
Description copied from interface:DataClayByteBuffer
Get an array of chars.- Specified by:
readChars
in interfaceDataClayByteBuffer
- Parameters:
size
- number of chars to read- Returns:
- An array of chars.
-
writeShort
public void writeShort(short value)
Description copied from interface:DataClayByteBuffer
Put a short into the byte buffer.- Specified by:
writeShort
in interfaceDataClayByteBuffer
- Parameters:
value
- short to add.
-
readShort
public short readShort()
Description copied from interface:DataClayByteBuffer
Get a short from the byte buffer- Specified by:
readShort
in interfaceDataClayByteBuffer
- Returns:
- short from the array.
-
writeShorts
public void writeShorts(short[] values)
Description copied from interface:DataClayByteBuffer
Put an array of shorts into the byte buffer.- Specified by:
writeShorts
in interfaceDataClayByteBuffer
- Parameters:
values
- Array of shorts to add.
-
readShorts
public short[] readShorts(int size)
Description copied from interface:DataClayByteBuffer
Get an array of shorts.- Specified by:
readShorts
in interfaceDataClayByteBuffer
- Parameters:
size
- number of shorts to read- Returns:
- An array of shorts.
-
writeString
public void writeString(String value)
Description copied from interface:DataClayByteBuffer
Put a string into the byte buffer.- Specified by:
writeString
in interfaceDataClayByteBuffer
- Parameters:
value
- string to add.
-
readString
public String readString()
Description copied from interface:DataClayByteBuffer
Get a string from the byte buffer- Specified by:
readString
in interfaceDataClayByteBuffer
- Returns:
- string from the array.
-
writeStrings
public void writeStrings(String[] values)
Description copied from interface:DataClayByteBuffer
Put an array of strings into the byte buffer.- Specified by:
writeStrings
in interfaceDataClayByteBuffer
- Parameters:
values
- Array of strings to add.
-
readStrings
public String[] readStrings(int size)
Description copied from interface:DataClayByteBuffer
Get an array of strings.- Specified by:
readStrings
in interfaceDataClayByteBuffer
- Parameters:
size
- number of strings to read- Returns:
- An array of strings.
-
writeByteArray
public void writeByteArray(byte[] value)
Description copied from interface:DataClayByteBuffer
Put a byte array into the byte buffer.- Specified by:
writeByteArray
in interfaceDataClayByteBuffer
- Parameters:
value
- byte array to add.
-
readByteArray
public byte[] readByteArray()
Description copied from interface:DataClayByteBuffer
Get a byte array from the byte buffer- Specified by:
readByteArray
in interfaceDataClayByteBuffer
- Returns:
- byte array from the array.
-
writeByteArrays
public void writeByteArrays(byte[][] values)
Description copied from interface:DataClayByteBuffer
Put an array of byte arrays into the byte buffer.- Specified by:
writeByteArrays
in interfaceDataClayByteBuffer
- Parameters:
values
- Array of byte arrays to add.
-
readByteArrays
public byte[][] readByteArrays(int size)
Description copied from interface:DataClayByteBuffer
Get an array of byte arrays.- Specified by:
readByteArrays
in interfaceDataClayByteBuffer
- Parameters:
size
- number of byte arrays to read- Returns:
- An array of byte arrays.
-
-