|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectvoldemort.utils.ByteUtils
public class ByteUtils
Utility functions for munging on bytes
| Field Summary | |
|---|---|
static int |
MASK_00000000
|
static int |
MASK_00011111
|
static int |
MASK_00111111
|
static int |
MASK_01000000
|
static int |
MASK_01011111
|
static int |
MASK_01100000
|
static int |
MASK_01101111
|
static int |
MASK_01110000
|
static int |
MASK_01111111
|
static int |
MASK_10000000
|
static int |
MASK_10111111
|
static int |
MASK_11000000
|
static int |
MASK_11011111
|
static int |
MASK_11100000
|
static int |
MASK_11111111
|
static int |
SIZE_OF_BYTE
|
static int |
SIZE_OF_INT
|
static int |
SIZE_OF_LONG
|
static int |
SIZE_OF_SHORT
|
| Constructor Summary | |
|---|---|
ByteUtils()
|
|
| Method Summary | |
|---|---|
static byte[] |
cat(byte[]... arrays)
Concatenate the given arrays TODO: cut and paste for every primative type and Object (yay! java!) |
static int |
compare(byte[] b1,
byte[] b2)
Compare two byte arrays. |
static int |
compare(byte[] b1,
byte[] b2,
int offset,
int to)
Compare a byte array ( b1 ) with a sub |
static byte[] |
copy(byte[] array,
int from,
int to)
Copy the specified bytes into a new array |
static java.nio.ByteBuffer |
expand(java.nio.ByteBuffer buffer,
int newCapacity)
If we have no more room in the current buffer, then double our capacity and copy the current buffer to the new one. |
static byte[] |
getBytes(java.lang.String string,
java.lang.String encoding)
Translate the string to bytes using the given encoding |
static java.security.MessageDigest |
getDigest(java.lang.String algorithm)
|
static java.lang.String |
getString(byte[] bytes,
java.lang.String encoding)
Create a string from bytes using the given encoding |
static byte[] |
md5(byte[] input)
Compute the md5 hash of the input catching all the irritating exceptions for you |
static byte |
numberOfBytesRequired(long number)
The number of bytes required to hold the given number |
static void |
read(java.io.InputStream stream,
byte[] buffer)
Read exactly buffer.length bytes from the stream into the buffer |
static long |
readBytes(byte[] bytes,
int offset,
int numBytes)
Read the given number of bytes into a long |
static int |
readInt(byte[] bytes,
int offset)
Read an int from the byte array starting at the given offset |
static long |
readLong(byte[] bytes,
int offset)
Read a long from the byte array starting at the given offset |
static byte |
readNthByte(long l,
int n)
Get the nth byte from the right in the given number |
static short |
readShort(byte[] bytes,
int offset)
Read a short from the byte array starting at the given offset |
static long |
readUnsignedInt(byte[] bytes,
int offset)
Read an unsigned integer from the given byte array |
static long |
readVarNumber(java.io.DataInputStream input)
|
static byte[] |
sha1(byte[] input)
Compute the sha1 hash of the input catching all the irritating exceptions for you |
static java.lang.String |
toBinaryString(byte[] bytes)
Translate the given byte array into a string of 1s and 0s |
static java.lang.String |
toHexString(byte[] bytes)
Translate the given byte array into a hexidecimal string |
static void |
writeBytes(byte[] bytes,
long value,
int offset,
int numBytes)
Write the given number of bytes out to the array |
static void |
writeInt(byte[] bytes,
int value,
int offset)
Write an int to the byte array starting at the given offset |
static void |
writeLong(byte[] bytes,
long value,
int offset)
Write a long to the byte array starting at the given offset |
static void |
writeShort(byte[] bytes,
short value,
int offset)
Write a short to the byte array starting at the given offset |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final int SIZE_OF_BYTE
public static final int SIZE_OF_SHORT
public static final int SIZE_OF_INT
public static final int SIZE_OF_LONG
public static final int MASK_00000000
public static final int MASK_10000000
public static final int MASK_11000000
public static final int MASK_11100000
public static final int MASK_10111111
public static final int MASK_11011111
public static final int MASK_01000000
public static final int MASK_01100000
public static final int MASK_01110000
public static final int MASK_01011111
public static final int MASK_01101111
public static final int MASK_11111111
public static final int MASK_01111111
public static final int MASK_00111111
public static final int MASK_00011111
| Constructor Detail |
|---|
public ByteUtils()
| Method Detail |
|---|
public static java.security.MessageDigest getDigest(java.lang.String algorithm)
public static java.lang.String toHexString(byte[] bytes)
bytes - The bytes to translate
public static java.lang.String toBinaryString(byte[] bytes)
bytes - The bytes to translate
public static byte[] cat(byte[]... arrays)
arrays - The arrays to concatenate
public static byte[] copy(byte[] array,
int from,
int to)
array - The array to copy fromfrom - The index in the array to begin copying fromto - The least index not copied
public static short readShort(byte[] bytes,
int offset)
bytes - The byte array to read fromoffset - The offset to start reading at
public static int readInt(byte[] bytes,
int offset)
bytes - The byte array to read fromoffset - The offset to start reading at
public static long readUnsignedInt(byte[] bytes,
int offset)
bytes - The bytes to read fromoffset - The offset to begin reading at
public static long readLong(byte[] bytes,
int offset)
bytes - The byte array to read fromoffset - The offset to start reading at
public static long readBytes(byte[] bytes,
int offset,
int numBytes)
bytes - The byte array to read fromoffset - The offset at which to begin readingnumBytes - The number of bytes to read
public static void writeShort(byte[] bytes,
short value,
int offset)
bytes - The byte arrayvalue - The short to writeoffset - The offset to begin writing at
public static void writeInt(byte[] bytes,
int value,
int offset)
bytes - The byte arrayvalue - The int to writeoffset - The offset to begin writing at
public static void writeLong(byte[] bytes,
long value,
int offset)
bytes - The byte arrayvalue - The long to writeoffset - The offset to begin writing at
public static void writeBytes(byte[] bytes,
long value,
int offset,
int numBytes)
bytes - The array to write tovalue - The value to write fromoffset - the offset into the arraynumBytes - The number of bytes to writepublic static byte numberOfBytesRequired(long number)
number - The number being checked.
public static long readVarNumber(java.io.DataInputStream input)
throws java.io.IOException
java.io.IOException
public static byte readNthByte(long l,
int n)
l - The number from which to extract the byten - The byte index
public static void read(java.io.InputStream stream,
byte[] buffer)
throws java.io.IOException
stream - The stream to read frombuffer - The buffer to read into
java.io.IOException
public static byte[] getBytes(java.lang.String string,
java.lang.String encoding)
string - The string to translateencoding - The encoding to use
public static java.lang.String getString(byte[] bytes,
java.lang.String encoding)
bytes - The bytes to create a string fromencoding - The encoding of the string
public static byte[] md5(byte[] input)
input - The input to take the hash of
public static byte[] sha1(byte[] input)
input - The input to take the hash of
public static int compare(byte[] b1,
byte[] b2)
bytes are considered unsigned. passing negative values into byte will cause them to be considered as unsigned two's complement value.
b1 - The first arrayb2 - The second array
public static int compare(byte[] b1,
byte[] b2,
int offset,
int to)
b1 - The first arrayb2 - The second arrayoffset - The offset in b2 from which to compareto - The least offset in b2 which we don't compare
public static java.nio.ByteBuffer expand(java.nio.ByteBuffer buffer,
int newCapacity)
buffer - The buffer from which to copy the contentsnewCapacity - The new capacity size
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||