Class Bytes
- java.lang.Object
-
- com.datastax.driver.core.utils.Bytes
-
public final class Bytes extends Object
Simple utility methods to make working with bytes (blob) easier.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static ByteBufferfromHexString(String str)Parse an hex string representing a CQL blob.static byte[]fromRawHexString(String str, int strOffset)Converts a CQL hex string representation into a byte array.static byte[]getArray(ByteBuffer bytes)Extract the content of the providedByteBufferas a byte array.static StringtoHexString(byte[] byteArray)Converts a blob to its CQL hex string representation.static StringtoHexString(ByteBuffer bytes)Converts a blob to its CQL hex string representation.static StringtoRawHexString(ByteBuffer bytes)Converts a blob to its CQL hex string representation.
-
-
-
Method Detail
-
toHexString
public static String toHexString(ByteBuffer bytes)
Converts a blob to its CQL hex string representation.A CQL blob string representation consist of the hexadecimal representation of the blob bytes prefixed by "0x".
- Parameters:
bytes- the blob/bytes to convert to a string.- Returns:
- the CQL string representation of
bytes. Ifbytesisnull, this method returnsnull.
-
toRawHexString
public static String toRawHexString(ByteBuffer bytes)
Converts a blob to its CQL hex string representation.A CQL blob string representation consist of the hexadecimal representation of the blob bytes.
- Parameters:
bytes- the blob/bytes to convert to a string.- Returns:
- the CQL string representation of
bytes. Ifbytesisnull, this method returnsnull.
-
toHexString
public static String toHexString(byte[] byteArray)
Converts a blob to its CQL hex string representation.A CQL blob string representation consist of the hexadecimal representation of the blob bytes prefixed by "0x".
- Parameters:
byteArray- the blob/bytes array to convert to a string.- Returns:
- the CQL string representation of
bytes. Ifbytesisnull, this method returnsnull.
-
fromHexString
public static ByteBuffer fromHexString(String str)
Parse an hex string representing a CQL blob.The input should be a valid representation of a CQL blob, i.e. it must start by "0x" followed by the hexadecimal representation of the blob bytes.
- Parameters:
str- the CQL blob string representation to parse.- Returns:
- the bytes corresponding to
str. Ifstrisnull, this method returnsnull. - Throws:
IllegalArgumentException- ifstris not a valid CQL blob string.
-
getArray
public static byte[] getArray(ByteBuffer bytes)
Extract the content of the providedByteBufferas a byte array.This method work with any type of
ByteBuffer(direct and non-direct ones), but when theByteBufferis backed by an array, this method will try to avoid copy when possible. As a consequence, changes to the returned byte array may or may not reflect into the initialByteBuffer.- Parameters:
bytes- the buffer whose content to extract.- Returns:
- a byte array with the content of
bytes. That array may be the array backingbytesif this can avoid a copy.
-
fromRawHexString
public static byte[] fromRawHexString(String str, int strOffset)
Converts a CQL hex string representation into a byte array.A CQL blob string representation consist of the hexadecimal representation of the blob bytes.
- Parameters:
str- the string converted in hex representation.strOffset- he offset for starting the string conversion- Returns:
- the byte array which the String was representing.
-
-