public class IOUtils extends Object
| Constructor and Description |
|---|
IOUtils() |
| Modifier and Type | Method and Description |
|---|---|
static String |
bytesToString(byte[] bytes,
int offset,
int length) |
static int |
compareTo(byte[] bytes1,
byte[] bytes2)
Lexicographically compares two byte arrays.
|
static int |
compareTo(byte[] bytes1,
int offset1,
int length1,
byte[] bytes2,
int offset2,
int length2)
Lexicographically compares two byte arrays.
|
static byte[] |
copy(byte[] bytes,
int offset,
int length) |
static void |
copy(InputStream inputStream,
OutputStream outputStream) |
static int |
decodeVarLongSize(byte value)
Parses the first byte of a variable-length encoded number (integer or long value) to determine
total number of bytes representing the number on disk.
|
static int |
decodeVarLongSizeOnDisk(byte[] bytes,
int offset)
Parses the first byte of a variable-length encoded number (integer or long value) to determine
total number of bytes representing the number on disk.
|
static DataInputStream |
getDataInputStream(ByteBuffer byteBuffer) |
static int |
hashCode(byte[] bytes,
int offset,
int length) |
static int |
indexOf(byte[] array,
byte[] target)
Returns the start position of the first occurrence of the specified
target within array, or -1 if there is no such occurrence. |
static boolean |
isNegativeVarLong(byte value)
Given the first byte of a variable-length encoded number, determines the sign.
|
static byte[] |
readAsByteArray(InputStream input,
int outputSize) |
static int |
readFully(InputStream inputStream,
byte[] targetByteArray,
int offset,
int length)
Reads the data fully from the
InputStream to the byte array. |
static int |
readInt(byte[] bytes,
int offset)
Reads four bytes starting from the offset in the input and returns
int value. |
static long |
readLong(byte[] bytes,
int offset)
Reads eight bytes starting from the offset in the input and returns
long value. |
static short |
readShort(byte[] bytes,
int offset)
Reads two bytes starting from the offset in the input and returns
short value. |
static long |
readVarLong(byte[] bytes,
int offset)
Reads a variable-length encoded number from input bytes and returns it.
|
static long |
readVarLong(byte[] bytes,
int offset,
int varLongSizeOnDisk)
Reads a variable-length encoded number from input bytes and the decoded size on disk,
and returns it.
|
static byte[] |
toBytes(ByteBuffer buf)
Returns a new byte array, copied from the given
buf, from the index 0 (inclusive)
to the limit (exclusive), regardless of the current position. |
static byte[] |
toBytes(int val)
Converts an int value to a byte array using big-endian.
|
static byte[] |
toBytes(long val)
Converts a long value to a byte array using big-endian.
|
public static int readInt(byte[] bytes,
int offset)
int value.bytes - input byte array.offset - offset to start reading.int value.public static long readLong(byte[] bytes,
int offset)
long value.bytes - input byte array.offset - offset to start reading.long value.public static short readShort(byte[] bytes,
int offset)
short value.bytes - input byte array.offset - offset to start reading.short value.public static int decodeVarLongSizeOnDisk(byte[] bytes,
int offset)
bytes - input byte array of the encoded number.offset - offset to start reading.public static int decodeVarLongSize(byte value)
value - the first byte of the encoded number.public static long readVarLong(byte[] bytes,
int offset)
bytes - input byte array.offset - offset to start reading.long from the input.public static long readVarLong(byte[] bytes,
int offset,
int varLongSizeOnDisk)
bytes - input byte array.offset - offset to start reading.varLongSizeOnDisk - the total number of bytes (1 to 9) on disk.long from the input.public static boolean isNegativeVarLong(byte value)
value - the first byte.public static byte[] copy(byte[] bytes,
int offset,
int length)
bytes - input byte array.offset - offset to start reading.length - length of bytes to copy.public static int compareTo(byte[] bytes1,
byte[] bytes2)
bytes1 - left operand.bytes2 - right operand.public static int compareTo(byte[] bytes1,
int offset1,
int length1,
byte[] bytes2,
int offset2,
int length2)
bytes1 - left operand.bytes2 - right operand.offset1 - where to start comparing in the left buffer.offset2 - where to start comparing in the right buffer.length1 - how much to compare from the left buffer.length2 - how much to compare from the right buffer.public static int indexOf(byte[] array,
byte[] target)
target within array, or -1 if there is no such occurrence.
More formally, returns the lowest index i such that the range
[i, i + target.length) in array contains exactly the same elements
as target.
array - the array to search for the sequence target.target - the array to search for as a sub-sequence of array.-1 if there is no such occurrence.public static String bytesToString(byte[] bytes, int offset, int length)
bytes - input byte array.offset - offset to start reading.length - length of bytes to read.String value based on the byte array.public static byte[] toBytes(int val)
val - value to convert.public static byte[] toBytes(long val)
val - value to convert.public static int hashCode(byte[] bytes,
int offset,
int length)
bytes - byte array to hash.offset - offset to start hashing.length - length of bytes to hash.public static int readFully(InputStream inputStream, byte[] targetByteArray, int offset, int length) throws IOException
InputStream to the byte array.inputStream - InputStream containing the data.targetByteArray - target byte array.offset - offset in the target byte array to start to write data.length - maximum amount of data to write.IOException - upon error.public static byte[] readAsByteArray(InputStream input, int outputSize) throws IOException
IOExceptionpublic static void copy(InputStream inputStream, OutputStream outputStream) throws IOException
IOExceptionpublic static DataInputStream getDataInputStream(ByteBuffer byteBuffer)
byteBuffer - ByteBuffer containing the bytes.DataInputStream based on the byte buffer.public static byte[] toBytes(ByteBuffer buf)
buf, from the index 0 (inclusive)
to the limit (exclusive), regardless of the current position.
The position and the other index parameters are not changed.buf - a byte buffer.Copyright © 2024 The Apache Software Foundation. All rights reserved.