Class ByteUtils
java.lang.Object
org.apache.commons.compress.utils.ByteUtils
Utility methods for reading and writing bytes.
- Since:
- 1.14
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
Used to consume bytes.static interface
Used to supply bytes.static class
Deprecated.Unusedstatic class
ByteUtils.ByteConsumer
based onOutputStream
. -
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic long
fromLittleEndian
(byte[] bytes) Reads the given byte array as a little-endian long.static long
fromLittleEndian
(byte[] bytes, int off, int length) Reads the given byte array as a little-endian long.static long
fromLittleEndian
(DataInput in, int length) Reads the given number of bytes from the given input as little-endian long.static long
fromLittleEndian
(InputStream in, int length) Deprecated.Unusedstatic long
fromLittleEndian
(ByteUtils.ByteSupplier supplier, int length) Reads the given number of bytes from the given supplier as a little-endian long.static void
toLittleEndian
(byte[] b, long value, int off, int length) Inserts the given value into the array as a little-endian sequence of the given length starting at the given offset.static void
toLittleEndian
(DataOutput out, long value, int length) Deprecated.Unusedstatic void
toLittleEndian
(OutputStream out, long value, int length) Writes the given value to the given stream as a little-endian array of the given length.static void
toLittleEndian
(ByteUtils.ByteConsumer consumer, long value, int length) Provides the given value to the given consumer as a little-endian sequence of the given length.
-
Field Details
-
EMPTY_BYTE_ARRAY
Empty array.- Since:
- 1.21
-
-
Method Details
-
fromLittleEndian
Reads the given byte array as a little-endian long.- Parameters:
bytes
- the byte array to convert- Returns:
- the number read
-
fromLittleEndian
Reads the given byte array as a little-endian long.- Parameters:
bytes
- the byte array to convertoff
- the offset into the array that starts the valuelength
- the number of bytes representing the value- Returns:
- the number read
- Throws:
IllegalArgumentException
- if len is bigger than eight
-
fromLittleEndian
Reads the given number of bytes from the given supplier as a little-endian long.Typically used by our InputStreams that need to count the bytes read as well.
- Parameters:
supplier
- the supplier for byteslength
- the number of bytes representing the value- Returns:
- the number read
- Throws:
IllegalArgumentException
- if len is bigger than eightIOException
- if the supplier fails or doesn't supply the given number of bytes anymore
-
fromLittleEndian
Reads the given number of bytes from the given input as little-endian long.- Parameters:
in
- the input to read fromlength
- the number of bytes representing the value- Returns:
- the number read
- Throws:
IllegalArgumentException
- if len is bigger than eightIOException
- if reading fails or the stream doesn't contain the given number of bytes anymore
-
fromLittleEndian
Deprecated.UnusedReads the given number of bytes from the given stream as a little-endian long.- Parameters:
in
- the stream to read fromlength
- the number of bytes representing the value- Returns:
- the number read
- Throws:
IllegalArgumentException
- if len is bigger than eightIOException
- if reading fails or the stream doesn't contain the given number of bytes anymore
-
toLittleEndian
Inserts the given value into the array as a little-endian sequence of the given length starting at the given offset.- Parameters:
b
- the array to write intovalue
- the value to insertoff
- the offset into the array that receives the first bytelength
- the number of bytes to use to represent the value
-
toLittleEndian
public static void toLittleEndian(ByteUtils.ByteConsumer consumer, long value, int length) throws IOException Provides the given value to the given consumer as a little-endian sequence of the given length.- Parameters:
consumer
- the consumer to provide the bytes tovalue
- the value to providelength
- the number of bytes to use to represent the value- Throws:
IOException
- if writing fails
-
toLittleEndian
@Deprecated public static void toLittleEndian(DataOutput out, long value, int length) throws IOException Deprecated.UnusedWrites the given value to the given stream as a little-endian array of the given length.- Parameters:
out
- the output to write tovalue
- the value to writelength
- the number of bytes to use to represent the value- Throws:
IOException
- if writing fails
-
toLittleEndian
Writes the given value to the given stream as a little-endian array of the given length.- Parameters:
out
- the stream to write tovalue
- the value to writelength
- the number of bytes to use to represent the value- Throws:
IOException
- if writing fails
-