Package com.stimulsoft.lib.base64
Class StiBase64EncoderUtil
java.lang.Object
com.stimulsoft.lib.base64.StiBase64EncoderUtil
Class encodes the bytes read from the InputStream to a Base64 encoded string and writes to output
stream.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected int24-bit buffer to translate 3 octets into 4 sextets.protected intThe number of valid bytes in the data buffer.protected static final intNumber of sextets encoded from buffer.protected static final intInput buffer size.protected static final byte[]Array to convert sextet byte values into base64 characters.protected static final intMask buffer to or with first octet.protected static final intMask buffer to or with second octet.protected static final intThird octet in buffer.protected static final intMask buffer to or with third octet.protected static final intMask an octet.protected intNumber of octets in buffer.protected byte[]The buffer where data is stored between writes to output stream.protected static final byteByte used to pad output.protected static final intMask a sextet.protected static final intNumber of bits to shift for one octet.protected static final intNumber of bits to shift for one sextet.protected static final intNumber of bits to shift for two octets.protected static final intNumber of bits to shift for two sextets.protected static final intNumber of bits to shift for three sextets.protected final OutputStreamStream for encoded characters. -
Constructor Summary
ConstructorsConstructorDescriptionStiBase64EncoderUtil(OutputStream stream) Construct a Base64Encoder waiting on calls to its translate() method. -
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]encode(byte[] data) Encode given byte array into an encoded byte array.static byte[]encode(byte[] data, int begin, int end) Encode given byte array into an encoded byte array.static voidencode(InputStream input, OutputStream out) Encode bytes from input stream and write encoded bytes to output stream.static Stringprotected voidEncode 4 sextets from buffer.protected voidEncode the remaining sextets from buffer.voidflush()Writes all encoded characters.protected StiBase64EncoderUtiltranslate(byte[] bytes) Translate all bytes of given array by appending each to octet buffer.protected StiBase64EncoderUtiltranslate(byte[] bytes, int begin, int end) Translate bytes of given array by appending each to octet buffer.protected voidWrite buffer to output stream.
-
Field Details
-
FOUR_SEXTETS
protected static final int FOUR_SEXTETSNumber of sextets encoded from buffer.- See Also:
-
INPUT_BUFFER_SIZE
protected static final int INPUT_BUFFER_SIZEInput buffer size.- See Also:
-
SEXTET_MASK
protected static final int SEXTET_MASKMask a sextet.- See Also:
-
SHIFT_1_SEXTET
protected static final int SHIFT_1_SEXTETNumber of bits to shift for one sextet.- See Also:
-
SHIFT_2_SEXTET
protected static final int SHIFT_2_SEXTETNumber of bits to shift for two sextets.- See Also:
-
SHIFT_3_SEXTET
protected static final int SHIFT_3_SEXTETNumber of bits to shift for three sextets.- See Also:
-
PAD
protected static final byte PADByte used to pad output.- See Also:
-
MAP
protected static final byte[] MAPArray to convert sextet byte values into base64 characters. -
OCTET_3
protected static final int OCTET_3Third octet in buffer.- See Also:
-
OCTET_1_MASK
protected static final int OCTET_1_MASKMask buffer to or with first octet.- See Also:
-
OCTET_2_MASK
protected static final int OCTET_2_MASKMask buffer to or with second octet.- See Also:
-
OCTET_3_MASK
protected static final int OCTET_3_MASKMask buffer to or with third octet.- See Also:
-
OCTET_MASK
protected static final int OCTET_MASKMask an octet.- See Also:
-
SHIFT_1_OCTET
protected static final int SHIFT_1_OCTETNumber of bits to shift for one octet.- See Also:
-
SHIFT_2_OCTET
protected static final int SHIFT_2_OCTETNumber of bits to shift for two octets.- See Also:
-
buffer
protected int buffer24-bit buffer to translate 3 octets into 4 sextets. -
octets
protected int octetsNumber of octets in buffer. -
stream
Stream for encoded characters. -
outputBuffer
protected byte[] outputBufferThe buffer where data is stored between writes to output stream. -
count
protected int countThe number of valid bytes in the data buffer.
-
-
Constructor Details
-
StiBase64EncoderUtil
Construct a Base64Encoder waiting on calls to its translate() method. Base64Encoder must be flushed to write internally buffered data to output stream.- Parameters:
stream- stream to write encoded bytes to
-
-
Method Details
-
encode
Encode bytes from input stream and write encoded bytes to output stream.- Parameters:
input- input streamout- output stream- Throws:
IOException- if an I/O error occurs
-
encode
public static byte[] encode(byte[] data) Encode given byte array into an encoded byte array.- Parameters:
data- the byte array to be encoded- Returns:
- Base64 encoded characters as byte array
-
encode
-
encode
public static byte[] encode(byte[] data, int begin, int end) Encode given byte array into an encoded byte array.- Parameters:
data- the byte array to be encodedbegin- index of the first byte to start fromend- index after the last byte- Returns:
- Base64 encoded characters as byte array
-
translate
Translate all bytes of given array by appending each to octet buffer. If buffer contains 3 octets its content will be encoded to 4 sextet byte values which are converted to a base64 character each.- Parameters:
bytes- the byte array to be encoded- Returns:
- Base64Encoder
- Throws:
IOException- if an I/O error occurs. In particular, an IOException may be thrown if the output stream has been closed.
-
translate
Translate bytes of given array by appending each to octet buffer. If buffer contains 3 octets its content will be encoded to 4 sextet byte values which are converted to a base64 character each.- Parameters:
bytes- the byte array to be encodedbegin- index of the first byte to start fromend- index after the last byte- Returns:
- Base64Encoder
- Throws:
IOException- if an I/O error occurs. In particular, an IOException may be thrown if the output stream has been closed.
-
encodeBuffer
Encode 4 sextets from buffer.- Throws:
IOException- if an I/O error occurs. In particular, an IOException may be thrown if the output stream has been closed.
-
encodeBufferWithPadding
Encode the remaining sextets from buffer.- Throws:
IOException- if an I/O error occurs. In particular, an IOException may be thrown if the output stream has been closed.
-
writeBuffer
Write buffer to output stream.- Throws:
IOException- if an I/O error occurs. In particular, an IOException may be thrown if the output stream has been closed.
-
flush
Writes all encoded characters.- Throws:
IOException- if an I/O error occurs. In particular, an IOException may be thrown if the output stream has been closed.
-