Class Util
java.lang.Object
de.pottgames.tuningfork.decoder.util.Util
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic intintOfBigEndianBytes(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 intintOfLittleEndianBytes(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 booleanisEven(int number) static booleanisEven(long number) static booleanisOdd(int number) static booleanisOdd(long number) static intlastPowerOfTwo(int number) Returns the next lower power of two.static intlimit(int value, int limit) Clamps a value to the given limit.static longlongOfBigEndianBytes(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 longlongOfLittleEndianBytes(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 intnextPowerOfTwo(int number) Returns the next higher power of two.static intreadAll(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[]toByteArray(InputStream stream) Fully reads an InputStream and returns its data as an array of bytes.static longuIntOfBigEndianBytes(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.
-
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
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
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 valuelimit- the limit- Returns:
- the result
-