Class Utils

java.lang.Object
com.blackrook.rookscript.struct.Utils

public final class Utils extends Object
Utility functions.
Author:
Matthew Tropiano
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final InputStream
    A null input stream (never has data to read).
    static final OutputStream
    A null output stream (eats all data written).
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T> T
    arrayElement(T[] array, int index)
    Gets the element at an index in the array, but returns null if the index is outside of the array bounds.
    static <T> void
    arraySwap(T[] array, int a, int b)
    Swaps the contents of two indices of an array.
    static double
    clampValue(double val, double lo, double hi)
    Coerces a double to the range bounded by lo and hi.
    static void
    Attempts to close an AutoCloseable object.
    static <T> T
    construct(Constructor<T> constructor, Object... params)
    Creates a new instance of a class from a class type.
    static <T> T
    create(Class<T> clazz)
    Creates a new instance of a class from a class type.
    static <T> T
    createForType(Object object, Class<T> targetType)
    Creates a new instance of an object for placement in a POJO or elsewhere.
    static double
    degToRad(double degrees)
    Converts degrees to radians.
    static int
    getArrayDimensions(Class<?> arrayType)
    Gets how many dimensions that this array, represented by the provided type, has.
    static int
    Gets how many array dimensions that an object (presumably an array) has.
    static Class<?>
    getArrayType(Class<?> arrayType)
    Gets the class type of this array type, if this is an array type.
    static Class<?>
    Gets the class type of this array, if this is an array.
    static double
    getDouble(ByteOrder order, byte[] data, int offset)
    Gets a double floating-point number from an array.
    static Object
    getFieldValue(Object instance, Field field)
    Gets the value of a field on an object.
    static String
    getFileExtension(File file, String extensionSeparator)
    Returns the extension of a file's name.
    static String
    getFileExtension(String filename, String extensionSeparator)
    Returns the extension of a filename.
    static String
    getFileNameWithoutExtension(File file, String extensionSeparator)
    Returns the file's name, no extension.
    static String
    getFileNameWithoutExtension(String filename, String extensionSeparator)
    Returns the file's name, no extension.
    static float
    getFloat(ByteOrder order, byte[] data, int offset)
    Gets a floating-point number from an array.
    static int
    getInteger(ByteOrder order, byte[] data, int offset)
    Gets an integer from an array.
    static long
    getLong(ByteOrder order, byte[] data, int offset)
    Gets a long integer from an array.
    getProfile(Class<T> clazz)
    Creates a new profile for a provided type.
    static short
    getShort(ByteOrder order, byte[] data, int offset)
    Gets a short from an array.
    static long
    getUnsignedInteger(ByteOrder order, byte[] data, int offset)
    Gets an unsigned integer from an array.
    static int
    getUnsignedShort(ByteOrder order, byte[] data, int offset)
    Gets an unsigned short from an array.
    static Object
    invokeBlind(Method method, Object instance)
    Blindly invokes a method, with no parameters, only throwing a RuntimeException if something goes wrong.
    static Object
    invokeBlind(Method method, Object instance, Object... params)
    Blindly invokes a method, only throwing a RuntimeException if something goes wrong.
    static boolean
    isArray(Class<?> clazz)
    Tests if a class is actually an array type.
    static boolean
    isArray(Object object)
    Tests if an object is actually an array type.
    static boolean
    Checks if a value is "empty." The following is considered "empty": Null references.
    static <T> T
    isNull(T testObject, T nullReturn)
    Returns the first object if it is not null, otherwise returns the second.
    static boolean
     
    static <T> T[]
    joinArrays(T[]... arrays)
    Concatenates a set of arrays together, such that the contents of each array are joined into one array.
    static double
    linearInterpolate(double factor, double x, double y)
    Gives a value that is the result of a linear interpolation between two values.
    openResource(String pathString)
    Opens an InputStream to a resource using the current thread's ClassLoader.
    static double
    parseDouble(String s, double def)
    Attempts to parse a double from a string.
    static long
    parseLong(String s, long def)
    Attempts to parse a long from a string.
    static void
    putDouble(double value, ByteOrder order, byte[] data, int offset)
    Puts a double floating-point number into an array.
    static void
    putFloat(float value, ByteOrder order, byte[] data, int offset)
    Puts a floating-point number into an array.
    static void
    putInteger(int value, ByteOrder order, byte[] data, int offset)
    Puts an integer into an array.
    static void
    putLong(long value, ByteOrder order, byte[] data, int offset)
    Puts a long integer into an array.
    static void
    putShort(short value, ByteOrder order, byte[] data, int offset)
    Puts a short into an array.
    static void
    putUnsignedInteger(long value, ByteOrder order, byte[] data, int offset)
    Puts an unsigned integer into an array.
    static void
    putUnsignedShort(int value, ByteOrder order, byte[] data, int offset)
    Puts an unsigned short into an array.
    static <T extends Comparable<T>>
    void
    quicksort(T[] array)
    Performs an in-place QuickSort on the provided array.
    static <T extends Comparable<T>>
    void
    quicksort(T[] array, int lo, int hi)
    Performs an in-place QuickSort on the provided array within an interval of indices.
    static <T> void
    quicksort(T[] array, int lo, int hi, Comparator<? super T> comparator)
    Performs an in-place QuickSort on the provided array within an interval of indices.
    static <T> void
    quicksort(T[] array, Comparator<? super T> comparator)
    Performs an in-place QuickSort on the provided array using a compatible Comparator.
    static double
    radToDeg(double radians)
    Converts radians to degrees.
    static int
    read(DataInput input)
    Reads a set of bytes until end-of-stream or file.
    static int
    read(DataInput input, byte[] data, int offset, int length)
    Reads a set of bytes until end-of-stream or file.
    static int
    relay(DataInput in, DataOutput out, int bufferSize, int maxLength)
    Reads from an input stream, reading in a consistent set of data and writing it to the output stream.
    static void
    setFieldValue(Object instance, Field field, Object value)
    Sets the value of a field on an object.
    static <T extends Comparable<T>>
    int
    sortFrom(T[] array, int index)
    Shifts an object to an appropriate position according to the object's Comparable.compareTo(Object) function.
    static <T> int
    sortFrom(T[] array, int index, Comparator<? super T> comparator)
    Shifts an object to an appropriate position according to the provided comparator function.
    static double
    wrapValue(double val, double lo, double hi)
    Coerces a double to the range bounded by lo and hi, by "wrapping" the value.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • NULL_INPUT

      public static final InputStream NULL_INPUT
      A null input stream (never has data to read).
    • NULL_OUTPUT

      public static final OutputStream NULL_OUTPUT
      A null output stream (eats all data written).
  • Constructor Details

    • Utils

      public Utils()
  • Method Details

    • isWindows

      public static boolean isWindows()
      Returns:
      true if we using Windows.
    • isEmpty

      public static boolean isEmpty(Object obj)
      Checks if a value is "empty." The following is considered "empty":
      Parameters:
      obj - the object to check.
      Returns:
      true if the provided object is considered "empty", false otherwise.
    • isNull

      public static <T> T isNull(T testObject, T nullReturn)
      Returns the first object if it is not null, otherwise returns the second.
      Type Parameters:
      T - class that extends Object.
      Parameters:
      testObject - the first ("tested") object.
      nullReturn - the object to return if testObject is null.
      Returns:
      testObject if not null, nullReturn otherwise.
    • radToDeg

      public static double radToDeg(double radians)
      Converts radians to degrees.
      Parameters:
      radians - the input angle in radians.
      Returns:
      the resultant angle in degrees.
    • degToRad

      public static double degToRad(double degrees)
      Converts degrees to radians.
      Parameters:
      degrees - the input angle in degrees.
      Returns:
      the resultant angle in radians.
    • clampValue

      public static double clampValue(double val, double lo, double hi)
      Coerces a double to the range bounded by lo and hi.
      Example: clampValue(32,-16,16) returns 16.
      Example: clampValue(4,-16,16) returns 4.
      Example: clampValue(-1000,-16,16) returns -16.
      Parameters:
      val - the double.
      lo - the lower bound.
      hi - the upper bound.
      Returns:
      the value after being "forced" into the range.
    • wrapValue

      public static double wrapValue(double val, double lo, double hi)
      Coerces a double to the range bounded by lo and hi, by "wrapping" the value.
      Example: wrapValue(32,-16,16) returns 0.
      Example: wrapValue(4,-16,16) returns 4.
      Example: wrapValue(-1000,-16,16) returns 8.
      Parameters:
      val - the double.
      lo - the lower bound.
      hi - the upper bound.
      Returns:
      the value after being "wrapped" into the range.
    • linearInterpolate

      public static double linearInterpolate(double factor, double x, double y)
      Gives a value that is the result of a linear interpolation between two values.
      Parameters:
      factor - the interpolation factor.
      x - the first value.
      y - the second value.
      Returns:
      the interpolated value.
    • parseLong

      public static long parseLong(String s, long def)
      Attempts to parse a long from a string. If the string is null or the empty string, this returns def.
      Parameters:
      s - the input string.
      def - the fallback value to return.
      Returns:
      the interpreted long integer or def if the input string is blank.
    • parseDouble

      public static double parseDouble(String s, double def)
      Attempts to parse a double from a string. If the string is null or the empty string, this returns def.
      Parameters:
      s - the input string.
      def - the fallback value to return.
      Returns:
      the interpreted double or def if the input string is blank.
    • setFieldValue

      public static void setFieldValue(Object instance, Field field, Object value)
      Sets the value of a field on an object.
      Parameters:
      instance - the object instance to set the field on.
      field - the field to set.
      value - the value to set.
      Throws:
      NullPointerException - if the field or object provided is null.
      ClassCastException - if the value could not be cast to the proper type.
      RuntimeException - if anything goes wrong (bad field name, bad target, bad argument, or can't access the field).
      See Also:
    • getFieldValue

      public static Object getFieldValue(Object instance, Field field)
      Gets the value of a field on an object.
      Parameters:
      instance - the object instance to get the field value of.
      field - the field to get the value of.
      Returns:
      the current value of the field.
      Throws:
      NullPointerException - if the field or object provided is null.
      RuntimeException - if anything goes wrong (bad target, bad argument, or can't access the field).
      See Also:
    • invokeBlind

      public static Object invokeBlind(Method method, Object instance)
      Blindly invokes a method, with no parameters, only throwing a RuntimeException if something goes wrong. Here for the convenience of not making a billion try/catch clauses for a method invocation. This method exists to avoid unnecessary memory allocations.
      Parameters:
      method - the method to invoke.
      instance - the object instance that is the method target.
      Returns:
      the return value from the method invocation. If void, this is null.
      Throws:
      ClassCastException - if one of the parameters could not be cast to the proper type.
      RuntimeException - if anything goes wrong (bad target, bad argument, or can't access the method).
      See Also:
    • invokeBlind

      public static Object invokeBlind(Method method, Object instance, Object... params)
      Blindly invokes a method, only throwing a RuntimeException if something goes wrong. Here for the convenience of not making a billion try/catch clauses for a method invocation.
      Parameters:
      method - the method to invoke.
      instance - the object instance that is the method target.
      params - the parameters to pass to the method.
      Returns:
      the return value from the method invocation. If void, this is null.
      Throws:
      ClassCastException - if one of the parameters could not be cast to the proper type.
      RuntimeException - if anything goes wrong (bad target, bad argument, or can't access the method).
      See Also:
    • joinArrays

      public static <T> T[] joinArrays(T[]... arrays)
      Concatenates a set of arrays together, such that the contents of each array are joined into one array. Null arrays are skipped.
      Type Parameters:
      T - the object type stored in the arrays.
      Parameters:
      arrays - the list of arrays.
      Returns:
      a new array with all objects in each provided array added to the resultant one in the order in which they appear.
    • arrayElement

      public static <T> T arrayElement(T[] array, int index)
      Gets the element at an index in the array, but returns null if the index is outside of the array bounds.
      Type Parameters:
      T - the array type.
      Parameters:
      array - the array to use.
      index - the index to use.
      Returns:
      array[index] or null if out of bounds.
    • isArray

      public static boolean isArray(Class<?> clazz)
      Tests if a class is actually an array type.
      Parameters:
      clazz - the class to test.
      Returns:
      true if so, false if not.
    • isArray

      public static boolean isArray(Object object)
      Tests if an object is actually an array type.
      Parameters:
      object - the object to test.
      Returns:
      true if so, false if not.
    • getArrayType

      public static Class<?> getArrayType(Class<?> arrayType)
      Gets the class type of this array type, if this is an array type.
      Parameters:
      arrayType - the type to inspect.
      Returns:
      this array's type, or null if the provided type is not an array, or if the found class is not on the classpath.
    • getArrayType

      public static Class<?> getArrayType(Object object)
      Gets the class type of this array, if this is an array.
      Parameters:
      object - the object to inspect.
      Returns:
      this array's type, or null if the provided object is not an array, or if the found class is not on the classpath.
    • getArrayDimensions

      public static int getArrayDimensions(Class<?> arrayType)
      Gets how many dimensions that this array, represented by the provided type, has.
      Parameters:
      arrayType - the type to inspect.
      Returns:
      the number of array dimensions, or 0 if not an array.
    • getArrayDimensions

      public static int getArrayDimensions(Object array)
      Gets how many array dimensions that an object (presumably an array) has.
      Parameters:
      array - the object to inspect.
      Returns:
      the number of array dimensions, or 0 if not an array.
    • openResource

      public static InputStream openResource(String pathString)
      Opens an InputStream to a resource using the current thread's ClassLoader.
      Parameters:
      pathString - the resource pathname.
      Returns:
      an open InputStream for reading the resource or null if not found.
      See Also:
    • relay

      public static int relay(DataInput in, DataOutput out, int bufferSize, int maxLength) throws IOException
      Reads from an input stream, reading in a consistent set of data and writing it to the output stream. The read/write is buffered so that it does not bog down the OS's other I/O requests. This method finishes when the end of the source stream is reached. Note that this may block if the input stream is a type of stream that will block if the input stream blocks for additional input. This method is thread-safe.
      Parameters:
      in - the input stream to grab data from.
      out - the output stream to write the data to.
      bufferSize - the buffer size for the I/O. Must be > 0.
      maxLength - the maximum amount of bytes to relay, or a value < 0 for no max.
      Returns:
      the total amount of bytes relayed.
      Throws:
      IOException - if a read or write error occurs.
    • close

      public static void close(AutoCloseable c)
      Attempts to close an AutoCloseable object. If the object is null, this does nothing.
      Parameters:
      c - the reference to the AutoCloseable object.
    • getProfile

      public static <T> TypeProfileFactory.Profile<T> getProfile(Class<T> clazz)
      Creates a new profile for a provided type. Generated profiles are stored in memory, and retrieved again by class type.

      This method is thread-safe.

      Type Parameters:
      T - the class type.
      Parameters:
      clazz - the class.
      Returns:
      a new profile.
    • create

      public static <T> T create(Class<T> clazz)
      Creates a new instance of a class from a class type. This essentially calls Class.newInstance(), but wraps the call in a try/catch block that only throws an exception if something goes wrong.
      Type Parameters:
      T - the return object type.
      Parameters:
      clazz - the class type to instantiate.
      Returns:
      a new instance of an object.
      Throws:
      RuntimeException - if instantiation cannot happen, either due to a non-existent constructor or a non-visible constructor.
    • construct

      public static <T> T construct(Constructor<T> constructor, Object... params)
      Creates a new instance of a class from a class type. This essentially calls Class.newInstance(), but wraps the call in a try/catch block that only throws an exception if something goes wrong.
      Type Parameters:
      T - the return object type.
      Parameters:
      constructor - the constructor to call.
      params - the constructor parameters.
      Returns:
      a new instance of an object created via the provided constructor.
      Throws:
      RuntimeException - if instantiation cannot happen, either due to a non-existent constructor or a non-visible constructor.
    • createForType

      public static <T> T createForType(Object object, Class<T> targetType)
      Creates a new instance of an object for placement in a POJO or elsewhere.
      Type Parameters:
      T - the return object type.
      Parameters:
      object - the object to convert to another object
      targetType - the target class type to convert to, if the types differ.
      Returns:
      a suitable object of type targetType.
      Throws:
      ClassCastException - if the incoming type cannot be converted.
    • arraySwap

      public static <T> void arraySwap(T[] array, int a, int b)
      Swaps the contents of two indices of an array.
      Type Parameters:
      T - the object type stored in the array.
      Parameters:
      array - the input array.
      a - the first index.
      b - the second index.
    • sortFrom

      public static <T extends Comparable<T>> int sortFrom(T[] array, int index)
      Shifts an object to an appropriate position according to the object's Comparable.compareTo(Object) function.
      Type Parameters:
      T - the object type stored in the array that extends Comparable.
      Parameters:
      array - the array to shift the contents of.
      index - the index to add it to (the contents are replaced).
      Returns:
      the final index in the array of the sorted object.
    • sortFrom

      public static <T> int sortFrom(T[] array, int index, Comparator<? super T> comparator)
      Shifts an object to an appropriate position according to the provided comparator function.
      Type Parameters:
      T - the object type stored in the arrays.
      Parameters:
      array - the array to shift the contents of.
      index - the index to add it to (the contents are replaced).
      comparator - the comparator to use.
      Returns:
      the final index in the array of the sorted object.
    • quicksort

      public static <T extends Comparable<T>> void quicksort(T[] array)
      Performs an in-place QuickSort on the provided array. The array's contents will change upon completion. Convenience method for quicksort(array, 0, array.length - 1);
      Type Parameters:
      T - the object type stored in the array that extends Comparable.
      Parameters:
      array - the input array.
    • quicksort

      public static <T> void quicksort(T[] array, Comparator<? super T> comparator)
      Performs an in-place QuickSort on the provided array using a compatible Comparator. The array's contents will change upon completion. Convenience method for quicksort(array, 0, array.length - 1, comparator);
      Type Parameters:
      T - the object type stored in the array.
      Parameters:
      array - the input array.
      comparator - the comparator to use for comparing.
    • quicksort

      public static <T extends Comparable<T>> void quicksort(T[] array, int lo, int hi)
      Performs an in-place QuickSort on the provided array within an interval of indices. The array's contents will change upon completion. If lo is greater than hi, this does nothing.
      Type Parameters:
      T - the object type stored in the array that extends Comparable.
      Parameters:
      array - the input array.
      lo - the low index to start the sort (inclusive).
      hi - the high index to start the sort (inclusive).
    • quicksort

      public static <T> void quicksort(T[] array, int lo, int hi, Comparator<? super T> comparator)
      Performs an in-place QuickSort on the provided array within an interval of indices. The array's contents will change upon completion. If lo is greater than hi, this does nothing.
      Type Parameters:
      T - the object type stored in the array.
      Parameters:
      array - the input array.
      lo - the low index to start the sort (inclusive).
      hi - the high index to start the sort (inclusive).
      comparator - the comparator to use for comparing.
    • getFileExtension

      public static String getFileExtension(String filename, String extensionSeparator)
      Returns the extension of a filename.
      Parameters:
      filename - the file name.
      extensionSeparator - the text or characters that separates file name from extension.
      Returns:
      the file's extension, or an empty string for no extension.
    • getFileExtension

      public static String getFileExtension(File file, String extensionSeparator)
      Returns the extension of a file's name.
      Parameters:
      file - the file.
      extensionSeparator - the text or characters that separates file name from extension.
      Returns:
      the file's extension, or an empty string for no extension.
    • getFileNameWithoutExtension

      public static String getFileNameWithoutExtension(File file, String extensionSeparator)
      Returns the file's name, no extension.
      Parameters:
      file - the file.
      extensionSeparator - the text or characters that separates file name from extension.
      Returns:
      the file's name without extension.
    • getFileNameWithoutExtension

      public static String getFileNameWithoutExtension(String filename, String extensionSeparator)
      Returns the file's name, no extension.
      Parameters:
      filename - the file name.
      extensionSeparator - the text or characters that separates file name from extension.
      Returns:
      the file's name without extension.
    • putShort

      public static void putShort(short value, ByteOrder order, byte[] data, int offset)
      Puts a short into an array. Writes 2 bytes.
      Parameters:
      value - the value to convert.
      order - the byte ordering.
      data - the output array.
      offset - the offset into the array to write.
      Throws:
      ArrayIndexOutOfBoundsException - if offset + 2 exceeds data.length.
    • read

      public static int read(DataInput input) throws IOException
      Reads a set of bytes until end-of-stream or file.
      Parameters:
      input - the DataInput to read from.
      Returns:
      the byte read (0 - 255), or -1 if end-of-stream/file at time of call.
      Throws:
      IOException - if a read error occurs.
    • read

      public static int read(DataInput input, byte[] data, int offset, int length) throws IOException
      Reads a set of bytes until end-of-stream or file.
      Parameters:
      input - the DataInput to read from.
      data - the recipient array for the byte data.
      offset - the starting offset into the array to put the bytes.
      length - the maximum amount of bytes to read.
      Returns:
      the amount of bytes read, or -1 if end-of-stream/file at time of call.
      Throws:
      IOException - if a read error occurs.
      ArrayIndexOutOfBoundsException - if offset + length breaches the end of the data array.
    • getShort

      public static short getShort(ByteOrder order, byte[] data, int offset)
      Gets a short from an array. Reads 2 bytes.
      Parameters:
      order - the byte ordering.
      data - the input array.
      offset - the offset into the array to read.
      Returns:
      the resultant short.
      Throws:
      ArrayIndexOutOfBoundsException - if offset + 2 exceeds data.length.
    • putUnsignedShort

      public static void putUnsignedShort(int value, ByteOrder order, byte[] data, int offset)
      Puts an unsigned short into an array. Writes 2 bytes.
      Parameters:
      value - the value to convert.
      order - the byte ordering.
      data - the output array.
      offset - the offset into the array to write.
      Throws:
      ArrayIndexOutOfBoundsException - if offset + 2 exceeds data.length.
    • getUnsignedShort

      public static int getUnsignedShort(ByteOrder order, byte[] data, int offset)
      Gets an unsigned short from an array. Reads 2 bytes.
      Parameters:
      order - the byte ordering.
      data - the input array.
      offset - the offset into the array to read.
      Returns:
      the resultant short.
      Throws:
      ArrayIndexOutOfBoundsException - if offset + 2 exceeds data.length.
    • putInteger

      public static void putInteger(int value, ByteOrder order, byte[] data, int offset)
      Puts an integer into an array. Writes 4 bytes.
      Parameters:
      value - the value to convert.
      order - the byte ordering.
      data - the output array.
      offset - the offset into the array to write.
      Throws:
      ArrayIndexOutOfBoundsException - if offset + 4 exceeds data.length.
    • getInteger

      public static int getInteger(ByteOrder order, byte[] data, int offset)
      Gets an integer from an array. Reads 4 bytes.
      Parameters:
      order - the byte ordering.
      data - the input array.
      offset - the offset into the array to read.
      Returns:
      the resultant integer.
      Throws:
      ArrayIndexOutOfBoundsException - if offset + 4 exceeds data.length.
    • putUnsignedInteger

      public static void putUnsignedInteger(long value, ByteOrder order, byte[] data, int offset)
      Puts an unsigned integer into an array. Writes 4 bytes.
      Parameters:
      value - the value to convert.
      order - the byte ordering.
      data - the output array.
      offset - the offset into the array to write.
      Throws:
      ArrayIndexOutOfBoundsException - if offset + 4 exceeds data.length.
    • getUnsignedInteger

      public static long getUnsignedInteger(ByteOrder order, byte[] data, int offset)
      Gets an unsigned integer from an array. Reads 4 bytes.
      Parameters:
      order - the byte ordering.
      data - the input array.
      offset - the offset into the array to read.
      Returns:
      the resultant integer.
      Throws:
      ArrayIndexOutOfBoundsException - if offset + 4 exceeds data.length.
    • putFloat

      public static void putFloat(float value, ByteOrder order, byte[] data, int offset)
      Puts a floating-point number into an array. Writes 4 bytes.
      Parameters:
      value - the value to convert.
      order - the byte ordering.
      data - the output array.
      offset - the offset into the array to write.
      Throws:
      ArrayIndexOutOfBoundsException - if offset + 4 exceeds data.length.
    • getFloat

      public static float getFloat(ByteOrder order, byte[] data, int offset)
      Gets a floating-point number from an array. Reads 4 bytes.
      Parameters:
      order - the byte ordering.
      data - the input array.
      offset - the offset into the array to read.
      Returns:
      the resultant float.
      Throws:
      ArrayIndexOutOfBoundsException - if offset + 4 exceeds data.length.
    • putLong

      public static void putLong(long value, ByteOrder order, byte[] data, int offset)
      Puts a long integer into an array. Writes 8 bytes.
      Parameters:
      value - the value to convert.
      order - the byte ordering.
      data - the output array.
      offset - the offset into the array to write.
      Throws:
      ArrayIndexOutOfBoundsException - if offset + 8 exceeds data.length.
    • getLong

      public static long getLong(ByteOrder order, byte[] data, int offset)
      Gets a long integer from an array. Reads 8 bytes.
      Parameters:
      order - the byte ordering.
      data - the input array.
      offset - the offset into the array to read.
      Returns:
      the resultant integer.
      Throws:
      ArrayIndexOutOfBoundsException - if offset + 8 exceeds data.length.
    • putDouble

      public static void putDouble(double value, ByteOrder order, byte[] data, int offset)
      Puts a double floating-point number into an array. Writes 8 bytes.
      Parameters:
      value - the value to convert.
      order - the byte ordering.
      data - the output array.
      offset - the offset into the array to write.
      Throws:
      ArrayIndexOutOfBoundsException - if offset + 8 exceeds data.length.
    • getDouble

      public static double getDouble(ByteOrder order, byte[] data, int offset)
      Gets a double floating-point number from an array. Reads 8 bytes.
      Parameters:
      order - the byte ordering.
      data - the input array.
      offset - the offset into the array to read.
      Returns:
      the resultant float.
      Throws:
      ArrayIndexOutOfBoundsException - if offset + 8 exceeds data.length.