public static final class FlexBase64.Encoder extends Object
Modifier and Type | Method and Description |
---|---|
int | complete(byte[] target, int pos) Completes an encoding session by writing out the necessary padding. |
void | complete(ByteBuffer target) Completes an encoding session by writing out the necessary padding. |
int | encode(byte[] source, int pos, int limit, byte[] target, int opos, int olimit) Encodes bytes read from source and writes them in base64 format to target. |
void | encode(ByteBuffer source, ByteBuffer target) Encodes bytes read from source and writes them in base64 format to target. |
int | getLastInputPosition() Gets the last position where encoding left off in the last byte array that was used. |
public void encode(ByteBuffer source, ByteBuffer target)
complete(java.nio.ByteBuffer)
should be called to add the necessary padding characters.source
- the byte buffer to read fromtarget
- the byte buffer to write topublic int encode(byte[] source, int pos, int limit, byte[] target, int opos, int olimit)
complete(byte[], int)
should be called to add the necessary padding characters. In order to determine the last read position, the getLastInputPosition()
can be used. Note that the limit values are not lengths, they are positions similar to Buffer.limit()
. To calculate a length simply subtract position from limit.
Encoder encoder = FlexBase64.createEncoder(false);
byte[] outBuffer = new byte[10];
// Encode "ell"
int outPosition = encoder.encode("hello".getBytes("US-ASCII"), 1, 4, outBuffer, 5, 10);
// Prints "9 : ZWxs"
System.out.println(outPosition + " : " + new String(outBuffer, 0, 5, outPosition - 5));
source
- the byte array to read frompos
- ths position in the byte array to start reading fromlimit
- the position in the byte array that is after the end of the source datatarget
- the byte array to write base64 bytes toopos
- the position to start writing to the target array atolimit
- the position in the target byte array that makes the end of the writable area (exclusive)public int getLastInputPosition()
public int complete(byte[] target, int pos)
Encoder encoder = FlexBase64.createEncoder(false);
byte[] outBuffer = new byte[13];
// Encodes "ello"
int outPosition = encoder.encode("hello".getBytes("US-ASCII"), 0, 4, outBuffer, 5, 13);
outPosition = encoder.complete(outBuffer, outPosition);
// Prints "13 : aGVsbA=="
System.out.println(outPosition + " : " + new String(outBuffer, 0, 5, outPosition - 5));
target
- the byte array to write topos
- the position to start writing atpublic void complete(ByteBuffer target)
target
- the byte buffer to write toCopyright © 2020 JBoss by Red Hat. All rights reserved.