Package org.apache.jena.atlas.lib
Class Bytes
- java.lang.Object
-
- org.apache.jena.atlas.lib.Bytes
-
public class Bytes extends java.lang.ObjectByte-oriented operations. Packing and unpacking integers is in network order (Big endian - which is the preferred order in Java). See wikipedia Endianness.
-
-
Field Summary
Fields Modifier and Type Field Description static byte[]hexDigitsLCstatic byte[]hexDigitsUC
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.StringasHex(byte b)Return a hex string representing the byte.static java.lang.StringasHex(byte[] bytes)Return a hex string representing the bytes, zero padded to length of byte array.static java.lang.StringasHex(byte[] bytes, int start, int finish, char[] hexDigits)static java.lang.StringasHexLC(byte b)static java.lang.StringasHexLC(byte[] bytes)static java.lang.StringasHexUC(byte b)static java.lang.StringasHexUC(byte[] bytes)static java.lang.Stringbytes2string(byte[] x)Return the string for some UTF-8 bytesstatic intcompare(byte[] x1, byte[] x2)Compare two byte arrays which may be of different lengthsstatic intcompareByte(byte b1, byte b2)static byte[]copyOf(byte[] bytes)static byte[]copyOf(byte[] bytes, int start)static byte[]copyOf(byte[] bytes, int start, int length)static java.lang.StringfromByteBuffer(java.nio.ByteBuffer bb)Decode a string into a ByteBufferstatic java.lang.StringfromByteBuffer(java.nio.ByteBuffer bb, java.nio.charset.CharsetDecoder dec)Decode a string into a ByteBufferstatic intgetInt(byte[] b)Get an int from a byte array (network order)static intgetInt(byte[] b, int idx)Get an int from a byte array (network order)static longgetLong(byte[] b)Get a long from a byte array (network order)static longgetLong(byte[] b, int idx)Get a long from a byte array (network order)static inthexCharToInt(char c)static byte[]intToBytes(int v)Put an int value into an allocated byte array.static byte[]longToBytes(long v)Put a long value into an allocated byte array.static byte[]packInt(int val)int to byte arraystatic byte[]packLong(long val)long to byte arraystatic voidsetInt(int value, byte[] b)Put an int into a byte arraystatic voidsetInt(int x, byte[] b, int idx)Put an int into a byte array from a given positionstatic voidsetLong(long value, byte[] b)Put a long into a byte arraystatic voidsetLong(long value, byte[] b, int idx)Put a long into a byte array from a given positionstatic byte[]string2bytes(java.lang.String x)Return the UTF-8 bytes for a stringstatic inttoByteBuffer(java.lang.CharSequence s, java.nio.ByteBuffer bb)Encode a string into a ByteBuffer : on return position is the end of the encodingstatic inttoByteBuffer(java.lang.CharSequence s, java.nio.ByteBuffer bb, java.nio.charset.CharsetEncoder enc)Encode a string into a ByteBuffer : on return position is the end of the encoding
-
-
-
Method Detail
-
compare
public static int compare(byte[] x1, byte[] x2)Compare two byte arrays which may be of different lengths
-
compareByte
public static int compareByte(byte b1, byte b2)
-
copyOf
public static byte[] copyOf(byte[] bytes)
-
copyOf
public static byte[] copyOf(byte[] bytes, int start)
-
copyOf
public static byte[] copyOf(byte[] bytes, int start, int length)
-
intToBytes
public static byte[] intToBytes(int v)
Put an int value into an allocated byte array.- Parameters:
v-- Returns:
- byte[] array
- See Also:
Integer.SIZE
-
longToBytes
public static byte[] longToBytes(long v)
Put a long value into an allocated byte array.- Parameters:
v-- Returns:
- byte[] array
- See Also:
Long.SIZE
-
getInt
public static final int getInt(byte[] b)
Get an int from a byte array (network order)- Parameters:
b- Byte Array
-
getInt
public static final int getInt(byte[] b, int idx)Get an int from a byte array (network order)- Parameters:
b- Byte Arrayidx- Starting point of bytes
-
getLong
public static final long getLong(byte[] b)
Get a long from a byte array (network order)- Parameters:
b- Byte Array
-
getLong
public static final long getLong(byte[] b, int idx)Get a long from a byte array (network order)- Parameters:
b- Byte Arrayidx- Starting point of bytes
-
setInt
public static final void setInt(int value, byte[] b)Put an int into a byte array- Parameters:
value- The integerb- byte array
-
setInt
public static final void setInt(int x, byte[] b, int idx)Put an int into a byte array from a given position- Parameters:
x- The integerb- byte arrayidx- starting point
-
setLong
public static final void setLong(long value, byte[] b)Put a long into a byte array- Parameters:
value- The integerb- byte array
-
setLong
public static final void setLong(long value, byte[] b, int idx)Put a long into a byte array from a given position- Parameters:
value- The integerb- byte arrayidx- starting point
-
packInt
public static byte[] packInt(int val)
int to byte array
-
packLong
public static byte[] packLong(long val)
long to byte array
-
string2bytes
public static byte[] string2bytes(java.lang.String x)
Return the UTF-8 bytes for a string
-
bytes2string
public static java.lang.String bytes2string(byte[] x)
Return the string for some UTF-8 bytes
-
toByteBuffer
public static int toByteBuffer(java.lang.CharSequence s, java.nio.ByteBuffer bb)Encode a string into a ByteBuffer : on return position is the end of the encoding
-
toByteBuffer
public static int toByteBuffer(java.lang.CharSequence s, java.nio.ByteBuffer bb, java.nio.charset.CharsetEncoder enc)Encode a string into a ByteBuffer : on return position is the end of the encoding
-
fromByteBuffer
public static java.lang.String fromByteBuffer(java.nio.ByteBuffer bb)
Decode a string into a ByteBuffer
-
fromByteBuffer
public static java.lang.String fromByteBuffer(java.nio.ByteBuffer bb, java.nio.charset.CharsetDecoder dec)Decode a string into a ByteBuffer
-
asHex
public static java.lang.String asHex(byte[] bytes)
Return a hex string representing the bytes, zero padded to length of byte array.
-
asHexUC
public static java.lang.String asHexUC(byte[] bytes)
-
asHexLC
public static java.lang.String asHexLC(byte[] bytes)
-
asHex
public static java.lang.String asHex(byte[] bytes, int start, int finish, char[] hexDigits)
-
asHex
public static java.lang.String asHex(byte b)
Return a hex string representing the byte.
-
asHexUC
public static java.lang.String asHexUC(byte b)
-
asHexLC
public static java.lang.String asHexLC(byte b)
-
hexCharToInt
public static int hexCharToInt(char c)
-
-