Class Utility


  • public final class Utility
    extends java.lang.Object
    Author:
    V2.x Handy class full of static functions.
    • Constructor Summary

      Constructors 
      Constructor Description
      Utility()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static int bytesToInt​(byte[] array, int offset)
      Unmarshal a byte array to an integer.
      static long bytesToLong​(byte[] array, int offset)  
      static byte[] intToBytes​(int value)
      Marshal an integer to a byte array.
      static void intToBytes​(int value, byte[] array, int offset)  
      static byte[] longToBytes​(long value)
      Unmarshal a byte array to an long.
      static void longToBytes​(long value, byte[] array, int offset)
      Marshal an long to a byte array.
      • Methods inherited from class java.lang.Object

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

      • Utility

        public Utility()
    • Method Detail

      • bytesToInt

        public static int bytesToInt​(byte[] array,
                                     int offset)
        Unmarshal a byte array to an integer. Assume the bytes are in BIGENDIAN order. i.e. array[offset] is the most-significant-byte and array[offset+3] is the least-significant-byte.
        Parameters:
        array - The array of bytes.
        offset - The offset from which to start unmarshalling.
      • intToBytes

        public static byte[] intToBytes​(int value)
        Marshal an integer to a byte array. The bytes are in BIGENDIAN order. i.e. array[offset] is the most-significant-byte and array[offset+3] is the least-significant-byte.
      • intToBytes

        public static void intToBytes​(int value,
                                      byte[] array,
                                      int offset)
      • longToBytes

        public static byte[] longToBytes​(long value)
        Unmarshal a byte array to an long. Assume the bytes are in BIGENDIAN order. i.e. array[offset] is the most-significant-byte and array[offset+7] is the least-significant-byte.
      • bytesToLong

        public static long bytesToLong​(byte[] array,
                                       int offset)
      • longToBytes

        public static void longToBytes​(long value,
                                       byte[] array,
                                       int offset)
        Marshal an long to a byte array. The bytes are in BIGENDIAN order. i.e. array[offset] is the most-significant-byte and array[offset+7] is the least-significant-byte.
        Parameters:
        array - The array of bytes.
        offset - The offset from which to start marshalling.