public class ByteUtils extends Object
Modifier and Type | Field and Description |
---|---|
static int |
SIZEOF_BOOLEAN
Size of boolean in bytes
|
static int |
SIZEOF_BYTE
Size of byte in bytes
|
static int |
SIZEOF_CHAR
Size of char in bytes
|
static int |
SIZEOF_DOUBLE
Size of double in bytes
|
static int |
SIZEOF_FLOAT
Size of float in bytes
|
static int |
SIZEOF_INT
Size of int in bytes
|
static int |
SIZEOF_LONG
Size of long in bytes
|
static int |
SIZEOF_SHORT
Size of short in bytes
|
Constructor and Description |
---|
ByteUtils() |
Modifier and Type | Method and Description |
---|---|
static int |
bytesToVint(byte[] buffer)
Converts variable length byte array to it s int value representation.
|
static long |
bytesToVlong(byte[] buffer)
Converts variable length byte array to it s long value representation.
|
static int |
compareTo(byte[] left,
byte[] right)
Compare byte two byte arrays, and returns a int value accordingly.
|
static int |
compareTo(byte[] b1,
int s1,
int l1,
byte[] b2,
int s2,
int l2)
Compare byte two byte arrays given offset and length, and returns a int value accordingly.
|
static boolean |
equals(byte[] left,
byte[] right)
Compare byte two byte arrays for equality, and returns a boolean value accordingly.
|
static <T> T |
fromBytes(byte[] val,
org.apache.avro.Schema schema,
org.apache.avro.specific.SpecificDatumReader<T> datumReader,
T object) |
static int |
putByte(byte[] bytes,
int offset,
byte b)
Write a single byte out to the specified byte array position.
|
static int |
putBytes(byte[] tgtBytes,
int tgtOffset,
byte[] srcBytes,
int srcOffset,
int srcLength)
Put bytes at the specified byte array position.
|
static long |
readVLong(byte[] buffer,
int offset)
Reads a zero-compressed encoded long from input stream and returns it.
|
static boolean |
toBoolean(byte[] b)
Convert a byte array to it s boolean value.
|
static byte[] |
toBytes(boolean b)
Convert a boolean to a byte array.
|
static byte[] |
toBytes(ByteBuffer bb)
Returns a new byte array, copied from the passed ByteBuffer.
|
static byte[] |
toBytes(char val)
Convert a char value to a byte array.
|
static byte[] |
toBytes(double d)
Converts double value to byte array.
|
static byte[] |
toBytes(float f)
Converts float value to it s byte array representation.
|
static byte[] |
toBytes(int val)
Convert an int value to a byte array.
|
static byte[] |
toBytes(long val)
Convert a long value to a byte array.
|
static byte[] |
toBytes(short val)
Convert a short value to a byte array.
|
static byte[] |
toBytes(String s)
Converts a string to a UTF-8 byte array.
|
static <T> byte[] |
toBytes(T o,
org.apache.avro.Schema schema,
org.apache.avro.specific.SpecificDatumWriter<T> datumWriter) |
static char |
toChar(byte[] bytes)
Converts a byte array to a char value.
|
static char |
toChar(byte[] bytes,
int offset)
Converts a byte array to a char value.
|
static char |
toChar(byte[] bytes,
int offset,
int length)
Converts a byte array to a char value.
|
static char[] |
toChars(byte[] bytes)
Converts a byte array to a char array value.
|
static char[] |
toChars(byte[] bytes,
int offset)
Converts a byte array to a char array value.
|
static char[] |
toChars(byte[] bytes,
int offset,
int length)
Converts a byte array to a char array value.
|
static double |
toDouble(byte[] bytes)
Converts byte array to a double value.
|
static double |
toDouble(byte[] bytes,
int offset)
Converts byte array given offset to double value.
|
static float |
toFloat(byte[] bytes)
Presumes float encoded as IEEE 754 floating-point "single format".
|
static float |
toFloat(byte[] bytes,
int offset)
Presumes float encoded as IEEE 754 floating-point "single format".
|
static int |
toInt(byte[] bytes)
Converts a byte array to an int value.
|
static int |
toInt(byte[] bytes,
int offset)
Converts a byte array to an int value.
|
static int |
toInt(byte[] bytes,
int offset,
int length)
Converts a byte array to an int value.
|
static long |
toLong(byte[] bytes)
Converts a byte array to a long value.
|
static long |
toLong(byte[] bytes,
int offset)
Converts a byte array to a long value.
|
static long |
toLong(byte[] bytes,
int offset,
int length)
Converts a byte array to a long value.
|
static short |
toShort(byte[] bytes)
Converts a byte array to a short value.
|
static short |
toShort(byte[] bytes,
int offset)
Converts a byte array to a short value.
|
static short |
toShort(byte[] bytes,
int offset,
int length)
Converts a byte array to a short value.
|
static String |
toString(byte[] b)
Converts a byte array to it s String representation.
|
static String |
toString(byte[] b,
int off,
int len)
Converts byte array given offset and length to it s String representation.
|
static String |
toString(byte[] b1,
String sep,
byte[] b2)
Converts two byte array given a separator string in between to single String representation.
|
static byte[] |
vintToBytes(long vint)
Converts a int value to it s variable length byte array representation.
|
public static final int SIZEOF_BOOLEAN
public static final int SIZEOF_BYTE
public static final int SIZEOF_CHAR
public static final int SIZEOF_DOUBLE
public static final int SIZEOF_FLOAT
public static final int SIZEOF_INT
public static final int SIZEOF_LONG
public static final int SIZEOF_SHORT
public static int putBytes(byte[] tgtBytes, int tgtOffset, byte[] srcBytes, int srcOffset, int srcLength)
tgtBytes
- the byte array which source/input bytes are written.tgtOffset
- offset position in the array to be considered to write bytes.srcBytes
- source of byte to write out on target byte array.srcOffset
- offset of source byte array to be considered.srcLength
- length from offset of source byte array to be considered.public static int putByte(byte[] bytes, int offset, byte b)
bytes
- the byte array input.offset
- position in the array.b
- byte to write out.public static byte[] toBytes(ByteBuffer bb)
bb
- A ByteBuffer as input.bb
.public static String toString(byte[] b)
b
- Presumed UTF-8 encoded byte array.b
.public static String toString(byte[] b1, String sep, byte[] b2)
b1
- Presumed UTF-8 encoded byte array input 1.b2
- Presumed UTF-8 encoded byte array input 2.sep
- Separator String.b1
+sep
+b2
.public static String toString(byte[] b, int off, int len)
b
- Presumed UTF-8 encoded byte array.off
- offset to be from the input byte array.len
- length to be considered from the offset.b
.public static byte[] toBytes(String s)
s
- input String value.public static byte[] toBytes(boolean b)
b
- input boolean value.b
encoded in a byte array.public static boolean toBoolean(byte[] b)
b
- input byte array.public static byte[] toBytes(long val)
val
- input long value.public static long toLong(byte[] bytes)
bytes
- input byte array.public static long toLong(byte[] bytes, int offset)
bytes
- input byte array.offset
- offset to be from the input byte array.public static long toLong(byte[] bytes, int offset, int length)
bytes
- input byte array.offset
- offset to be from the input byte array.length
- length to be considered from the offset.public static float toFloat(byte[] bytes)
bytes
- offset to be considered from byte array.public static float toFloat(byte[] bytes, int offset)
bytes
- input byte array to be considered.offset
- offset to be considered from byte array.public static byte[] toBytes(float f)
f
- input float value.public static double toDouble(byte[] bytes)
bytes
- input byte array to be considered.public static double toDouble(byte[] bytes, int offset)
bytes
- input byte array.offset
- offset to be considered from input array.public static byte[] toBytes(double d)
d
- double input value.public static byte[] toBytes(int val)
val
- int input value.public static int toInt(byte[] bytes)
bytes
- input byte array to be converted.public static int toInt(byte[] bytes, int offset)
bytes
- input byte array.offset
- input byte array offset.public static int toInt(byte[] bytes, int offset, int length)
bytes
- input byte array.offset
- input byte array offset.length
- length from offset position.public static byte[] toBytes(short val)
val
- input short value.public static short toShort(byte[] bytes)
bytes
- input byte array.public static short toShort(byte[] bytes, int offset)
bytes
- input byte array.offset
- offset position of input array.public static short toShort(byte[] bytes, int offset, int length)
bytes
- input byte array.offset
- offset position from input byte array.length
- length to be considered from offset.public static byte[] toBytes(char val)
val
- input char value.public static char toChar(byte[] bytes)
bytes
- input bytes array.public static char toChar(byte[] bytes, int offset)
bytes
- input bytes array.offset
- offset to be considered from input array.public static char toChar(byte[] bytes, int offset, int length)
bytes
- input byte array.offset
- offset to be considered from input array.length
- length to be considered from offset.public static char[] toChars(byte[] bytes)
bytes
- input byte array.public static char[] toChars(byte[] bytes, int offset)
bytes
- input byte array.offset
- offset to be considered from input array.public static char[] toChars(byte[] bytes, int offset, int length)
bytes
- input byte array.offset
- offset to be considered from input array.length
- length to be considered from offset.public static byte[] vintToBytes(long vint)
vint
- Integer to make a vint of.public static long bytesToVlong(byte[] buffer)
buffer
- input byte array.public static int bytesToVint(byte[] buffer)
buffer
- input byte array.public static long readVLong(byte[] buffer, int offset) throws IOException
buffer
- Binary input array.offset
- Offset into array at which vint begins.IOException
- when read error occurs while extracting data from input stream.public static int compareTo(byte[] left, byte[] right)
left
- left byte array to be considered.right
- right byte array to be considered.public static int compareTo(byte[] b1, int s1, int l1, byte[] b2, int s2, int l2)
b1
- left byte array to be considered.b2
- right byte array to be considered.s1
- Where to start comparing in the left buffer.s2
- Where to start comparing in the right buffer.l1
- How much to compare from the left buffer.l2
- How much to compare from the right buffer.public static boolean equals(byte[] left, byte[] right)
left
- left byte array to be considered.right
- right byte array to be considered.public static <T> T fromBytes(byte[] val, org.apache.avro.Schema schema, org.apache.avro.specific.SpecificDatumReader<T> datumReader, T object) throws IOException
IOException
public static <T> byte[] toBytes(T o, org.apache.avro.Schema schema, org.apache.avro.specific.SpecificDatumWriter<T> datumWriter) throws IOException
IOException
Copyright © 2010-2017 The Apache Software Foundation. All Rights Reserved.