Class GridByteArrayList

    • 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
      • 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.