Class Util

java.lang.Object
de.pottgames.tuningfork.decoder.util.Util

public class Util extends Object
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static int
    intOfBigEndianBytes(byte[] source, int offset)
    Converts a sequence of 4 bytes from the specified source array, starting at the specified offset, into an int value representing a signed integer using big-endian byte order.
    static int
    intOfLittleEndianBytes(byte[] source, int offset)
    Converts a sequence of 4 bytes from the specified source array, starting at the specified offset, into an int value representing a signed integer using little-endian byte order.
    static boolean
    isEven(int number)
     
    static boolean
    isEven(long number)
     
    static boolean
    isOdd(int number)
     
    static boolean
    isOdd(long number)
     
    static int
    lastPowerOfTwo(int number)
    Returns the next lower power of two.
    static int
    limit(int value, int limit)
    Clamps a value to the given limit.
    static long
    longOfBigEndianBytes(byte[] source, int offset)
    Converts a sequence of 8 bytes from the specified source array, starting at the specified offset, into a long value using big-endian byte order.
    static long
    longOfLittleEndianBytes(byte[] source, int offset)
    Converts a sequence of 8 bytes from the specified source array, starting at the specified offset, into a long value using little-endian byte order.
    static int
    nextPowerOfTwo(int number)
    Returns the next higher power of two.
    static int
    readAll(InputStream stream, byte[] output, int limit)
    Reads bytes from the provided input stream into the given output buffer, up to the specified limit.
    This method attempts to read bytes from the input stream into the output buffer until either the specified limit is reached or the end of the input stream is encountered.
    static byte[]
    Fully reads an InputStream and returns its data as an array of bytes.
    static long
    uIntOfBigEndianBytes(byte[] source, int offset)
    Converts a sequence of 4 bytes from the specified source array, starting at the specified offset, into a long value representing an unsigned integer using big-endian byte order.

    Methods inherited from class Object

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

    • Util

      public Util()
  • Method Details

    • isOdd

      public static boolean isOdd(int number)
    • isOdd

      public static boolean isOdd(long number)
    • isEven

      public static boolean isEven(int number)
    • isEven

      public static boolean isEven(long number)
    • nextPowerOfTwo

      public static int nextPowerOfTwo(int number)
      Returns the next higher power of two. If number is negative, 1 is returned.
      Parameters:
      number - the number
      Returns:
      the next power of two
    • lastPowerOfTwo

      public static int lastPowerOfTwo(int number)
      Returns the next lower power of two. If the number is negative, 1 is returned.
      Parameters:
      number - the number
      Returns:
      the next lower power of two
    • toByteArray

      public static byte[] toByteArray(InputStream stream) throws IOException
      Fully reads an InputStream and returns its data as an array of bytes.
      Parameters:
      stream - the InputStream
      Returns:
      a byte array that contains the data of the stream
      Throws:
      IOException - IOException
    • readAll

      public static int readAll(InputStream stream, byte[] output, int limit) throws IOException
      Reads bytes from the provided input stream into the given output buffer, up to the specified limit.
      This method attempts to read bytes from the input stream into the output buffer until either the specified limit is reached or the end of the input stream is encountered.
      Parameters:
      stream - The input stream to read from.
      output - The byte array to store the read data into.
      limit - The maximum number of bytes to read.
      Returns:
      The total number of bytes read from the input stream and stored in the output buffer.
      Throws:
      IOException - If an I/O error occurs while reading from the input stream.
    • longOfBigEndianBytes

      public static long longOfBigEndianBytes(byte[] source, int offset)
      Converts a sequence of 8 bytes from the specified source array, starting at the specified offset, into a long value using big-endian byte order.
      Parameters:
      source - The source byte array.
      offset - The starting offset in the source array.
      Returns:
      The long value converted from the specified bytes in big-endian byte order.
    • longOfLittleEndianBytes

      public static long longOfLittleEndianBytes(byte[] source, int offset)
      Converts a sequence of 8 bytes from the specified source array, starting at the specified offset, into a long value using little-endian byte order.
      Parameters:
      source - The source byte array.
      offset - The starting offset in the source array.
      Returns:
      The long value converted from the specified bytes in little-endian byte order.
    • uIntOfBigEndianBytes

      public static long uIntOfBigEndianBytes(byte[] source, int offset)
      Converts a sequence of 4 bytes from the specified source array, starting at the specified offset, into a long value representing an unsigned integer using big-endian byte order.
      Parameters:
      source - The source byte array.
      offset - The starting offset in the source array.
      Returns:
      The long value representing the unsigned integer from the specified bytes in big-endian order.
    • intOfBigEndianBytes

      public static int intOfBigEndianBytes(byte[] source, int offset)
      Converts a sequence of 4 bytes from the specified source array, starting at the specified offset, into an int value representing a signed integer using big-endian byte order.
      Parameters:
      source - The source byte array.
      offset - The starting offset in the source array.
      Returns:
      The int value representing the signed integer from the specified bytes in big-endian byte order.
    • intOfLittleEndianBytes

      public static int intOfLittleEndianBytes(byte[] source, int offset)
      Converts a sequence of 4 bytes from the specified source array, starting at the specified offset, into an int value representing a signed integer using little-endian byte order.
      Parameters:
      source - The source byte array.
      offset - The starting offset in the source array.
      Returns:
      The int value representing the signed integer from the specified bytes in little-endian byte order.
    • limit

      public static int limit(int value, int limit)
      Clamps a value to the given limit.
      Parameters:
      value - the value
      limit - the limit
      Returns:
      the result