Package 

Class ByteArray

  • All Implemented Interfaces:
    java.io.Serializable , java.lang.Cloneable

    
    public class ByteArray
     implements Serializable, Cloneable
                        

    The ByteArray class provides a flexible and efficient way of managing and manipulating byte arrays. It includes various constructors, methods for appending, prepending, copying, and resetting byte data, and functionalities for equality checks, hashing, and string representation. This class supports both read-only and writable modes and ensures proper handling of capacity and bounds.

    • Constructor Summary

      Constructors 
      Constructor Description
      ByteArray(Array<byte> p_arr, int p_offset, int p_length) Constructs a ByteArray object with the specified byte array, offset, and length.
      ByteArray(Array<byte> p_arr) Constructs a ByteArray object with the specified byte array.Initializes the byte array, offset, length, and read-only state based on the input.
      ByteArray(int capacity) Constructs a ByteArray with the specified initial capacity.
      ByteArray() Default constructor for creating a ByteArray with the default capacity.It initializes the internal byte array to the predefined default size.
      ByteArray(String str) Constructor that initializes the ByteArray object using the given string.
      ByteArray(ByteArray b) Constructs a new ByteArray object by copying the contents of the specified ByteArray.
    • Method Summary

      Modifier and Type Method Description
      int getLength() Retrieves the length value.
      ByteArray copy(ByteArray b) Creates a copy of the given ByteArray and appends its contents to the current ByteArray.
      ByteArray copy(Array<byte> b) Creates a copy of the provided byte array, resets the offset and length to zero,and sets the object to be writable.
      ByteArray copy(Array<byte> b, int offset, int len) Copies a specified portion of the given byte array into a ByteArray object.
      void reset() Resets the state of the object to its initial values.This method sets the `offset` and `length` to 0, fills the array with zero bytes,and sets the `readOnly` flag to false.
      synchronized int hashCode() Computes a hash code for the object based on its internal state.The method ensures thread-safety through synchronization and usesa buffer to calculate the hash code value iteratively over an array.
      boolean equals(Object obj) Compares this ByteArray object to the specified object for equality.
      String toString() Returns a string representation of the specified portion of the array.
      ByteArray append(Array<byte> a) Appends the given byte array to the current ByteArray instance.
      ByteArray appendIPAddress(Array<byte> a) Appends an IP address represented as a byte array to the underlying data structure.Each byte in the array is interpreted as a segment of the IP address, separated by dots.
      ByteArray append(Array<byte> a, int p_offset, int p_length) Appends a portion of the given byte array to the current ByteArray object.
      ByteArray append(ByteArray p) Appends the specified ByteArray to the current ByteArray instance.
      ByteArray append(char a) Appends a single character to the current ByteArray instance.
      ByteArray append(char a, char b) Appends two characters to the current ByteArray instance.Converts the provided characters to bytes and stores them sequentiallyin the underlying byte array.
      ByteArray append(char a, char b, char c) Appends three characters to the current ByteArray.The characters provided are cast to bytes and added sequentiallyat the end of the current ByteArray.
      ByteArray append(char a, char b, char c, char d) Appends four characters to the ByteArray.
      ByteArray append(int n) Appends the byte representation of the provided integer to the current byte array.
      ByteArray append(long n) Appends the string representation of the specified long valueto the current ByteArray.
      boolean isEmpty() Checks if the collection or data structure is empty.
      Array<byte> getBytes() Copies a portion of the source array into a new byte array and returns it.
      ByteArray prepend(ByteArray b) Prepends the content of the specified ByteArray to this ByteArray.
      ByteArray prepend(Array<byte> inputData, int inputOffset, int inputLen) Prepends a specified portion of the given byte array to the beginning of the current ByteArray.
      ByteArray appendByte(int i) Appends a single byte, represented as an integer, to the current ByteArray.
      ByteArray appendByte(long l) Appends a byte represented by the specified long value to the current ByteArray.
      ByteArray append(String string) Appends the byte representation of the given string to the ByteArray.
      byte endCharacter() Retrieves the last character in the byte array based on the current offset and length.
      byte startCharacter() Retrieves the starting character from the byte array at a specific offset.
      ByteArray readOnlyCopy() Creates a read-only copy of the current ByteArray instance.
      ByteArray increment() Increments the offset by one and decrements the length by one.
      byte getCharacterAt(int index) Retrieves the byte value of a character at the specified index in the internal byte array.
      ByteArray append(ByteArray b, int length) Appends a portion of the given ByteArray to the current ByteArray.
      boolean getStrUptoSlashR(String searchStr, ByteArray buffer, int maxLength) Extracts a string up to the occurrence of a carriage return character ('\r')from the specified input string and stores it in the provided buffer.
      boolean getStrUptoSlashR(ByteArray searchStr, ByteArray buffer, int maxLength) Extracts a substring from the given search string up to the occurrence of a carriage return ('\r') or until the specified maximum length.
      boolean getStrUptoSpace(ByteArray searchStr, ByteArray buffer, int maxLength) Extracts a substring from the current instance of a ByteArray until a spaceor carriage return is encountered, or until the specified maximum length is reached.
      boolean getStrValueUptoSlashR(String searchStr, ByteArray buffer, int maxLength) Retrieves a value from the buffer up to the occurrence of a '\r' or maxLength in the given search string,with a restriction on the maximum length of the value extracted.
      boolean getStrValueUptoSlashR(ByteArray searchStr, ByteArray buffer, int maxLength) Searches for a specific string within a byte array and extracts characters up to a carriage return ('\r')or newline ('\n'), appending them to a buffer.
      boolean getStrValueUptoSlashRFromBalance(ByteArray searchStr, ByteArray buffer, int maxLength) Searches for the specified byte array within the object's buffer, retrievesvalues up to the first occurrence of a carriage return ('\r'), and appendsthem to a provided buffer.
      int iTelStrstr(String searchStr) Searches for the first occurrence of a substring within a byte arraycreated from the given string.
      int iTelStrstr(ByteArray searchStr) Searches for the first occurrence of a substring within the current byte array,ignoring case differences in ASCII characters.
      boolean startsWith(String startStr) Checks if the current byte array starts with the specified string.This method internally converts the string to its corresponding byte arrayand then performs the comparison.
      boolean startsWith(Array<byte> startStr) Checks if the current byte array starts with the specified byte arrayprefix.
      void forward(int length) Advances the internal offset of the byte array by the specified length and reducesthe available length accordingly.
      void dropBytes(int index, int length) Removes a specified number of bytes from the byte array, starting at the given index.This shifts all subsequent bytes to fill the removed space and adjusts the length of the array.
      byte charAt(int i) Returns the byte value at the specified index in the byte array.The index is computed relative to the internal offset and must bewithin the bounds of the array length.
      int toInteger() Converts a sequence of numeric characters within the underlying byte array (`arr`)to an integer.
      int toIntegerWhenValueIsInteger() Converts the first two bytes of the underlying byte array (`arr`) into an integer.The method interprets the first byte (`arr[0]`) as the higher-order byteand the second byte (`arr[1]`) as the lower-order byte, combining them using bitwise operations.
      boolean getStrValueUptoSpace(String searchStr, ByteArray buffer, int maxLength) Searches for a specified substring within the given string and extractsa sequence of characters from the underlying data buffer starting after theoccurrence of the specified substring.
      boolean getStrValueUptoSpace(ByteArray searchStr, ByteArray buffer, int maxLength) Searches for a specified substring within the current ByteArray and extractsa sequence of characters from the underlying byte array starting after theoccurrence of the specified substring.
      Object clone() Creates and returns a copy of this object.The method performs a shallow copy of the current objectby invoking the `clone` method from the `Object` class.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ByteArray

        ByteArray(Array<byte> p_arr, int p_offset, int p_length)
        Constructs a ByteArray object with the specified byte array, offset, and length.
        Parameters:
        p_arr - the byte array from which data will be used
        p_offset - the starting offset within the byte array
        p_length - the number of bytes to include from the specified offset
      • ByteArray

        ByteArray(Array<byte> p_arr)
        Constructs a ByteArray object with the specified byte array.Initializes the byte array, offset, length, and read-only state based on the input.
        Parameters:
        p_arr - the byte array to initialize the ByteArray object with.If null, a default capacity array will be created, and the object will be writable.If non-null, the object will be initialized with the given array and set to read-only.
      • ByteArray

        ByteArray(int capacity)
        Constructs a ByteArray with the specified initial capacity.
        Parameters:
        capacity - the initial size of the byte array to be created
      • ByteArray

        ByteArray()
        Default constructor for creating a ByteArray with the default capacity.It initializes the internal byte array to the predefined default size.
      • ByteArray

        ByteArray(String str)
        Constructor that initializes the ByteArray object using the given string.
        Parameters:
        str - the input string to be converted into a byte array
      • ByteArray

        ByteArray(ByteArray b)
        Constructs a new ByteArray object by copying the contents of the specified ByteArray.
        Parameters:
        b - the ByteArray to be copied
    • Method Detail

      • getLength

         int getLength()

        Retrieves the length value.

      • copy

         ByteArray copy(ByteArray b)

        Creates a copy of the given ByteArray and appends its contents to the current ByteArray.

        Parameters:
        b - the ByteArray to be copied and appended
      • copy

         ByteArray copy(Array<byte> b)

        Creates a copy of the provided byte array, resets the offset and length to zero,and sets the object to be writable. The byte array is appended to the current data.

        Parameters:
        b - The byte array to copy and append.
      • copy

         ByteArray copy(Array<byte> b, int offset, int len)

        Copies a specified portion of the given byte array into a ByteArray object.

        Parameters:
        b - the byte array to be copied from
        offset - the starting position in the array to begin copying
        len - the number of bytes to copy from the array
      • reset

         void reset()

        Resets the state of the object to its initial values.This method sets the `offset` and `length` to 0, fills the array with zero bytes,and sets the `readOnly` flag to false. Use this method to clear the current stateand prepare the object for reuse.

      • hashCode

         synchronized int hashCode()

        Computes a hash code for the object based on its internal state.The method ensures thread-safety through synchronization and usesa buffer to calculate the hash code value iteratively over an array.

      • equals

         boolean equals(Object obj)

        Compares this ByteArray object to the specified object for equality.

        Parameters:
        obj - the object to be compared for equality with this ByteArray
      • toString

        @NotNull() String toString()

        Returns a string representation of the specified portion of the array.

      • append

         ByteArray append(Array<byte> a)

        Appends the given byte array to the current ByteArray instance.

        Parameters:
        a - the byte array to append; if null, the method performs no operation
      • appendIPAddress

         ByteArray appendIPAddress(Array<byte> a)

        Appends an IP address represented as a byte array to the underlying data structure.Each byte in the array is interpreted as a segment of the IP address, separated by dots.

        Parameters:
        a - the byte array representing the IP address; each byte corresponds to a segment of the address
      • append

         ByteArray append(Array<byte> a, int p_offset, int p_length)

        Appends a portion of the given byte array to the current ByteArray object.

        Parameters:
        a - the byte array to append from
        p_offset - the starting offset in the given byte array
        p_length - the number of bytes to append
      • append

         ByteArray append(ByteArray p)

        Appends the specified ByteArray to the current ByteArray instance.

        Parameters:
        p - the ByteArray to append to the current instance; can be null
      • append

         ByteArray append(char a)

        Appends a single character to the current ByteArray instance.

        Parameters:
        a - the character to append
      • append

         ByteArray append(char a, char b)

        Appends two characters to the current ByteArray instance.Converts the provided characters to bytes and stores them sequentiallyin the underlying byte array.

        Parameters:
        a - the first character to append
        b - the second character to append
      • append

         ByteArray append(char a, char b, char c)

        Appends three characters to the current ByteArray.The characters provided are cast to bytes and added sequentiallyat the end of the current ByteArray. The method verifies if thearray has sufficient capacity for the new bytes and if modificationsare allowed. Throws an exception if any of these conditions are not met.

        Parameters:
        a - the first character to append
        b - the second character to append
        c - the third character to append
      • append

         ByteArray append(char a, char b, char c, char d)

        Appends four characters to the ByteArray. The characters are cast to bytesand stored in sequence within the internal byte array.

        Parameters:
        a - the first character to append, cast to a byte before storing
        b - the second character to append, cast to a byte before storing
        c - the third character to append, cast to a byte before storing
        d - the fourth character to append, cast to a byte before storing
      • append

         ByteArray append(int n)

        Appends the byte representation of the provided integer to the current byte array.

        Parameters:
        n - the integer value to be converted to bytes and appended
      • append

         ByteArray append(long n)

        Appends the string representation of the specified long valueto the current ByteArray.

        Parameters:
        n - the long value to be converted to a string and appended
      • isEmpty

         boolean isEmpty()

        Checks if the collection or data structure is empty.

      • getBytes

         Array<byte> getBytes()

        Copies a portion of the source array into a new byte array and returns it.

      • prepend

         ByteArray prepend(ByteArray b)

        Prepends the content of the specified ByteArray to this ByteArray.

        Parameters:
        b - the ByteArray to be prepended to this ByteArray.
      • prepend

         ByteArray prepend(Array<byte> inputData, int inputOffset, int inputLen)

        Prepends a specified portion of the given byte array to the beginning of the current ByteArray.

        Parameters:
        inputData - The byte array containing the data to prepend.
        inputOffset - The starting offset in the inputData array from where the data should be read.
        inputLen - The number of bytes to read from the inputData array starting at inputOffset.
      • appendByte

         ByteArray appendByte(int i)

        Appends a single byte, represented as an integer, to the current ByteArray.

        Parameters:
        i - the byte value to be appended, represented as an integer (0-255)
      • appendByte

         ByteArray appendByte(long l)

        Appends a byte represented by the specified long value to the current ByteArray.

        Parameters:
        l - the long value whose lower 8 bits are to be appended as a byte
      • append

         ByteArray append(String string)

        Appends the byte representation of the given string to the ByteArray.

        Parameters:
        string - the string to be converted to bytes and appended; if null, an empty byte array is appended
      • endCharacter

         byte endCharacter()

        Retrieves the last character in the byte array based on the current offset and length.

      • startCharacter

         byte startCharacter()

        Retrieves the starting character from the byte array at a specific offset.

      • increment

         ByteArray increment()

        Increments the offset by one and decrements the length by one.

      • getCharacterAt

         byte getCharacterAt(int index)

        Retrieves the byte value of a character at the specified index in the internal byte array.

        Parameters:
        index - the position in the array to retrieve the character from, where 0 is the starting index.
      • append

         ByteArray append(ByteArray b, int length)

        Appends a portion of the given ByteArray to the current ByteArray.

        Parameters:
        b - the ByteArray to append to the current ByteArray
        length - the number of bytes to append; if negative, the full length of the given ByteArray is appended
      • getStrUptoSlashR

         boolean getStrUptoSlashR(String searchStr, ByteArray buffer, int maxLength)

        Extracts a string up to the occurrence of a carriage return character ('\r')from the specified input string and stores it in the provided buffer.

        Parameters:
        searchStr - the input string to search for a carriage return character
        buffer - the buffer where the extracted string will be stored
        maxLength - the maximum number of characters to extract and store in the buffer
      • getStrUptoSlashR

         boolean getStrUptoSlashR(ByteArray searchStr, ByteArray buffer, int maxLength)

        Extracts a substring from the given search string up to the occurrence of a carriage return ('\r') or until the specified maximum length.

        Parameters:
        searchStr - The string in which to search for the substring.
        buffer - The buffer to store the extracted substring.
        maxLength - The maximum length to extract, regardless of whether a carriage return is found.
      • getStrUptoSpace

         boolean getStrUptoSpace(ByteArray searchStr, ByteArray buffer, int maxLength)

        Extracts a substring from the current instance of a ByteArray until a spaceor carriage return is encountered, or until the specified maximum length is reached.

        Parameters:
        searchStr - the ByteArray representing the substring to search for.
        buffer - the ByteArray to store the extracted substring.
        maxLength - the maximum number of characters to extract from the substring.
      • getStrValueUptoSlashR

         boolean getStrValueUptoSlashR(String searchStr, ByteArray buffer, int maxLength)

        Retrieves a value from the buffer up to the occurrence of a '\r' or maxLength in the given search string,with a restriction on the maximum length of the value extracted. This method delegates the operation toanother overloaded method using a ByteArray representation of the search string.

        Parameters:
        searchStr - the string to search for within the buffer
        buffer - the ByteArray buffer from which the value will be extracted
        maxLength - the maximum allowed length of the string value to be retrieved
      • getStrValueUptoSlashR

         boolean getStrValueUptoSlashR(ByteArray searchStr, ByteArray buffer, int maxLength)

        Searches for a specific string within a byte array and extracts characters up to a carriage return ('\r')or newline ('\n'), appending them to a buffer. If the target string is not found, the buffer is cleared.

        Parameters:
        searchStr - The target string to search for within the byte array.
        buffer - The buffer to store the extracted characters up to a carriage return or newline.
        maxLength - The maximum length of characters to extract and append to the buffer.
      • getStrValueUptoSlashRFromBalance

         boolean getStrValueUptoSlashRFromBalance(ByteArray searchStr, ByteArray buffer, int maxLength)

        Searches for the specified byte array within the object's buffer, retrievesvalues up to the first occurrence of a carriage return ('\r'), and appendsthem to a provided buffer. The method stops at either the maximum specifiedlength or a carriage return, whichever occurs first.

        Parameters:
        searchStr - The ByteArray to search for within the object's buffer.
        buffer - The ByteArray where the retrieved values will be appended.
        maxLength - The maximum number of bytes to read and append to the buffer.
      • iTelStrstr

         int iTelStrstr(String searchStr)

        Searches for the first occurrence of a substring within a byte arraycreated from the given string.

        Parameters:
        searchStr - the string to search for within the current byte array.This string is converted into a ByteArray internally.
      • iTelStrstr

         int iTelStrstr(ByteArray searchStr)

        Searches for the first occurrence of a substring within the current byte array,ignoring case differences in ASCII characters.

        Parameters:
        searchStr - the ByteArray to search for within the current byte array.
      • startsWith

         boolean startsWith(String startStr)

        Checks if the current byte array starts with the specified string.This method internally converts the string to its corresponding byte arrayand then performs the comparison.

        Parameters:
        startStr - the string to check as the prefix of the current byte array.
      • startsWith

         boolean startsWith(Array<byte> startStr)

        Checks if the current byte array starts with the specified byte arrayprefix. The comparison is case-insensitive for characters withinthe ASCII range.

        Parameters:
        startStr - the byte array to check as the prefix of the currentbyte array.
      • forward

         void forward(int length)

        Advances the internal offset of the byte array by the specified length and reducesthe available length accordingly. This is typically used to skip over a portionof the byte array.

        Parameters:
        length - the number of bytes to advance the offset by.
      • dropBytes

         void dropBytes(int index, int length)

        Removes a specified number of bytes from the byte array, starting at the given index.This shifts all subsequent bytes to fill the removed space and adjusts the length of the array.

        Parameters:
        index - the starting position from which bytes are to be removed.
        length - the number of bytes to be removed.
      • charAt

         byte charAt(int i)

        Returns the byte value at the specified index in the byte array.The index is computed relative to the internal offset and must bewithin the bounds of the array length.

        Parameters:
        i - the index of the byte to be returned, relative to the offset.
      • toInteger

         int toInteger()

        Converts a sequence of numeric characters within the underlying byte array (`arr`)to an integer. The conversion begins at the specified `offset` and continuesup to the `length` of the array or until a non-numeric character (e.g., '\r') is encountered.Non-numeric characters are ignored, and the method processes only valid digit characters ('0' to '9').

      • toIntegerWhenValueIsInteger

         int toIntegerWhenValueIsInteger()

        Converts the first two bytes of the underlying byte array (`arr`) into an integer.The method interprets the first byte (`arr[0]`) as the higher-order byteand the second byte (`arr[1]`) as the lower-order byte, combining them using bitwise operations.

      • getStrValueUptoSpace

         boolean getStrValueUptoSpace(String searchStr, ByteArray buffer, int maxLength)

        Searches for a specified substring within the given string and extractsa sequence of characters from the underlying data buffer starting after theoccurrence of the specified substring. The characters are appended to theprovided buffer until a space, carriage return, newline, or the maximumlength is reached.

        Parameters:
        searchStr - the string to search for within the current byte array.
        buffer - the ByteArray to which the extracted sequence of characters willbe appended.
        maxLength - the maximum number of characters to extract and append intothe buffer.
      • getStrValueUptoSpace

         boolean getStrValueUptoSpace(ByteArray searchStr, ByteArray buffer, int maxLength)

        Searches for a specified substring within the current ByteArray and extractsa sequence of characters from the underlying byte array starting after theoccurrence of the specified substring. The characters are appended to theprovided buffer until a space, carriage return, newline, or the maximumlength is reached.

        Parameters:
        searchStr - the ByteArray to search for within the current ByteArray.
        buffer - the ByteArray to which the extracted sequence of characters willbe appended.
        maxLength - the maximum number of characters to extract and append intothe buffer.
      • clone

        @NotNull() Object clone()

        Creates and returns a copy of this object.The method performs a shallow copy of the current objectby invoking the `clone` method from the `Object` class.