Class ByteUtils


  • public class ByteUtils
    extends Object
    Byte utilities
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean equals​(byte[] source, byte[] match)
      Does the source array equal the match array?
      static void getBytes​(byte[] source, int srcBegin, int srcEnd, byte[] destination, int dstBegin)
      Copies bytes from the source byte array to the destination array
      static int indexOf​(byte[] source, byte[] match)
      Returns the index in the source array where the first occurrence of the specified byte pattern is found
      static int indexOf​(byte[] source, String matchString)
      Returns the index in the source array where the first occurrence of the specified text (a String, converted to a byte array) is found
      static int lastIndexOf​(byte[] source, byte[] match)
      Returns the index in the source array where the last occurrence of the specified byte pattern is found
      static int lastIndexOf​(byte[] source, String matchString)
      Returns the index in the source array where the last occurrence of the specified text (a String, converted to a byte array) is found
      static void main​(String[] args)  
      static boolean startsWith​(byte[] source, byte[] match)
      Does this byte array begin with match array content?
      static boolean startsWith​(byte[] source, int offset, byte[] match)
      Does this byte array begin with match array content?
      static byte[] subbytes​(byte[] source, int srcBegin)
      Return a new byte array containing a sub-portion of the source array
      static byte[] subbytes​(byte[] source, int srcBegin, int srcEnd)
      Return a new byte array containing a sub-portion of the source array
    • Method Detail

      • indexOf

        public static int indexOf​(byte[] source,
                                  String matchString)
        Returns the index in the source array where the first occurrence of the specified text (a String, converted to a byte array) is found
        Parameters:
        source - Byte array to examine
        matchString - String to locate in source
        Returns:
        Index of the first matching character (-1 if no match)
      • indexOf

        public static int indexOf​(byte[] source,
                                  byte[] match)
        Returns the index in the source array where the first occurrence of the specified byte pattern is found
        Parameters:
        source - Byte array to examine
        match - Byte array to locate in source
        Returns:
        Index of the first matching character (-1 if no match)
      • lastIndexOf

        public static int lastIndexOf​(byte[] source,
                                      String matchString)
        Returns the index in the source array where the last occurrence of the specified text (a String, converted to a byte array) is found
        Parameters:
        source - Byte array to examine
        matchString - String to locate in source
        Returns:
        Index of the first matching character (-1 if no match)
      • lastIndexOf

        public static int lastIndexOf​(byte[] source,
                                      byte[] match)
        Returns the index in the source array where the last occurrence of the specified byte pattern is found
        Parameters:
        source - Byte array to examine
        match - Byte array to locate in source
        Returns:
        Index of the last matching character (-1 if no match)
      • startsWith

        public static boolean startsWith​(byte[] source,
                                         byte[] match)
        Does this byte array begin with match array content?
        Parameters:
        source - Byte array to examine
        match - Byte array to locate in source
        Returns:
        true If the starting bytes are equal
      • startsWith

        public static boolean startsWith​(byte[] source,
                                         int offset,
                                         byte[] match)
        Does this byte array begin with match array content?
        Parameters:
        source - Byte array to examine
        offset - An offset into the source array
        match - Byte array to locate in source
        Returns:
        true If the starting bytes are equal
      • equals

        public static boolean equals​(byte[] source,
                                     byte[] match)
        Does the source array equal the match array?
        Parameters:
        source - Byte array to examine
        offset - An offset into the source array
        match - Byte array to locate in source
        Returns:
        true If the two arrays are equal
      • getBytes

        public static void getBytes​(byte[] source,
                                    int srcBegin,
                                    int srcEnd,
                                    byte[] destination,
                                    int dstBegin)
        Copies bytes from the source byte array to the destination array
        Parameters:
        source - The source array
        srcBegin - Index of the first source byte to copy
        srcEnd - Index after the last source byte to copy
        destination - The destination array
        dstBegin - The starting offset in the destination array
      • subbytes

        public static byte[] subbytes​(byte[] source,
                                      int srcBegin,
                                      int srcEnd)
        Return a new byte array containing a sub-portion of the source array
        Parameters:
        srcBegin - The beginning index (inclusive)
        srcEnd - The ending index (exclusive)
        Returns:
        The new, populated byte array
      • subbytes

        public static byte[] subbytes​(byte[] source,
                                      int srcBegin)
        Return a new byte array containing a sub-portion of the source array
        Parameters:
        srcBegin - The beginning index (inclusive)
        Returns:
        The new, populated byte array