Package org.apache.commons.imaging.common

# Class ByteConversions

java.lang.Object
org.apache.commons.imaging.common.ByteConversions

public final class ByteConversions extends Object
Convenience methods for converting data types to and from byte arrays.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static byte[]`
  `toBytes(double[] values, ByteOrder byteOrder)`
  `static byte[]`
  `toBytes(double value, ByteOrder byteOrder)`
  `static byte[]`
  `toBytes(float[] values, ByteOrder byteOrder)`
  `static byte[]`
  `toBytes(float value, ByteOrder byteOrder)`
  `static byte[]`
  `toBytes(int[] values, ByteOrder byteOrder)`
  `static byte[]`
  `toBytes(int value, ByteOrder byteOrder)`
  `static byte[]`
  `toBytes(long value, ByteOrder byteOrder)`
  Encodes an eight-byte (long) into an array of bytes based on the specified byte order.
  `static byte[]`
  `toBytes(short[] values, ByteOrder byteOrder)`
  `static byte[]`
  `toBytes(short value, ByteOrder byteOrder)`
  `static byte[]`
  `toBytes(RationalNumber[] values, ByteOrder byteOrder)`
  `static byte[]`
  `toBytes(RationalNumber value, ByteOrder byteOrder)`
  `static double`
  `toDouble(byte[] bytes, ByteOrder byteOrder)`
  `static double[]`
  `toDoubles(byte[] bytes, ByteOrder byteOrder)`
  `static float`
  `toFloat(byte[] bytes, ByteOrder byteOrder)`
  `static float[]`
  `toFloats(byte[] bytes, ByteOrder byteOrder)`
  `static int`
  `toInt(byte[] bytes, int offset, ByteOrder byteOrder)`
  `static int`
  `toInt(byte[] bytes, ByteOrder byteOrder)`
  `static int[]`
  `toInts(byte[] bytes, ByteOrder byteOrder)`
  `static long`
  `toLong(byte[] bytes, ByteOrder byteOrder)`
  Extracts an eight-byte long integer from the specified byte array.
  `static long[]`
  `toLongs(byte[] bytes, ByteOrder byteOrder)`
  Extracts an array of eight-byte long integers from the specified array of bytes.
  `static RationalNumber`
  `toRational(byte[] bytes, ByteOrder byteOrder, boolean unsignedType)`
  Interprets the content of a specified bytes array to create an instance of the RationalNumber class.
  `static RationalNumber[]`
  `toRationals(byte[] bytes, ByteOrder byteOrder, boolean unsignedType)`
  `static short`
  `toShort(byte[] bytes, ByteOrder byteOrder)`
  `static short[]`
  `toShorts(byte[] bytes, ByteOrder byteOrder)`
  `static int`
  `toUInt16(byte[] bytes, int offset, ByteOrder byteOrder)`
  `static int`
  `toUInt16(byte[] bytes, ByteOrder byteOrder)`
  `static int[]`
  `toUInt16s(byte[] bytes, ByteOrder byteOrder)`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Method Details

  - ### toBytes

    public static byte[] toBytes(double value, ByteOrder byteOrder)

  - ### toBytes

    public static byte[] toBytes(double[] values, ByteOrder byteOrder)

  - ### toBytes

    public static byte[] toBytes(float value, ByteOrder byteOrder)

  - ### toBytes

    public static byte[] toBytes(float[] values, ByteOrder byteOrder)

  - ### toBytes

    public static byte[] toBytes(int value, ByteOrder byteOrder)

  - ### toBytes

    public static byte[] toBytes(int[] values, ByteOrder byteOrder)

  - ### toBytes

    public static byte[] toBytes(long value, ByteOrder byteOrder)
    Encodes an eight-byte (long) into an array of bytes based on the specified byte order.
    Parameters:
      `value` - a standard data primitive of type long
      `byteOrder` - the byte order to be used for encoding
    Returns:
      an array of length 8

  - ### toBytes

    public static byte[] toBytes(RationalNumber value, ByteOrder byteOrder)

  - ### toBytes

    public static byte[] toBytes(RationalNumber[] values, ByteOrder byteOrder)

  - ### toBytes

    public static byte[] toBytes(short value, ByteOrder byteOrder)

  - ### toBytes

    public static byte[] toBytes(short[] values, ByteOrder byteOrder)

  - ### toDouble

    public static double toDouble(byte[] bytes, ByteOrder byteOrder)

  - ### toDoubles

    public static double[] toDoubles(byte[] bytes, ByteOrder byteOrder)

  - ### toFloat

    public static float toFloat(byte[] bytes, ByteOrder byteOrder)

  - ### toFloats

    public static float[] toFloats(byte[] bytes, ByteOrder byteOrder)

  - ### toInt

    public static int toInt(byte[] bytes, ByteOrder byteOrder)

  - ### toInt

    public static int toInt(byte[] bytes, int offset, ByteOrder byteOrder)

  - ### toInts

    public static int[] toInts(byte[] bytes, ByteOrder byteOrder)

  - ### toLong

    public static long toLong(byte[] bytes, ByteOrder byteOrder)
    Extracts an eight-byte long integer from the specified byte array. This method assumes that the byte array is of sufficiently large size to encode a long integer.
    Parameters:
      `bytes` - an array of size at least 8
      `byteOrder` - the byte-order for interpreting the input bytes
    Returns:
      an eight-byte signed integer

  - ### toLongs

    public static long[] toLongs(byte[] bytes, ByteOrder byteOrder)
    Extracts an array of eight-byte long integers from the specified array of bytes. The size of the result array is computed based on the size of the input byte array.
    Parameters:
      `bytes` - a valid array
      `byteOrder` - the byte-order for interpreting the input bytes
    Returns:
      an array of zero or more eight-byte signed integers

  - ### toRational

    public static RationalNumber toRational(byte[] bytes, ByteOrder byteOrder, boolean unsignedType)
    Interprets the content of a specified bytes array to create an instance of the RationalNumber class.
    Parameters:
      `bytes` - a valid array dimensioned to at least 8.
      `byteOrder` - the byte order for integer conversion
      `unsignedType` - indicates whether the extracted value is an unsigned type.
    Returns:
      a valid instance

  - ### toRationals

    public static RationalNumber[] toRationals(byte[] bytes, ByteOrder byteOrder, boolean unsignedType)

  - ### toShort

    public static short toShort(byte[] bytes, ByteOrder byteOrder)

  - ### toShorts

    public static short[] toShorts(byte[] bytes, ByteOrder byteOrder)

  - ### toUInt16

    public static int toUInt16(byte[] bytes, ByteOrder byteOrder)

  - ### toUInt16

    public static int toUInt16(byte[] bytes, int offset, ByteOrder byteOrder)

  - ### toUInt16s

    public static int[] toUInt16s(byte[] bytes, ByteOrder byteOrder)