public static final class FlexBase64.Decoder extends Object
Modifier and Type | Method and Description |
---|---|
int |
decode(byte[] source,
int sourcePos,
int sourceLimit,
byte[] target,
int targetPos,
int targetLimit)
Decodes one Base64 byte array into another byte array.
|
void |
decode(ByteBuffer source,
ByteBuffer target)
Decodes one Base64 byte buffer into another.
|
int |
decode(String source,
byte[] target)
Decodes a Base64 encoded string into the passed byte array.
|
int |
decode(String source,
int sourcePos,
int sourceLimit,
byte[] target,
int targetPos,
int targetLimit)
Decodes one Base64 byte array into another byte array.
|
int |
getLastInputPosition()
Gets the last position where decoding left off in the last byte array that was used for reading.
|
public void decode(ByteBuffer source, ByteBuffer target) throws IOException
The decoder will skip white space, but will error if it detects corruption.
source
- the byte buffer to read encoded data fromtarget
- the byte buffer to write decoded data toIOException
- if the encoded data is corruptedpublic int getLastInputPosition()
public int decode(String source, int sourcePos, int sourceLimit, byte[] target, int targetPos, int targetLimit) throws IOException
When multiple calls are made, getLastInputPosition()
should be used to determine what value
should be set for sourcePos. Likewise, the returned target position should be used as the targetPos
in a subsequent call.
The decoder will skip white space, but will error if it detects corruption.
source
- a Base64 encoded string to decode data fromsourcePos
- the position in the source array to start decoding fromsourceLimit
- the position in the source array to halt decoding when hit (exclusive)target
- the byte buffer to write decoded data totargetPos
- the position in the target byte array to begin writing attargetLimit
- the position in the target byte array to halt writing (exclusive)IOException
- if the encoded data is corruptedpublic int decode(String source, byte[] target) throws IOException
Since this method variant assumes a position of 0 and a limit of the item length,
repeated calls will need fresh source and target values. decode(String, int, int, byte[], int, int)
would be a better fit if you need reuse
The decoder will skip white space, but will error if it detects corruption.
source
- a base64 encoded string to decode fromtarget
- a byte array to write toIOException
- if the base64 content is malformedpublic int decode(byte[] source, int sourcePos, int sourceLimit, byte[] target, int targetPos, int targetLimit) throws IOException
When multiple calls are made, getLastInputPosition()
should be used to determine what value
should be set for sourcePos. Likewise, the returned target position should be used as the targetPos
in a subsequent call.
The decoder will skip white space, but will error if it detects corruption.
Decoder decoder = FlexBase64.createDecoder();
byte[] outBuffer = new byte[10];
byte[] bytes = "aGVsbG8=".getBytes("US-ASCII");
// Decode only 2 bytes
int outPosition = decoder.decode(bytes, 0, 8, outBuffer, 5, 7);
// Resume where we left off and get the rest
outPosition = decoder.decode(bytes, decoder.getLastInputPosition(), 8, outBuffer, outPosition, 10);
// Prints "10 : Hello"
System.out.println(outPosition + " : " + new String(outBuffer, 0, 5, outPosition - 5));
source
- the byte array to read encoded data fromsourcePos
- the position in the source array to start decoding fromsourceLimit
- the position in the source array to halt decoding when hit (exclusive)target
- the byte buffer to write decoded data totargetPos
- the position in the target byte array to begin writing attargetLimit
- the position in the target byte array to halt writing (exclusive)IOException
- if the encoded data is corruptedCopyright © 2017 JBoss by Red Hat. All rights reserved.