public class ByteUtilities
extends java.lang.Object
构造器和说明 |
---|
ByteUtilities() |
限定符和类型 | 方法和说明 |
---|---|
static byte[] |
asByteArray(java.lang.String hex)
Converts a hex string representation to a byte array.
|
static java.lang.String |
asHex(byte[] bytes)
Returns a hexadecimal representation of the given byte array.
|
static java.lang.String |
asHex(byte[] bytes,
java.lang.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(java.lang.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(java.lang.String s)
Converts an OEM string as defined in NTLM protocol (eg ASCII charset)
to a byte array.
|
static byte[] |
getUTFStringAsByteArray(java.lang.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 . |
public static int networkByteOrderToInt(byte[] buf, int start, int count)
buf
- the buffer to read the bytes fromstart
- The starting positioncount
- The number of bytes to in the bufferpublic static byte[] intToNetworkByteOrder(int num, int count)
num
- the int to convert to a byte arraycount
- the number of reserved bytes for the write operationpublic 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(java.lang.String s) throws java.io.UnsupportedEncodingException
s
- the string to convertjava.io.UnsupportedEncodingException
- if the string is not an OEM stringpublic static final byte[] getUTFStringAsByteArray(java.lang.String s) throws java.io.UnsupportedEncodingException
s
- the string to convertjava.io.UnsupportedEncodingException
- if the string is not an UTF-16LE stringpublic static final byte[] encodeString(java.lang.String s, boolean useUnicode) throws java.io.UnsupportedEncodingException
useUnicode
argument.s
- the string to encodeuseUnicode
- if true then string is encoded to UTF-16LE
otherwise to ASCIIjava.io.UnsupportedEncodingException
- if encoding failspublic static java.lang.String asHex(byte[] bytes)
bytes
- the array to output to an hex stringpublic static java.lang.String asHex(byte[] bytes, java.lang.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(java.lang.String hex)
hex
- the string holding the hex valuespublic static final int makeIntFromByte4(byte[] b)
b
- the byte array to readpublic static final int makeIntFromByte4(byte[] b, int offset)
b
- the byte array to readoffset
- the offset at which to startpublic static final int makeIntFromByte2(byte[] b)
b
- the byte array to readpublic static final int makeIntFromByte2(byte[] b, int offset)
b
- the byte array to readoffset
- the offset at which to startpublic 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