Package org.apache.ignite.internal.util
Class GridByteArrayList
- java.lang.Object
-
- org.apache.ignite.internal.util.GridByteArrayList
-
- All Implemented Interfaces:
Externalizable,Serializable,Message
public class GridByteArrayList extends Object implements Message, Externalizable
Re-sizable array implementation of the byte list (eliminating auto-boxing of primitive byte type).- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from interface org.apache.ignite.plugin.extensions.communication.Message
DIRECT_TYPE_SIZE
-
-
Constructor Summary
Constructors Constructor Description GridByteArrayList()No-op constructor that creates uninitialized list.GridByteArrayList(byte[] data)Wraps existing array into byte array list.GridByteArrayList(byte[] data, int size)Wraps existing array into byte array list.GridByteArrayList(int cap)Creates empty list with the specified initial capacity.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(byte b)Appends byte element to the list.voidadd(byte[] bytes, int off, int len)voidadd(int i)Appends integer to the next 4 bytes of list.voidadd(long l)Appends long to the next 8 bytes of list.voidadd(short i)Appends short to the next 2 bytes of the list.voidadd(ByteBuffer buf, int len)Adds data from byte buffer into array.voidallocate(int cnt)Pre-allocates internal array for specified byte number only if it currently is smaller than desired number.byte[]array()Gets copy of internal array.intcapacity()Gets initial capacity of the list.shortdirectType()Gets message type.byte[]entireArray()Returns internal array if it represents the whole length, otherwise returns the result ofarray().bytefieldsCount()Gets fields count.byteget(int i)Gets the element (byte) at the specified position in the list.intgetInt(int i)Gets 4 bytes from byte list as an integer.InputStreaminputStream()byte[]internalArray()Returns the underlying array.voidonAckReceived()Method called when ack message received.OutputStreamoutputStream()voidreadAll(InputStream in)Reads all data from input stream until the end into this byte list.voidreadExternal(ObjectInput in)booleanreadFrom(ByteBuffer buf, MessageReader reader)Reads this message from provided byte buffer.voidreset()Resets byte array to empty.voidset(int pos, byte b)Sets a byte at specified position.voidset(int pos, int i)Sets integer at specified position.voidset(int pos, long l)Sets long at specified position.voidset(int pos, short i)Sets short at specified position.intsize()Gets number of bytes in the list.StringtoString()voidwriteExternal(ObjectOutput out)booleanwriteTo(ByteBuffer buf, MessageWriter writer)Writes this message to provided byte buffer.
-
-
-
Constructor Detail
-
GridByteArrayList
public GridByteArrayList()
No-op constructor that creates uninitialized list. This method is meant to by used only byExternalizableinterface.
-
GridByteArrayList
public GridByteArrayList(int cap)
Creates empty list with the specified initial capacity.- Parameters:
cap- Initial capacity.
-
GridByteArrayList
public GridByteArrayList(byte[] data, int size)Wraps existing array into byte array list.- Parameters:
data- Array to wrap.size- Size of data inside of array.
-
GridByteArrayList
public GridByteArrayList(byte[] data)
Wraps existing array into byte array list.- Parameters:
data- Array to wrap.
-
-
Method Detail
-
reset
public void reset()
Resets byte array to empty. Note that this method simply resets the size as there is no need to reset every byte in the array.
-
internalArray
public byte[] internalArray()
Returns the underlying array. This method exists as performance optimization to avoid extra copying of the arrays. Data inside of this array should not be altered, only copied.- Returns:
- Internal array.
-
array
public byte[] array()
Gets copy of internal array.- Returns:
- Copy of internal array.
-
entireArray
public byte[] entireArray()
Returns internal array if it represents the whole length, otherwise returns the result ofarray().- Returns:
- Array of exact data size.
-
capacity
public int capacity()
Gets initial capacity of the list.- Returns:
- Initial capacity.
-
size
public int size()
Gets number of bytes in the list.- Returns:
- Number of bytes in the list.
-
allocate
public void allocate(int cnt)
Pre-allocates internal array for specified byte number only if it currently is smaller than desired number.- Parameters:
cnt- Byte number to preallocate.
-
add
public void add(byte b)
Appends byte element to the list.- Parameters:
b- Byte value to append.
-
set
public void set(int pos, byte b)Sets a byte at specified position.- Parameters:
pos- Specified position.b- Byte to set.
-
add
public void add(int i)
Appends integer to the next 4 bytes of list.- Parameters:
i- Integer to append.
-
add
public void add(short i)
Appends short to the next 2 bytes of the list.- Parameters:
i- Short to append.
-
set
public void set(int pos, short i)Sets short at specified position.- Parameters:
pos- Specified position.i- Short to set.
-
set
public void set(int pos, int i)Sets integer at specified position.- Parameters:
pos- Specified position.i- Integer to set.
-
add
public void add(long l)
Appends long to the next 8 bytes of list.- Parameters:
l- Long to append.
-
set
public void set(int pos, long l)Sets long at specified position.- Parameters:
pos- Specified position.l- Long to set.
-
add
public void add(byte[] bytes, int off, int len)- Parameters:
bytes- Byte to add.off- Offset at which to add.len- Number of bytes to add.
-
add
public void add(ByteBuffer buf, int len)
Adds data from byte buffer into array.- Parameters:
buf- Buffer to read bytes from.len- Number of bytes to add.
-
get
public byte get(int i)
Gets the element (byte) at the specified position in the list.- Parameters:
i- Index of element to return.- Returns:
- The element at the specified position in the list.
-
getInt
public int getInt(int i)
Gets 4 bytes from byte list as an integer.- Parameters:
i- Index into the byte list.- Returns:
- Integer starting at index location.
-
readAll
public void readAll(InputStream in) throws IOException
Reads all data from input stream until the end into this byte list.- Parameters:
in- Input stream to read from.- Throws:
IOException- Thrown if any I/O error occurred.
-
outputStream
public OutputStream outputStream()
- Returns:
- Output stream based on this byte array list.
-
inputStream
public InputStream inputStream()
- Returns:
- Input stream based on this byte array list.
-
onAckReceived
public void onAckReceived()
Method called when ack message received.- Specified by:
onAckReceivedin interfaceMessage
-
writeExternal
public void writeExternal(ObjectOutput out) throws IOException
- Specified by:
writeExternalin interfaceExternalizable- Throws:
IOException
-
readExternal
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
- Specified by:
readExternalin interfaceExternalizable- Throws:
IOExceptionClassNotFoundException
-
writeTo
public boolean writeTo(ByteBuffer buf, MessageWriter writer)
Writes this message to provided byte buffer.
-
readFrom
public boolean readFrom(ByteBuffer buf, MessageReader reader)
Reads this message from provided byte buffer.
-
directType
public short directType()
Gets message type.- Specified by:
directTypein interfaceMessage- Returns:
- Message type.
-
fieldsCount
public byte fieldsCount()
Gets fields count.- Specified by:
fieldsCountin interfaceMessage- Returns:
- Fields count.
-
-