パッケージ org.pcap4j.util

クラス ByteArrays


  • public final class ByteArrays
    extends Object
    導入されたバージョン:
    pcap4j 0.9.1
    作成者:
    Kaito Yamada
    • メソッドの詳細

      • reverse

        public static byte[] reverse​(byte[] array)
        パラメータ:
        array - array
        戻り値:
        a new array containing specified array's elements in reverse order.
      • getByte

        public static byte getByte​(byte[] array,
                                   int offset)
        パラメータ:
        array - array
        offset - offset
        戻り値:
        byte value.
      • toByteArray

        public static byte[] toByteArray​(byte value)
        パラメータ:
        value - value
        戻り値:
        byte array
      • toHexString

        public static String toHexString​(byte value,
                                         String separator)
        パラメータ:
        value - value
        separator - separator
        戻り値:
        hex string
      • getShort

        public static short getShort​(byte[] array,
                                     int offset)
        パラメータ:
        array - array
        offset - offset
        戻り値:
        short value
      • getShort

        public static short getShort​(byte[] array,
                                     int offset,
                                     ByteOrder bo)
        パラメータ:
        array - array
        offset - offset
        bo - bo
        戻り値:
        short value
      • toByteArray

        public static byte[] toByteArray​(short value)
        パラメータ:
        value - value
        戻り値:
        byte array
      • toByteArray

        public static byte[] toByteArray​(short value,
                                         ByteOrder bo)
        パラメータ:
        value - value
        bo - bo
        戻り値:
        byte array
      • toHexString

        public static String toHexString​(short value,
                                         String separator)
        パラメータ:
        value - value
        separator - separator
        戻り値:
        hex string
      • toHexString

        public static String toHexString​(short value,
                                         String separator,
                                         ByteOrder bo)
        パラメータ:
        value - value
        separator - separator
        bo - bo
        戻り値:
        hex string
      • getInt

        public static int getInt​(byte[] array,
                                 int offset)
        パラメータ:
        array - array
        offset - offset
        戻り値:
        int value.
      • getInt

        public static int getInt​(byte[] array,
                                 int offset,
                                 ByteOrder bo)
        パラメータ:
        array - array
        offset - offset
        bo - bo
        戻り値:
        int value.
      • getInt

        public static int getInt​(byte[] array,
                                 int offset,
                                 int length)
        パラメータ:
        array - array
        offset - offset
        length - length
        戻り値:
        int value.
      • getInt

        public static int getInt​(byte[] array,
                                 int offset,
                                 int length,
                                 ByteOrder bo)
        パラメータ:
        array - array
        offset - offset
        length - length
        bo - bo
        戻り値:
        int value.
      • toByteArray

        public static byte[] toByteArray​(int value)
        パラメータ:
        value - value
        戻り値:
        byte array
      • toByteArray

        public static byte[] toByteArray​(int value,
                                         ByteOrder bo)
        パラメータ:
        value - value
        bo - bo
        戻り値:
        byte array
      • toByteArray

        public static byte[] toByteArray​(int value,
                                         int length)
        パラメータ:
        value - value
        length - length
        戻り値:
        byte array
      • toByteArray

        public static byte[] toByteArray​(int value,
                                         int length,
                                         ByteOrder bo)
        パラメータ:
        value - value
        length - length
        bo - bo
        戻り値:
        byte array
      • toHexString

        public static String toHexString​(int value,
                                         String separator)
        パラメータ:
        value - value
        separator - separator
        戻り値:
        hex string
      • toHexString

        public static String toHexString​(int value,
                                         String separator,
                                         ByteOrder bo)
        パラメータ:
        value - value
        separator - separator
        bo - bo
        戻り値:
        hex string
      • getLong

        public static long getLong​(byte[] array,
                                   int offset)
        パラメータ:
        array - array
        offset - offset
        戻り値:
        long value
      • getLong

        public static long getLong​(byte[] array,
                                   int offset,
                                   ByteOrder bo)
        パラメータ:
        array - array
        offset - offset
        bo - bo
        戻り値:
        long value
      • toByteArray

        public static byte[] toByteArray​(long value)
        パラメータ:
        value - value
        戻り値:
        byte array
      • toByteArray

        public static byte[] toByteArray​(long value,
                                         ByteOrder bo)
        パラメータ:
        value - value
        bo - bo
        戻り値:
        byte array
      • toHexString

        public static String toHexString​(long value,
                                         String separator)
        パラメータ:
        value - value
        separator - separator
        戻り値:
        hex string
      • toHexString

        public static String toHexString​(long value,
                                         String separator,
                                         ByteOrder bo)
        パラメータ:
        value - value
        separator - separator
        bo - bo
        戻り値:
        hex string
      • getMacAddress

        public static MacAddress getMacAddress​(byte[] array,
                                               int offset)
        パラメータ:
        array - array
        offset - offset
        戻り値:
        a new MacAddress object.
      • getMacAddress

        public static MacAddress getMacAddress​(byte[] array,
                                               int offset,
                                               ByteOrder bo)
        パラメータ:
        array - array
        offset - offset
        bo - bo
        戻り値:
        a new MacAddress object.
      • toByteArray

        public static byte[] toByteArray​(MacAddress value)
        パラメータ:
        value - value
        戻り値:
        byte array
      • toByteArray

        public static byte[] toByteArray​(MacAddress value,
                                         ByteOrder bo)
        パラメータ:
        value - value
        bo - bo
        戻り値:
        byte array
      • getLinkLayerAddress

        public static LinkLayerAddress getLinkLayerAddress​(byte[] array,
                                                           int offset,
                                                           int length)
        パラメータ:
        array - array
        offset - offset
        length - length
        戻り値:
        a new LinkLayerAddress object.
      • getLinkLayerAddress

        public static LinkLayerAddress getLinkLayerAddress​(byte[] array,
                                                           int offset,
                                                           int length,
                                                           ByteOrder bo)
        パラメータ:
        array - array
        offset - offset
        length - length
        bo - bo
        戻り値:
        a new LinkLayerAddress object.
      • toByteArray

        public static byte[] toByteArray​(LinkLayerAddress value)
        パラメータ:
        value - value
        戻り値:
        byte array
      • toByteArray

        public static byte[] toByteArray​(LinkLayerAddress value,
                                         ByteOrder bo)
        パラメータ:
        value - value
        bo - bo
        戻り値:
        byte array
      • getInet4Address

        public static Inet4Address getInet4Address​(byte[] array,
                                                   int offset)
        パラメータ:
        array - array
        offset - offset
        戻り値:
        a new Inet4Address object.
      • getInet4Address

        public static Inet4Address getInet4Address​(byte[] array,
                                                   int offset,
                                                   ByteOrder bo)
        パラメータ:
        array - array
        offset - offset
        bo - bo
        戻り値:
        a new Inet4Address object.
      • parseInet4Address

        public static byte[] parseInet4Address​(String addr)
        パラメータ:
        addr - a string representation of an IPv4 address. (e.g. "192.168.0.100")
        戻り値:
        a byte array representation of the IPv4 address.
        例外:
        IllegalArgumentException - if failed to parse addr.
      • getInet6Address

        public static Inet6Address getInet6Address​(byte[] array,
                                                   int offset)
        パラメータ:
        array - array
        offset - offset
        戻り値:
        a new Inet6Address object.
      • getInet6Address

        public static Inet6Address getInet6Address​(byte[] array,
                                                   int offset,
                                                   ByteOrder bo)
        パラメータ:
        array - array
        offset - offset
        bo - bo
        戻り値:
        a new Inet6Address object.
      • toByteArray

        public static byte[] toByteArray​(InetAddress value)
        パラメータ:
        value - value
        戻り値:
        byte array
      • toByteArray

        public static byte[] toByteArray​(InetAddress value,
                                         ByteOrder bo)
        パラメータ:
        value - value
        bo - bo
        戻り値:
        byte array
      • getSubArray

        public static byte[] getSubArray​(byte[] array,
                                         int offset,
                                         int length)
        パラメータ:
        array - array
        offset - offset
        length - length
        戻り値:
        sub array
      • getSubArray

        public static byte[] getSubArray​(byte[] array,
                                         int offset)
        パラメータ:
        array - array
        offset - offset
        戻り値:
        sub array
      • toHexString

        public static String toHexString​(byte[] array,
                                         String separator)
        パラメータ:
        array - array
        separator - separator
        戻り値:
        hex string
      • toHexString

        public static String toHexString​(byte[] array,
                                         String separator,
                                         int offset,
                                         int length)
        パラメータ:
        array - array
        separator - separator
        offset - offset
        length - length
        戻り値:
        hex string
      • calcChecksum

        public static short calcChecksum​(byte[] data)
        A utility method to calculate the Internet checksum.
        パラメータ:
        data - data
        戻り値:
        checksum
        関連項目:
        RFC 1071
      • calcCrc32Checksum

        public static int calcCrc32Checksum​(byte[] data)
        A utility method to calculate CRC-32 checksum.
        パラメータ:
        data - data
        戻り値:
        checksum
      • calcCrc32cChecksum

        public static int calcCrc32cChecksum​(byte[] data)
        A utility method to calculate CRC-32C checksum.
        パラメータ:
        data - data
        戻り値:
        checksum
      • calcAdler32Checksum

        public static int calcAdler32Checksum​(byte[] data)
        A utility method to calculate Adler-32 checksum.
        パラメータ:
        data - data
        戻り値:
        checksum
      • parseByteArray

        public static byte[] parseByteArray​(String hexString,
                                            String separator)
        パラメータ:
        hexString - hexString
        separator - separator
        戻り値:
        a new byte array.
      • clone

        public static byte[] clone​(byte[] array)
        パラメータ:
        array - array
        戻り値:
        a clone of array
      • validateBounds

        public static void validateBounds​(byte[] arr,
                                          int offset,
                                          int len)
        A utility method to validate arguments which indicate a part of an array.
        パラメータ:
        arr - arr
        offset - offset
        len - len
        例外:
        NullPointerException - if the arr is null.
        IllegalArgumentException - if arr is empty or len is zero.
        ArrayIndexOutOfBoundsException - if offset or len is negative, or ( offset + len) is greater than or equal to arr.length.
      • xor

        public static byte[] xor​(byte[] arr1,
                                 byte[] arr2)
        パラメータ:
        arr1 - arr1
        arr2 - arr2
        戻り値:
        arr1 xor arr2
      • concatenate

        public static byte[] concatenate​(byte[] arr1,
                                         byte[] arr2)
        パラメータ:
        arr1 - arr1
        arr2 - arr2
        戻り値:
        arr1 + arr2
      • concatenate

        public static byte[] concatenate​(List<byte[]> arrs)
        パラメータ:
        arrs - arrays
        戻り値:
        the concatenated array.