|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.mina.proxy.utils.ByteUtilities
public class ByteUtilities
ByteUtilities.java - Byte manipulation functions.
Constructor Summary | |
---|---|
ByteUtilities()
|
Method Summary | |
---|---|
static byte[] |
asByteArray(String hex)
Converts a hex string representation to a byte array. |
static String |
asHex(byte[] bytes)
Returns a hexadecimal representation of the given byte array. |
static String |
asHex(byte[] bytes,
String separator)
Returns a hexadecimal representation of the given byte array. |
static void |
changeByteEndianess(byte[] b,
int offset,
int length)
Invert two bytes in the given byte array starting at the given offset and repeating the inversion length/2 times. |
static void |
changeWordEndianess(byte[] b,
int offset,
int length)
Invert the endianness of words (4 bytes) in the given byte array starting at the given offset and repeating length/4 times. |
static byte[] |
encodeString(String s,
boolean useUnicode)
Encodes the string to a byte array using UTF-16LE or the ASCII charset in function of the useUnicode argument. |
static byte[] |
getOEMStringAsByteArray(String s)
Converts an OEM string as defined in NTLM protocol (eg ASCII charset) to a byte array. |
static byte[] |
getUTFStringAsByteArray(String s)
Converts an UTF-16LE string as defined in NTLM protocol to a byte array. |
static void |
intToNetworkByteOrder(int num,
byte[] buf,
int start,
int count)
Encodes an integer into up to 4 bytes in network byte order in the supplied buffer starting at start offset and writing
count bytes. |
static byte[] |
intToNetworkByteOrder(int num,
int count)
Encodes an integer into up to 4 bytes in network byte order. |
static boolean |
isFlagSet(int flagSet,
int testFlag)
Returns true if the flag testFlag is set in the
flags flagset. |
static int |
makeIntFromByte2(byte[] b)
Reads an int from 2 bytes of the given array at offset 0. |
static int |
makeIntFromByte2(byte[] b,
int offset)
Reads an int from 2 bytes of the given array at the given offset. |
static int |
makeIntFromByte4(byte[] b)
Reads an int from 4 bytes of the given array at offset 0. |
static int |
makeIntFromByte4(byte[] b,
int offset)
Reads an int from 4 bytes of the given array at the given offset. |
static int |
networkByteOrderToInt(byte[] buf,
int start,
int count)
Returns the integer represented by up to 4 bytes in network byte order. |
static byte[] |
writeInt(int v)
Write a 32 bit int as LITTLE_ENDIAN. |
static byte[] |
writeInt(int v,
byte[] b,
int offset)
Write a 32 bit int as LITTLE_ENDIAN to the given array b at offset offset . |
static byte[] |
writeShort(short v)
Write a 16 bit short as LITTLE_ENDIAN. |
static byte[] |
writeShort(short v,
byte[] b,
int offset)
Write a 16 bit short as LITTLE_ENDIAN to the given array b at offset offset . |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ByteUtilities()
Method Detail |
---|
public static int networkByteOrderToInt(byte[] buf, int start, int count)
buf
- the buffer to read the bytes fromstart
- count
-
public static byte[] intToNetworkByteOrder(int num, int count)
num
- the int to convert to a byte arraycount
- the number of reserved bytes for the write operation
public static void intToNetworkByteOrder(int num, byte[] buf, int start, int count)
start
offset and writing
count
bytes.
num
- the int to convert to a byte arraybuf
- the buffer to write the bytes tostart
- the offset from beginning for the write operationcount
- the number of reserved bytes for the write operationpublic static final byte[] writeShort(short v)
v
- the short to writepublic static final byte[] writeShort(short v, byte[] b, int offset)
b
at offset offset
.
v
- the short to writeb
- the byte array to write tooffset
- the offset at which to start writing in the arraypublic static final byte[] writeInt(int v)
v
- the int to writepublic static final byte[] writeInt(int v, byte[] b, int offset)
b
at offset offset
.
v
- the int to writeb
- the byte array to write tooffset
- the offset at which to start writing in the arraypublic static final void changeWordEndianess(byte[] b, int offset, int length)
b
- the byte arrayoffset
- the offset at which to change word startlength
- the number of bytes on which to operate
(should be a multiple of 4)public static final void changeByteEndianess(byte[] b, int offset, int length)
b
- the byte arrayoffset
- the offset at which to change word startlength
- the number of bytes on which to operate
(should be a multiple of 2)public static final byte[] getOEMStringAsByteArray(String s) throws UnsupportedEncodingException
s
- the string to convert
UnsupportedEncodingException
- if the string is not an OEM stringpublic static final byte[] getUTFStringAsByteArray(String s) throws UnsupportedEncodingException
s
- the string to convert
UnsupportedEncodingException
- if the string is not an UTF-16LE stringpublic static final byte[] encodeString(String s, boolean useUnicode) throws UnsupportedEncodingException
useUnicode
argument.
s
- the string to encodeuseUnicode
- if true then string is encoded to UTF-16LE
otherwise to ASCII
UnsupportedEncodingException
- if encoding failspublic static String asHex(byte[] bytes)
bytes
- the array to output to an hex string
public static String asHex(byte[] bytes, String separator)
bytes
- the array to output to an hex stringseparator
- the separator to use between each byte in the output
string. If null no char is inserted between each byte value.
public static byte[] asByteArray(String hex)
hex
- the string holding the hex values
public static final int makeIntFromByte4(byte[] b)
b
- the byte array to readoffset
- the offset at which to start
public static final int makeIntFromByte4(byte[] b, int offset)
b
- the byte array to readoffset
- the offset at which to start
public static final int makeIntFromByte2(byte[] b)
b
- the byte array to read
public static final int makeIntFromByte2(byte[] b, int offset)
b
- the byte array to readoffset
- the offset at which to start
public static final boolean isFlagSet(int flagSet, int testFlag)
testFlag
is set in the
flags
flagset.
flagset
- the flagset to testtestFlag
- the flag we search the presence of
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |