Class BinaryUtils
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]
Returns a copy of all the bytes from the givenByteBuffer
, from the beginning to the buffer's limit; or null if the input is null.static byte[]
Returns a copy of the bytes from the givenByteBuffer
, ranging from the the buffer's current position to the buffer's limit; or null if the input is null.static byte[]
fromBase64
(String b64Data) Converts a Base64-encoded string to the original byte data.static byte[]
Converts a Hex-encoded data string to the original byte data.static String
toBase64
(byte[] data) Converts byte data to a Base64-encoded string.static String
toHex
(byte[] data) Converts byte data to a Hex-encoded string in lower case.static ByteArrayInputStream
toStream
(ByteBuffer byteBuffer) Wraps a ByteBuffer in an InputStream.
-
Constructor Details
-
BinaryUtils
public BinaryUtils()
-
-
Method Details
-
toHex
Converts byte data to a Hex-encoded string in lower case.- Parameters:
data
- data to hex encode.- Returns:
- hex-encoded string.
-
fromHex
Converts a Hex-encoded data string to the original byte data.- Parameters:
hexData
- hex-encoded data to decode.- Returns:
- decoded data from the hex string.
-
toBase64
Converts byte data to a Base64-encoded string.- Parameters:
data
- data to Base64 encode.- Returns:
- encoded Base64 string.
-
fromBase64
Converts a Base64-encoded string to the original byte data.- Parameters:
b64Data
- a Base64-encoded string to decode.- Returns:
- bytes decoded from a Base64 string.
-
toStream
Wraps a ByteBuffer in an InputStream. If the inputbyteBuffer
is null, returns an empty stream.- Parameters:
byteBuffer
- The ByteBuffer to wrap.- Returns:
- An InputStream wrapping the ByteBuffer content.
-
copyAllBytesFrom
Returns a copy of all the bytes from the givenByteBuffer
, from the beginning to the buffer's limit; or null if the input is null.The internal states of the given byte buffer will be restored when this method completes execution.
When handling
ByteBuffer
from user's input, it's typical to call thecopyBytesFrom(ByteBuffer)
instead ofcopyAllBytesFrom(ByteBuffer)
so as to account for the position of the inputByteBuffer
. The opposite is typically true, however, when handlingByteBuffer
from withint the unmarshallers of the low-level clients. -
copyBytesFrom
Returns a copy of the bytes from the givenByteBuffer
, ranging from the the buffer's current position to the buffer's limit; or null if the input is null.The internal states of the given byte buffer will be restored when this method completes execution.
When handling
ByteBuffer
from user's input, it's typical to call thecopyBytesFrom(ByteBuffer)
instead ofcopyAllBytesFrom(ByteBuffer)
so as to account for the position of the inputByteBuffer
. The opposite is typically true, however, when handlingByteBuffer
from withint the unmarshallers of the low-level clients.
-