BinaryUtils (AWS SDK for Java
Utilities for encoding and decoding binary data to and from different forms.
Method Summary
All MethodsStatic MethodsConcrete Methods
static byte[]
Returns a copy of all the bytes from the given
ByteBuffer
, 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 given
ByteBuffer
, ranging from the the buffer's current position to the buffer's limit; or null if the input is null.
This behaves identically tostatic byte[]
copyBytesFrom(ByteBuffer)
, except that the readLimit acts as a limit to the number of bytes that should be read from the byte buffer.static byte[]
static byte[]
Converts a Base64-encoded string to the original byte data.
static byte[]
Converts a Base64-encoded string to the original byte data.
static byte[]
Converts a Hex-encoded data string to the original byte data.
Returns an immutable copy of the given
ByteBuffer
.Returns an immutable copy of the remaining bytes of the given
ByteBuffer
.Converts byte data to a Base64-encoded string.
static byte[]
Converts byte data to a Base64-encoded string.
Converts byte data to a Hex-encoded string in lower case.
Returns a copy of the given
DirectByteBuffer
from its current position as a non-directHeapByteBuffer
Wraps a ByteBuffer in an InputStream.
Method Details
toHex
public static String toHex(byte[] data)Converts byte data to a Hex-encoded string in lower case.
Parameters:data
- data to hex encode. Returns: hex-encoded string.fromHex
public static byte[] fromHex(String hexData)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
public static String toBase64(byte[] data)Converts byte data to a Base64-encoded string.
Parameters:data
- data to Base64 encode. Returns: encoded Base64 string.toBase64Bytes
public static byte[] toBase64Bytes(byte[] data)
Converts byte data to a Base64-encoded string.
Parameters:data
- data to Base64 encode. Returns: encoded Base64 string.fromBase64
public static byte[] fromBase64(String b64Data)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.fromBase64Bytes
public static byte[] fromBase64Bytes(byte[] b64Data)
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 input
Parameters:byteBuffer
is null, returns an empty stream.byteBuffer
- The ByteBuffer to wrap. Returns: An InputStream wrapping the ByteBuffer content.immutableCopyOf
Returns an immutable copy of the givenByteBuffer
.The new buffer's position will be set to the position of the given
ByteBuffer
, but the mark if defined will be ignored.NOTE: this method intentionally converts direct buffers to non-direct though there is no guarantee this will always be the case, if this is required see
Parameters:toNonDirectBuffer(ByteBuffer)
bb
- the sourceByteBuffer
to copy. Returns: a read onlyByteBuffer
.immutableCopyOfRemaining
Returns an immutable copy of the remaining bytes of the givenByteBuffer
.NOTE: this method intentionally converts direct buffers to non-direct though there is no guarantee this will always be the case, if this is required see
Parameters:toNonDirectBuffer(ByteBuffer)
bb
- the sourceByteBuffer
to copy. Returns: a read onlyByteBuffer
.toNonDirectBuffer
Returns a copy of the givenDirectByteBuffer
from its current position as a non-directHeapByteBuffer
The new buffer's position will be set to the position of the given
Parameters:ByteBuffer
, but the mark if defined will be ignored.bb
- the sourceByteBuffer
to copy. Returns:ByteBuffer
.copyAllBytesFrom
public static byte[] copyAllBytesFrom(ByteBuffer bb) 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.copyRemainingBytesFrom
public static byte[] copyRemainingBytesFrom(ByteBuffer bb)copyBytesFrom
public static byte[] copyBytesFrom(ByteBuffer bb) 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.copyBytesFrom
public static byte[] copyBytesFrom(ByteBuffer bb, int readLimit) This behaves identically tocopyBytesFrom(ByteBuffer)
, except that the readLimit acts as a limit to the number of bytes that should be read from the byte buffer.
ncG1vNJzZmirlKB7ornAs6anmaeoe6S7zGihmq6RZK6xtY6lmK2do6l8tLvFra6aqpVkrq6t2ailaJmnqMClt46uq6Kko2SPqrrAq7COrJmhwG%2B006aj