public class FlexBase64 extends Object
Modifier and Type | Class and Description |
---|---|
static class | FlexBase64.Decoder Controls the decoding process. |
static class | FlexBase64.DecoderInputStream An input stream which decodes bytes as they are read from a stream with Base64 encoded data. |
static class | FlexBase64.DecoderOutputStream An output stream which decodes base64 data written to it, and writes the decoded output to the wrapped inner stream. |
static class | FlexBase64.Encoder Controls the encoding process. |
static class | FlexBase64.EncoderInputStream An input stream which encodes bytes as they are read from a stream. |
static class | FlexBase64.EncoderOutputStream An output stream which base64 encodes all passed data and writes it to the wrapped target output stream. |
Constructor and Description |
---|
FlexBase64() |
Modifier and Type | Method and Description |
---|---|
static FlexBase64.Decoder | createDecoder() Creates a state driven base64 decoder. |
static FlexBase64.DecoderInputStream | createDecoderInputStream(InputStream source) Creates an InputStream wrapper which decodes a base64 input source into the decoded content as it is read, until the source hits EOF. |
static FlexBase64.DecoderInputStream | createDecoderInputStream(InputStream source, int bufferSize) Creates an InputStream wrapper which decodes a base64 input source into the decoded content as it is read, until the source hits EOF. |
static FlexBase64.DecoderOutputStream | createDecoderOutputStream(OutputStream output) Creates an OutputStream wrapper which decodes base64 content before writing to the passed OutputStream target. |
static FlexBase64.DecoderOutputStream | createDecoderOutputStream(OutputStream output, int bufferSize) Creates an OutputStream wrapper which decodes base64 content before writing to the passed OutputStream target. |
static FlexBase64.Encoder | createEncoder(boolean wrap) Creates a state driven base64 encoder. |
static FlexBase64.EncoderInputStream | createEncoderInputStream(InputStream source) Creates an InputStream wrapper which encodes a source into base64 as it is read, until the source hits EOF. |
static FlexBase64.EncoderInputStream | createEncoderInputStream(InputStream source, int bufferSize, boolean wrap) Creates an InputStream wrapper which encodes a source into base64 as it is read, until the source hits EOF. |
static FlexBase64.EncoderOutputStream | createEncoderOutputStream(OutputStream output) Creates an OutputStream wrapper which base64 encodes and writes to the passed OutputStream target. |
static FlexBase64.EncoderOutputStream | createEncoderOutputStream(OutputStream target, int bufferSize, boolean wrap) Creates an OutputStream wrapper which base64 encodes and writes to the passed OutputStream target. |
static FlexBase64.Decoder | createURLDecoder() Creates a state driven base64url decoder. |
static FlexBase64.Encoder | createURLEncoder(boolean wrap) Creates a state driven base64url encoder. |
static ByteBuffer | decode(byte[] source, int off, int limit) Decodes a Base64 encoded byte array into a new byte buffer. |
static ByteBuffer | decode(ByteBuffer source) Decodes a Base64 encoded byte buffer into a new byte buffer. |
static ByteBuffer | decode(String source) Decodes a Base64 encoded string into a new byte buffer. |
static ByteBuffer | decodeURL(byte[] source, int off, int limit) Decodes a Base64url encoded byte array into a new byte buffer. |
static ByteBuffer | decodeURL(ByteBuffer source) Decodes a Base64url encoded byte buffer into a new byte buffer. |
static ByteBuffer | decodeURL(String source) Decodes a Base64url encoded string into a new byte buffer. |
static byte[] | encodeBytes(byte[] source, int pos, int limit, boolean wrap) Encodes a fixed and complete byte buffer into a Base64 byte array. |
static byte[] | encodeBytesURL(byte[] source, int pos, int limit, boolean wrap) Encodes a fixed and complete byte buffer into a Base64url byte array. |
static String | encodeString(byte[] source, boolean wrap) Encodes a fixed and complete byte array into a Base64 String. |
static String | encodeString(byte[] source, int pos, int limit, boolean wrap) Encodes a fixed and complete byte array into a Base64 String. |
static String | encodeString(ByteBuffer source, boolean wrap) Encodes a fixed and complete byte buffer into a Base64 String. |
static String | encodeStringURL(byte[] source, boolean wrap) Encodes a fixed and complete byte array into a Base64url String. |
static String | encodeStringURL(byte[] source, int pos, int limit, boolean wrap) Encodes a fixed and complete byte array into a Base64url String. |
static String | encodeStringURL(ByteBuffer source, boolean wrap) Encodes a fixed and complete byte buffer into a Base64url String. |
public static FlexBase64.Encoder createEncoder(boolean wrap)
The Encoder instance is not thread-safe, and must not be shared between threads without establishing a happens-before relationship.
wrap
- whether or not to wrap at 76 characters with CRLFpublic static FlexBase64.Encoder createURLEncoder(boolean wrap)
The Encoder instance is not thread-safe, and must not be shared between threads without establishing a happens-before relationship.
wrap
- whether or not to wrap at 76 characters with CRLFpublic static FlexBase64.Decoder createDecoder()
The Decoder instance is not thread-safe, and must not be shared between threads without establishing a happens-before relationship.
public static FlexBase64.Decoder createURLDecoder()
The Decoder instance is not thread-safe, and must not be shared between threads without establishing a happens-before relationship.
public static String encodeString(byte[] source, boolean wrap)
This method is only useful for applications which require a String and have all data to be encoded up-front. Note that byte arrays or buffers are almost always a better storage choice. They consume half the memory and can be reused (modified). In other words, it is almost always better to use encodeBytes(byte[], int, int, boolean)
, createEncoder(boolean)
, or createEncoderOutputStream(java.io.OutputStream, int, boolean)
instead. instead.
source
- the byte array to encode fromwrap
- whether or not to wrap the output at 76 chars with CRLFspublic static String encodeStringURL(byte[] source, boolean wrap)
This method is only useful for applications which require a String and have all data to be encoded up-front. Note that byte arrays or buffers are almost always a better storage choice. They consume half the memory and can be reused (modified). In other words, it is almost always better to use encodeBytes(byte[], int, int, boolean)
, createEncoder(boolean)
, or createEncoderOutputStream(java.io.OutputStream, int, boolean)
instead. instead.
source
- the byte array to encode fromwrap
- whether or not to wrap the output at 76 chars with CRLFspublic static String encodeString(byte[] source, int pos, int limit, boolean wrap)
This method is only useful for applications which require a String and have all data to be encoded up-front. Note that byte arrays or buffers are almost always a better storage choice. They consume half the memory and can be reused (modified). In other words, it is almost always better to use encodeBytes(byte[], int, int, boolean)
, createEncoder(boolean)
, or createEncoderOutputStream(java.io.OutputStream, int, boolean)
instead.
// Encodes "ell"
FlexBase64.encodeString("hello".getBytes("US-ASCII"), 1, 4);
source
- the byte array to encode frompos
- the position to start encoding fromlimit
- the position to halt encoding at (exclusive)wrap
- whether or not to wrap the output at 76 chars with CRLFspublic static String encodeStringURL(byte[] source, int pos, int limit, boolean wrap)
This method is only useful for applications which require a String and have all data to be encoded up-front. Note that byte arrays or buffers are almost always a better storage choice. They consume half the memory and can be reused (modified). In other words, it is almost always better to use encodeBytes(byte[], int, int, boolean)
, createEncoder(boolean)
, or createEncoderOutputStream(java.io.OutputStream, int, boolean)
instead.
// Encodes "ell"
FlexBase64.encodeStringURL("hello".getBytes("US-ASCII"), 1, 4);
source
- the byte array to encode frompos
- the position to start encoding fromlimit
- the position to halt encoding at (exclusive)wrap
- whether or not to wrap the output at 76 chars with CRLFspublic static String encodeString(ByteBuffer source, boolean wrap)
This method is only useful for applications which require a String and have all data to be encoded up-front. Note that byte arrays or buffers are almost always a better storage choice. They consume half the memory and can be reused (modified). In other words, it is almost always better to use encodeBytes(byte[], int, int, boolean)
, createEncoder(boolean)
, or createEncoderOutputStream(java.io.OutputStream, int, boolean)
instead.
// Encodes "ell"
FlexBase64.ecncodeString("hello".getBytes("US-ASCII"), 1, 4);
source
- the byte buffer to encode fromwrap
- whether or not to wrap the output at 76 chars with CRLFspublic static String encodeStringURL(ByteBuffer source, boolean wrap)
This method is only useful for applications which require a String and have all data to be encoded up-front. Note that byte arrays or buffers are almost always a better storage choice. They consume half the memory and can be reused (modified). In other words, it is almost always better to use encodeBytes(byte[], int, int, boolean)
, createEncoder(boolean)
, or createEncoderOutputStream(java.io.OutputStream, int, boolean)
instead.
// Encodes "ell"
FlexBase64.ecncodeStringURL("hello".getBytes("US-ASCII"), 1, 4);
source
- the byte buffer to encode fromwrap
- whether or not to wrap the output at 76 chars with CRLFspublic static byte[] encodeBytes(byte[] source, int pos, int limit, boolean wrap)
// Encodes "ell"
FlexBase64.ecncodeString("hello".getBytes("US-ASCII"), 1, 4);
source
- the byte array to encode frompos
- the position to start encoding atlimit
- the position to halt encoding at (exclusive)wrap
- whether or not to wrap at 76 characters with CRLFspublic static byte[] encodeBytesURL(byte[] source, int pos, int limit, boolean wrap)
// Encodes "ell"
FlexBase64.ecncodeStringURL("hello".getBytes("US-ASCII"), 1, 4);
source
- the byte array to encode frompos
- the position to start encoding atlimit
- the position to halt encoding at (exclusive)wrap
- whether or not to wrap at 76 characters with CRLFspublic static ByteBuffer decode(String source) throws IOException
ByteBuffer.array()
, ByteBuffer.arrayOffset()
and Buffer.limit()
. The latter is very important since the decoded array may be larger than the decoded data. This is due to length estimation which avoids an unnecessary array copy.source
- the Base64 string to decodeIOException
- if the encoding is invalid or corruptedpublic static ByteBuffer decodeURL(String source) throws IOException
ByteBuffer.array()
, ByteBuffer.arrayOffset()
and Buffer.limit()
. The latter is very important since the decoded array may be larger than the decoded data. This is due to length estimation which avoids an unnecessary array copy.source
- the Base64 string to decodeIOException
- if the encoding is invalid or corruptedpublic static ByteBuffer decode(ByteBuffer source) throws IOException
ByteBuffer.array()
, ByteBuffer.arrayOffset()
and Buffer.limit()
. The latter is very important since the decoded array may be larger than the decoded data. This is due to length estimation which avoids an unnecessary array copy.source
- the Base64 content to decodeIOException
- if the encoding is invalid or corruptedpublic static ByteBuffer decodeURL(ByteBuffer source) throws IOException
ByteBuffer.array()
, ByteBuffer.arrayOffset()
and Buffer.limit()
. The latter is very important since the decoded array may be larger than the decoded data. This is due to length estimation which avoids an unnecessary array copy.source
- the Base64 content to decodeIOException
- if the encoding is invalid or corruptedpublic static ByteBuffer decode(byte[] source, int off, int limit) throws IOException
ByteBuffer.array()
, ByteBuffer.arrayOffset()
and Buffer.limit()
. The latter is very important since the decoded array may be larger than the decoded data. This is due to length estimation which avoids an unnecessary array copy.source
- the Base64 content to decodeoff
- position to start decoding from in sourcelimit
- position to stop decoding in source (exclusive)IOException
- if the encoding is invalid or corruptedpublic static ByteBuffer decodeURL(byte[] source, int off, int limit) throws IOException
ByteBuffer.array()
, ByteBuffer.arrayOffset()
and Buffer.limit()
. The latter is very important since the decoded array may be larger than the decoded data. This is due to length estimation which avoids an unnecessary array copy.source
- the Base64url content to decodeoff
- position to start decoding from in sourcelimit
- position to stop decoding in source (exclusive)IOException
- if the encoding is invalid or corruptedpublic static FlexBase64.EncoderInputStream createEncoderInputStream(InputStream source, int bufferSize, boolean wrap)
This stream is not thread-safe, and should not be shared between threads, without establishing a happens-before relationship.
source
- an input source to read frombufferSize
- the chunk size to buffer from the sourcewrap
- whether or not the stream should wrap base64 output at 76 characterspublic static FlexBase64.EncoderInputStream createEncoderInputStream(InputStream source)
This stream is not thread-safe, and should not be shared between threads, without establishing a happens-before relationship.
source
- an input source to read frompublic static FlexBase64.DecoderInputStream createDecoderInputStream(InputStream source, int bufferSize)
Note that the end of a base64 stream can not reliably be detected, so if multiple base64 streams exist on the wire, the source stream will need to simulate an EOF when the boundary mechanism is detected.
This stream is not thread-safe, and should not be shared between threads, without establishing a happens-before relationship.
source
- an input source to read frombufferSize
- the chunk size to buffer before when reading from the targetpublic static FlexBase64.DecoderInputStream createDecoderInputStream(InputStream source)
Note that the end of a base64 stream can not reliably be detected, so if multiple base64 streams exist on the wire, the source stream will need to simulate an EOF when the boundary mechanism is detected.
This stream is not thread-safe, and should not be shared between threads, without establishing a happens-before relationship.
source
- an input source to read frompublic static FlexBase64.EncoderOutputStream createEncoderOutputStream(OutputStream target, int bufferSize, boolean wrap)
FlexBase64.EncoderOutputStream.complete()
method can be called to close out the inner stream without closing the wrapped target. All bytes written will be queued to a buffer in the specified size. This stream, therefore, does not require BufferedOutputStream, which would lead to double buffering.
target
- an output target to write tobufferSize
- the chunk size to buffer before writing to the targetwrap
- whether or not the stream should wrap base64 output at 76 characterspublic static FlexBase64.EncoderOutputStream createEncoderOutputStream(OutputStream output)
FlexBase64.EncoderOutputStream.complete()
method can be called to close out the inner stream without closing the wrapped target. All bytes written will be queued to an 8192 byte buffer. This stream, therefore, does not require BufferedOutputStream, which would lead to double buffering.
This stream is not thread-safe, and should not be shared between threads, without establishing a happens-before relationship.
output
- the output stream to write encoded output topublic static FlexBase64.DecoderOutputStream createDecoderOutputStream(OutputStream output, int bufferSize)
All bytes written will be queued to a buffer using the specified buffer size. This stream, therefore, does not require BufferedOutputStream, which would lead to double buffering.
This stream is not thread-safe, and should not be shared between threads, without establishing a happens-before relationship.
output
- the output stream to write decoded output tobufferSize
- the buffer size to buffer writes topublic static FlexBase64.DecoderOutputStream createDecoderOutputStream(OutputStream output)
All bytes written will be queued to an 8192 byte buffer. This stream, therefore, does not require BufferedOutputStream, which would lead to double buffering.
This stream is not thread-safe, and should not be shared between threads, without establishing a happens-before relationship.
output
- the output stream to write decoded output toCopyright © 2015 JBoss by Red Hat. All rights reserved.