Class ByteBuffer

  • All Implemented Interfaces:
    Comparable<ByteBuffer>

    public final class ByteBuffer
    extends Object
    implements Comparable<ByteBuffer>
    The ByteBuffer class provides a flexible container for handling and manipulating byte arrays. It includes methods for creating, copying, appending, overwriting, and inserting byte data, along with utility methods for encoding and decoding strings to and from byte arrays. This class is used to dynamically manage byte sequences with methods to expand or manipulate its capacity as needed.
    • Constructor Summary

      Constructors 
      Constructor Description
      ByteBuffer()
      Constructs a new ByteBuffer instance with an initial storage capacity.
      ByteBuffer​(byte[] buffer)
      Constructs a ByteBuffer object using the provided byte array.
      ByteBuffer​(byte[] buffer, int length)
      Constructs a new ByteBuffer with a specified initial data buffer and length.
      ByteBuffer​(int capacity)
      Constructs a ByteBuffer with the specified capacity.
      ByteBuffer​(ByteBuffer byteBuffer)
      Constructs a new ByteBuffer object by copying the content of the provided ByteBuffer.
      ByteBuffer​(ByteBuffer byteBuffer, int length)
      Constructs a given ByteBuffer into a new ByteBuffer with a specified length.
      ByteBuffer​(ByteBuffer buffer, int offset, int length)
      Constructs a new ByteBuffer by copying a portion of an existing buffer.
      ByteBuffer​(String str)
      Constructs a ByteBuffer object with the given string.
      ByteBuffer​(String str, Charset charset)
      Constructs a ByteBuffer object by converting the specified string into bytes using the provided character set.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      ByteBuffer append​(byte b)
      Appends a single byte to the ByteBuffer.
      ByteBuffer append​(byte[] buffer)
      Appends the specified byte array to the buffer.
      ByteBuffer append​(byte[] buffer, int length)
      Appends the specified portion of the byte array to the buffer.
      ByteBuffer append​(byte[] buffer, int offset, int length)
      Appends a portion of the given byte array to the current storage buffer.
      ByteBuffer append​(char c)
      Appends the specified character to this buffer.
      ByteBuffer append​(long value)
      Appends the string representation of a specified long value to the current ByteBuffer.
      ByteBuffer append​(ByteBuffer byteBuffer)
      Appends the contents of the provided ByteBuffer to the current buffer.
      ByteBuffer append​(ValuePtr value)
      Appends the given value to the buffer.
      ByteBuffer append​(String str)
      Appends the content of the provided string to the ByteBuffer using ISO-8859-1 encoding.
      ByteBuffer append​(String str, Charset charset)
      Appends the specified string to the buffer using the given charset for encoding.
      ByteBuffer appendBase64​(byte[] buffer)
      Appends Base64 representation of all bytes from the provided byte array.
      ByteBuffer appendBase64​(byte[] buffer, int offset, int length)
      Appends Base64 representation of a byte array range.
      ByteBuffer appendCheckSum​(int checkSum)
      Appends a checksum value to the current buffer by converting it into three bytes.
      int capacity()
      Returns the maximum capacity of the underlying storage.
      ByteBuffer clear()
      Clears the current buffer by resetting its size to zero.
      int compareTo​(ByteBuffer o)  
      ByteBuffer copy()
      Creates a new ByteBuffer that is a copy of the current ByteBuffer.
      boolean equals​(Object obj)  
      ByteBuffer erase​(int length)
      Erases a portion of the buffer by specifying the length to erase.
      ByteBuffer erase​(int length, int startPsn)
      Erases a portion of the ByteBuffer starting from the specified position and of the specified length.
      int findIndex​(int startPsn, byte[] subBuffer)
      Searches for the first occurrence of the specified sub-buffer starting from the given position.
      byte[] get()
      Retrieves the stored byte array.
      int getCheckSum()
      Computes the checksum of the elements stored in the 'storage' array.
      byte[] getCopy()
      Creates and returns a copy of the underlying storage array up to the current size.
      int hashCode()  
      ByteBuffer incLength​(int size)
      Increases the length of the current buffer by the specified size.
      ByteBuffer insert​(byte[] bytes, int pos)
      Inserts the specified byte array into a buffer at the given position.
      ByteBuffer insert​(byte[] buffer, int length, int startPsn)
      Inserts a specified range of bytes from the provided buffer into a ByteBuffer starting at the given position.
      ByteBuffer insert​(byte[] buffer, int offset, int length, int startPsn)
      Inserts a portion of the provided byte array into the internal storage at the specified position.
      ByteBuffer insert​(byte b, int pos)
      Inserts a byte at the specified position in the buffer.
      ByteBuffer insert​(byte b, int pos, int times)
      Inserts the specified byte into the buffer multiple times at the given position.
      ByteBuffer insert​(char c, int pos)
      Inserts the given character at the specified position in the ByteBuffer.
      ByteBuffer insert​(long l, int pos)
      Inserts the string representation of the specified long value at the given position.
      ByteBuffer insert​(ByteBuffer buffer, int startPsn)
      Inserts content from the given ByteBuffer into a specific position.
      ByteBuffer insert​(String s, int pos)
      Inserts the specified string into a byte buffer at the given position.
      ByteBuffer insert​(String s, int pos, Charset charset)
      Inserts the byte representation of the provided string at the specified position in the byte buffer using the given character set for encoding.
      int length()
      Returns the current size.
      ByteBuffer overwrite​(byte[] buffer, int length)
      Overwrites a portion of the buffer with the given byte array starting at a default offset of 0.
      ByteBuffer overwrite​(int startPsn, byte[] buffer, int length)
      Overwrites the content at the specified position in a ByteBuffer with the provided byte array.
      ByteBuffer overwrite​(int startPsn, byte[] buffer, int length, int offset)
      Overwrites a portion of the buffer starting at the specified position with the provided byte array.
      ByteBuffer overwrite​(ByteBuffer byteBuffer)
      Overwrites the current buffer with the contents of the provided ByteBuffer.
      ByteBuffer reserve​(int expectedCapacity)
      Reserves the specified capacity in the storage.
      ByteBuffer reserveSpace​(int space)
      Reserves additional space in the ByteBuffer.
      ByteBuffer resize​(int newSize)
      Resizes the ByteBuffer to the specified new size.
      ByteBuffer reverse()
      Reverses the order of the elements in the buffer within the specified range, starting from the beginning to the current size.
      ByteBuffer reverse​(int startIdx)
      Reverses the elements in the specified range within this byte buffer.
      ByteBuffer reverse​(int startIdx, int endIdx)
      Reverses the bytes in the specified range of the storage array.
      int size()
      Returns the current size.
      ByteBuffer subBuffer​(int offset)
      Creates a new sub-buffer starting at the specified offset and extending to the end of the current buffer.
      ByteBuffer subBuffer​(int offset, int length)
      Creates a new ByteBuffer that is a subsection of the original buffer.
      String toString()  
      ByteBuffer write​(OutputStream outputStream)
      Writes the contents of the internal storage buffer to the specified OutputStream.
    • Constructor Detail

      • ByteBuffer

        public ByteBuffer()
        Constructs a new ByteBuffer instance with an initial storage capacity.
      • ByteBuffer

        public ByteBuffer​(int capacity)
        Constructs a ByteBuffer with the specified capacity.
        Parameters:
        capacity - the initial capacity of the byte buffer. Must be non-negative.
        Throws:
        IllegalArgumentException - if the specified capacity is less than zero.
      • ByteBuffer

        public ByteBuffer​(byte[] buffer)
        Constructs a ByteBuffer object using the provided byte array.
        Parameters:
        buffer - the byte array to initialize the ByteBuffer.
      • ByteBuffer

        public ByteBuffer​(byte[] buffer,
                          int length)
        Constructs a new ByteBuffer with a specified initial data buffer and length.
        Parameters:
        buffer - The byte array containing the initial data to populate the ByteBuffer.
        length - The number of bytes from the buffer to copy into the ByteBuffer. Must be less than or equal to the size of the provided buffer.
        Throws:
        NullPointerException - if buffer is null
        IllegalArgumentException - if length is negative, exceeds buffer.length, or is too large to fit internal capacity limits
      • ByteBuffer

        public ByteBuffer​(String str,
                          Charset charset)
        Constructs a ByteBuffer object by converting the specified string into bytes using the provided character set.
        Parameters:
        str - the input string to be converted into bytes
        charset - the character set to be used for encoding the string to bytes
      • ByteBuffer

        public ByteBuffer​(String str)
        Constructs a ByteBuffer object with the given string. The string is encoded using ISO-8859-1 character set.
        Parameters:
        str - the input string to be converted into a ByteBuffer
      • ByteBuffer

        public ByteBuffer​(ByteBuffer byteBuffer)
        Constructs a new ByteBuffer object by copying the content of the provided ByteBuffer.
        Parameters:
        byteBuffer - the ByteBuffer instance to copy from
      • ByteBuffer

        public ByteBuffer​(ByteBuffer byteBuffer,
                          int length)
        Constructs a given ByteBuffer into a new ByteBuffer with a specified length.
        Parameters:
        byteBuffer - the original ByteBuffer to wrap
        length - the length of the new ByteBuffer
      • ByteBuffer

        public ByteBuffer​(ByteBuffer buffer,
                          int offset,
                          int length)
        Constructs a new ByteBuffer by copying a portion of an existing buffer.
        Parameters:
        buffer - The source ByteBuffer from which data is copied. Must not be null.
        offset - The start position in the source buffer to begin copying. Must be non-negative.
        length - The number of bytes to copy from the source buffer. Must be non-negative, and the sum of offset and length must not exceed the source buffer's length.
        Throws:
        NullPointerException - If the provided buffer is null.
        IllegalArgumentException - If the offset is negative, the length is negative, or offset plus length exceeds the source buffer's length.
    • Method Detail

      • copy

        public ByteBuffer copy()
        Creates a new ByteBuffer that is a copy of the current ByteBuffer.
        Returns:
        a new instance of ByteBuffer with the same data as the original.
      • subBuffer

        public ByteBuffer subBuffer​(int offset)
        Creates a new sub-buffer starting at the specified offset and extending to the end of the current buffer.
        Parameters:
        offset - the starting position of the sub-buffer within the current buffer.
        Returns:
        a new ByteBuffer object representing the sub-buffer starting at the given offset.
      • subBuffer

        public ByteBuffer subBuffer​(int offset,
                                    int length)
        Creates a new ByteBuffer that is a subsection of the original buffer.
        Parameters:
        offset - the starting position within the original buffer where the sub buffer begins
        length - the number of elements to include in the sub buffer
        Returns:
        a new ByteBuffer object representing the specified range of the original buffer
      • overwrite

        public ByteBuffer overwrite​(ByteBuffer byteBuffer)
        Overwrites the current buffer with the contents of the provided ByteBuffer.
        Parameters:
        byteBuffer - the ByteBuffer containing the data to overwrite with
        Returns:
        the updated ByteBuffer after the overwrite operation
        Throws:
        NullPointerException - if byteBuffer is null
      • overwrite

        public ByteBuffer overwrite​(byte[] buffer,
                                    int length)
        Overwrites a portion of the buffer with the given byte array starting at a default offset of 0.
        Parameters:
        buffer - the byte array containing the data to overwrite
        length - the number of bytes to write from the provided byte array
        Returns:
        a ByteBuffer object after the overwrite operation
      • overwrite

        public ByteBuffer overwrite​(int startPsn,
                                    byte[] buffer,
                                    int length)
        Overwrites the content at the specified position in a ByteBuffer with the provided byte array.
        Parameters:
        startPsn - the starting position in the ByteBuffer where the overwriting begins
        buffer - the byte array containing the data to be written
        length - the number of bytes to write from the provided byte array
        Returns:
        a ByteBuffer containing the updated data
      • overwrite

        public ByteBuffer overwrite​(int startPsn,
                                    byte[] buffer,
                                    int length,
                                    int offset)
        Overwrites a portion of the buffer starting at the specified position with the provided byte array. The operation adjusts the buffer size if needed.
        Parameters:
        startPsn - the start position in the buffer where data will be written
        buffer - the byte array containing data to write
        length - the length of the data in the byte array to be written
        offset - the starting offset in the buffer from where data will be written
        Returns:
        the updated buffer after the overwrite operation
        Throws:
        IllegalArgumentException - if startPsn is negative, startPsn is greater than or equal to the current size, length is negative or greater than buffer.length, offset is outside [0, length], or the resulting size overflows int range
        NullPointerException - if the buffer is null
      • append

        public ByteBuffer append​(ByteBuffer byteBuffer)
        Appends the contents of the provided ByteBuffer to the current buffer.
        Parameters:
        byteBuffer - the ByteBuffer whose data will be appended
        Returns:
        the updated ByteBuffer after appending the data
      • append

        public ByteBuffer append​(char c)
        Appends the specified character to this buffer.
        Parameters:
        c - the character to be appended, represented as a char.
        Returns:
        this buffer after the character has been appended.
      • append

        public ByteBuffer append​(byte b)
        Appends a single byte to the ByteBuffer.
        Parameters:
        b - the byte to be appended to the ByteBuffer
        Returns:
        the updated ByteBuffer instance with the new byte added
      • append

        public ByteBuffer append​(byte[] buffer)
        Appends the specified byte array to the buffer.
        Parameters:
        buffer - the byte array to append
        Returns:
        the updated ByteBuffer with the appended data
      • append

        public ByteBuffer append​(String str)
        Appends the content of the provided string to the ByteBuffer using ISO-8859-1 encoding.
        Parameters:
        str - the string whose content is to be appended
        Returns:
        the ByteBuffer instance with the appended content
      • append

        public ByteBuffer append​(String str,
                                 Charset charset)
        Appends the specified string to the buffer using the given charset for encoding.
        Parameters:
        str - the string to append to the buffer
        charset - the charset to be used for encoding the string
        Returns:
        the updated ByteBuffer after appending the encoded string
      • append

        public ByteBuffer append​(ValuePtr value)
        Appends the given value to the buffer. The value must be properly set and not null, otherwise a NullPointerException or IllegalArgumentException will be thrown.
        Parameters:
        value - the ValuePtr object containing the data to append. Must not be null and must be set.
        Returns:
        the ByteBuffer after appending the value.
        Throws:
        NullPointerException - if the value is null.
        IllegalArgumentException - if the value is not set.
      • append

        public ByteBuffer append​(byte[] buffer,
                                 int length)
        Appends the specified portion of the byte array to the buffer.
        Parameters:
        buffer - the byte array containing the data to be appended
        length - the number of bytes to append from the beginning of the array
        Returns:
        the modified ByteBuffer after appending the specified bytes
      • append

        public ByteBuffer append​(byte[] buffer,
                                 int offset,
                                 int length)
        Appends a portion of the given byte array to the current storage buffer.
        Parameters:
        buffer - the byte array containing the data to append
        offset - the starting position in the byte array to begin appending from
        length - the number of bytes to append from the byte array
        Returns:
        the updated ByteBuffer instance with the appended data
        Throws:
        NullPointerException - if buffer is null
        IllegalArgumentException - if offset or length is negative, if offset + length exceeds buffer.length, or if resulting buffer size overflows int range
      • appendBase64

        public ByteBuffer appendBase64​(byte[] buffer)
        Appends Base64 representation of all bytes from the provided byte array.
        Parameters:
        buffer - the source byte array
        Returns:
        the updated ByteBuffer after appending Base64 content
      • appendBase64

        public ByteBuffer appendBase64​(byte[] buffer,
                                       int offset,
                                       int length)
        Appends Base64 representation of a byte array range.
        Parameters:
        buffer - the source byte array
        offset - the start position in the source byte array
        length - number of source bytes to encode
        Returns:
        the updated ByteBuffer after appending Base64 content
        Throws:
        NullPointerException - if buffer is null
        IllegalArgumentException - if offset or length is negative, if offset + length exceeds buffer.length, or if encoded/resulting size overflows int range
      • append

        public ByteBuffer append​(long value)
        Appends the string representation of a specified long value to the current ByteBuffer.
        Parameters:
        value - the long value to be appended
        Returns:
        the updated ByteBuffer instance
      • appendCheckSum

        public ByteBuffer appendCheckSum​(int checkSum)
        Appends a checksum value to the current buffer by converting it into three bytes. Each digit of the checksum is stored as its ASCII character representation.
        Parameters:
        checkSum - the checksum value to append, represented as an integer
        Returns:
        the updated ByteBuffer instance with the checksum appended
      • insert

        public ByteBuffer insert​(ByteBuffer buffer,
                                 int startPsn)
        Inserts content from the given ByteBuffer into a specific position.
        Parameters:
        buffer - the ByteBuffer containing the data to be inserted; must not be null
        startPsn - the starting position where the content is to be inserted
        Returns:
        a ByteBuffer representing the modified state after insertion
        Throws:
        NullPointerException - if the provided buffer is null
      • insert

        public ByteBuffer insert​(char c,
                                 int pos)
        Inserts the given character at the specified position in the ByteBuffer.
        Parameters:
        c - the character to be inserted, provided as a char
        pos - the position at which the character should be inserted
        Returns:
        the updated ByteBuffer after the character has been inserted
      • insert

        public ByteBuffer insert​(byte b,
                                 int pos)
        Inserts a byte at the specified position in the buffer.
        Parameters:
        b - the byte to insert
        pos - the position at which the byte should be inserted
        Returns:
        the current buffer after the byte has been inserted
        Throws:
        IllegalArgumentException - if pos is negative or greater than current size
      • insert

        public ByteBuffer insert​(byte b,
                                 int pos,
                                 int times)
        Inserts the specified byte into the buffer multiple times at the given position.
        Parameters:
        b - the byte value to insert
        pos - the position in the buffer where the byte is to be inserted
        times - the number of times the byte should be inserted
        Returns:
        the updated ByteBuffer instance with the new bytes inserted
        Throws:
        IllegalArgumentException - if times is negative, if pos is outside [0, size], or if resulting size overflows int range
      • insert

        public ByteBuffer insert​(long l,
                                 int pos)
        Inserts the string representation of the specified long value at the given position.
        Parameters:
        l - the long value to be converted to a string and inserted
        pos - the position at which the string representation of the long value is to be inserted
        Returns:
        a ByteBuffer after inserting the string representation of the specified long value
      • insert

        public ByteBuffer insert​(String s,
                                 int pos,
                                 Charset charset)
        Inserts the byte representation of the provided string at the specified position in the byte buffer using the given character set for encoding.
        Parameters:
        s - the string to insert
        pos - the position in the byte buffer where the string's bytes will be inserted
        charset - the charset used to encode the string into bytes
        Returns:
        a ByteBuffer containing the updated buffer after the insertion
      • insert

        public ByteBuffer insert​(String s,
                                 int pos)
        Inserts the specified string into a byte buffer at the given position.
        Parameters:
        s - the string to be inserted, which will be converted to bytes using ISO_8859_1 encoding
        pos - the position at which the string's bytes should be inserted in the byte buffer
        Returns:
        a ByteBuffer containing the updated content after the insertion
      • insert

        public ByteBuffer insert​(byte[] bytes,
                                 int pos)
        Inserts the specified byte array into a buffer at the given position.
        Parameters:
        bytes - the byte array to be inserted
        pos - the position at which the byte array should be inserted
        Returns:
        a ByteBuffer containing the modified buffer with the inserted byte array
      • insert

        public ByteBuffer insert​(byte[] buffer,
                                 int length,
                                 int startPsn)
        Inserts a specified range of bytes from the provided buffer into a ByteBuffer starting at the given position.
        Parameters:
        buffer - the byte array containing the data to be inserted
        length - the number of bytes to insert from the buffer
        startPsn - the starting position in the ByteBuffer where the insertion will occur
        Returns:
        the resulting ByteBuffer after the insertion
      • insert

        public ByteBuffer insert​(byte[] buffer,
                                 int offset,
                                 int length,
                                 int startPsn)
        Inserts a portion of the provided byte array into the internal storage at the specified position.
        Parameters:
        buffer - the byte array containing the data to be inserted
        offset - the starting position in the byte array from which data should be read
        length - the number of bytes to be inserted from the byte array
        startPsn - the position in the internal storage where the data should be inserted
        Returns:
        a ByteBuffer instance after the insertion operation
        Throws:
        NullPointerException - if buffer is null
        IllegalArgumentException - if startPsn is outside [0, size], if offset or length is negative, if offset + length exceeds buffer.length, or if resulting size overflows int range
      • capacity

        public int capacity()
        Returns the maximum capacity of the underlying storage.
        Returns:
        the total number of elements that can be stored.
      • clear

        public ByteBuffer clear()
        Clears the current buffer by resetting its size to zero. Allows the buffer to be reused for new data.
        Returns:
        The current ByteBuffer instance after being cleared.
      • erase

        public ByteBuffer erase​(int length)
        Erases a portion of the buffer by specifying the length to erase. This method delegates to another erase method with a default offset of 0.
        Parameters:
        length - the number of bytes to erase from the buffer
        Returns:
        a ByteBuffer instance after the specified portion has been erased
      • erase

        public ByteBuffer erase​(int length,
                                int startPsn)
        Erases a portion of the ByteBuffer starting from the specified position and of the specified length. The content after the erased portion is shifted accordingly to fill the gap.
        Parameters:
        length - the number of bytes to be erased from the buffer
        startPsn - the starting position in the buffer from where the erasing begins
        Returns:
        the modified ByteBuffer after the specified range has been erased
        Throws:
        IllegalArgumentException - if length is negative, if startPsn is outside [0, size], or if length exceeds available data from startPsn
      • get

        public byte[] get()
        Retrieves the stored byte array.
        Returns:
        a byte array representing the stored data.
      • getCopy

        public byte[] getCopy()
        Creates and returns a copy of the underlying storage array up to the current size.
        Returns:
        a new byte array containing the copied elements from the storage array
      • getCheckSum

        public int getCheckSum()
        Computes the checksum of the elements stored in the 'storage' array. The checksum is calculated as the sum of the unsigned byte values of all elements in the array, modulo 256.
        Returns:
        the checksum value as an integer in the range 0 to 255
      • reserveSpace

        public ByteBuffer reserveSpace​(int space)
        Reserves additional space in the ByteBuffer.
        Parameters:
        space - the amount of additional space to reserve in the ByteBuffer
        Returns:
        a ByteBuffer instance with the updated reserved space
        Throws:
        IllegalArgumentException - if space is negative or if resulting size overflows int range
      • reserve

        public ByteBuffer reserve​(int expectedCapacity)
        Reserves the specified capacity in the storage.
        Parameters:
        expectedCapacity - the desired capacity to be reserved in the storage
        Returns:
        the updated ByteBuffer instance with the adjusted storage capacity
        Throws:
        IllegalArgumentException - if expectedCapacity is negative or exceeds internal growth limits
      • size

        public int size()
        Returns the current size.
        Returns:
        the number of elements or the current size as an integer
      • length

        public int length()
        Returns the current size.
        Returns:
        the number of elements or the current size as an integer
      • resize

        public ByteBuffer resize​(int newSize)
        Resizes the ByteBuffer to the specified new size. Allocates additional space if required.
        Parameters:
        newSize - the new size to which the ByteBuffer should be resized
        Returns:
        the current instance of ByteBuffer after resizing
        Throws:
        IllegalArgumentException - if newSize is negative
      • incLength

        public ByteBuffer incLength​(int size)
        Increases the length of the current buffer by the specified size. Updates the internal size and ensures sufficient capacity by reserving space if necessary.
        Parameters:
        size - the amount by which to increase the length; must be non-negative
        Returns:
        the updated ByteBuffer instance
        Throws:
        IllegalArgumentException - if size is negative or if resulting length overflows int range
      • reverse

        public ByteBuffer reverse()
        Reverses the order of the elements in the buffer within the specified range, starting from the beginning to the current size.
        Returns:
        a ByteBuffer object with the elements reversed in the specified range
      • reverse

        public ByteBuffer reverse​(int startIdx)
        Reverses the elements in the specified range within this byte buffer.
        Parameters:
        startIdx - the starting index of the range to reverse, inclusive.
        Returns:
        a ByteBuffer with the elements in the specified range reversed.
      • reverse

        public ByteBuffer reverse​(int startIdx,
                                  int endIdx)
        Reverses the bytes in the specified range of the storage array.
        Parameters:
        startIdx - the starting index of the range to reverse (inclusive)
        endIdx - the ending index of the range to reverse (inclusive)
        Returns:
        the current ByteBuffer instance with the specified range reversed
      • findIndex

        public int findIndex​(int startPsn,
                             byte[] subBuffer)
        Searches for the first occurrence of the specified sub-buffer starting from the given position.
        Parameters:
        startPsn - the starting position in the buffer from which the search begins. Must be non-negative.
        subBuffer - the byte array to search for within the buffer. Must not be null or empty.
        Returns:
        the index of the first occurrence of the specified sub-buffer, or -1 if the sub-buffer is not found or if the sub-buffer's length exceeds the size of the buffer.
        Throws:
        IllegalArgumentException - if the starting position is negative or the sub-buffer is empty
        NullPointerException - if the sub-buffer is null.
      • write

        public ByteBuffer write​(OutputStream outputStream)
                         throws IOException
        Writes the contents of the internal storage buffer to the specified OutputStream.
        Parameters:
        outputStream - the OutputStream to which the data will be written
        Returns:
        the current ByteBuffer instance after writing the data
        Throws:
        IOException - if an I/O error occurs during writing
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object