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 and 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
`void` `add(byte b)` Appends byte element to the list.
`void` `add(byte[] bytes, int off, int len)`
`void` `add(ByteBuffer buf, int len)` Adds data from byte buffer into array.
`void` `add(int i)` Appends integer to the next 4 bytes of list.
`void` `add(long l)` Appends long to the next 8 bytes of list.
`void` `add(short i)` Appends short to the next 2 bytes of the list.
`void` `allocate(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.
`int` `capacity()` Gets initial capacity of the list.
`short` `directType()` Gets message type.
`byte[]` `entireArray()` Returns internal array if it represents the whole length, otherwise returns the result of `array()`.
`byte` `fieldsCount()` Gets fields count.
`byte` `get(int i)` Gets the element (byte) at the specified position in the list.
`int` `getInt(int i)` Gets 4 bytes from byte list as an integer.
`InputStream` `inputStream()`
`byte[]` `internalArray()` Returns the underlying array.
`void` `onAckReceived()` Method called when ack message received.
`OutputStream` `outputStream()`
`void` `readAll(InputStream in)` Reads all data from input stream until the end into this byte list.
`void` `readExternal(ObjectInput in)`
`boolean` `readFrom(ByteBuffer buf, MessageReader reader)` Reads this message from provided byte buffer.
`void` `reset()` Resets byte array to empty.
`void` `set(int pos, byte b)` Sets a byte at specified position.
`void` `set(int pos, int i)` Sets integer at specified position.
`void` `set(int pos, long l)` Sets long at specified position.
`void` `set(int pos, short i)` Sets short at specified position.
`int` `size()` Gets number of bytes in the list.
`String` `toString()`
`void` `writeExternal(ObjectOutput out)`
`boolean` `writeTo(ByteBuffer buf, MessageWriter writer)` Writes this message to provided byte buffer.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

### Constructor Detail

#### GridByteArrayList

    public GridByteArrayList()

No-op constructor that creates uninitialized list. This method is meant to by used only by `Externalizable` interface.

#### 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 of `array()`.

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:
  `onAckReceived` in interface `Message`

#### writeExternal

    public void writeExternal(ObjectOutput out)
                       throws IOException

Specified by:
  `writeExternal` in interface `Externalizable`
Throws:
  `IOException`

#### readExternal

    public void readExternal(ObjectInput in)
                      throws IOException,
                             ClassNotFoundException

Specified by:
  `readExternal` in interface `Externalizable`
Throws:
  `IOException`
  `ClassNotFoundException`

#### writeTo

    public boolean writeTo(ByteBuffer buf,
                           MessageWriter writer)

Writes this message to provided byte buffer.

Specified by:
  `writeTo` in interface `Message`
Parameters:
  `buf` - Byte buffer.
  `writer` - Writer.
Returns:
  Whether message was fully written.

#### readFrom

    public boolean readFrom(ByteBuffer buf,
                            MessageReader reader)

Reads this message from provided byte buffer.

Specified by:
  `readFrom` in interface `Message`
Parameters:
  `buf` - Byte buffer.
  `reader` - Reader.
Returns:
  Whether message was fully read.

#### directType

    public short directType()

Gets message type.

Specified by:
  `directType` in interface `Message`
Returns:
  Message type.

#### fieldsCount

    public byte fieldsCount()

Gets fields count.

Specified by:
  `fieldsCount` in interface `Message`
Returns:
  Fields count.

#### toString

    public String toString()

Overrides:
  `toString` in class `Object`

${current.year} Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Database and Caching Platform | : ver. 2.13.0
Release Date | : April 20 2022