com.stimulsoft.lib.base64
Class StiBase64DecoderUtil

java.lang.Object
  extended by com.stimulsoft.lib.base64.StiBase64DecoderUtil

public final class StiBase64DecoderUtil
extends java.lang.Object

Class decodes a Base64 encoded data back into the original byte representation and writes to output stream.


Constructor Summary
StiBase64DecoderUtil(java.io.OutputStream stream)
          Construct a Base64Decoder waiting on calls to its translate() method.
 
Method Summary
static byte[] decode(byte[] data)
          Decode given byte array into a decoded byte array.
static byte[] decode(byte[] data, int begin, int end)
          Decode given byte array into a decoded byte array.
static void decode(java.io.InputStream input, java.io.OutputStream out)
          Decode bytes from input stream and write decoded bytes to output stream.
static void decode(java.io.InputStream input, java.io.OutputStream out, long count)
          Decode bytes from input stream and write decoded bytes to output stream.
static byte[] decode(java.lang.String str)
           
 void flush()
          Writes all decoded octets.
 StiBase64DecoderUtil translate(byte[] bytes)
          Translate every base64 character from given byte array into a sextet byte value by using above translation array.
 StiBase64DecoderUtil translate(byte[] bytes, int begin, int end)
          Translate every base64 character from given byte array into a sextet byte value by using above translation array.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StiBase64DecoderUtil

public StiBase64DecoderUtil(java.io.OutputStream stream)
Construct a Base64Decoder waiting on calls to its translate() method. Base64Decoder must be flushed to write internally buffered data to output stream.

Method Detail

decode

public static void decode(java.io.InputStream input,
                          java.io.OutputStream out)
                   throws java.io.IOException
Decode bytes from input stream and write decoded bytes to output stream.

Parameters:
input - input stream
out - output stream
Throws:
java.io.IOException - if an I/O error occurs

decode

public static void decode(java.io.InputStream input,
                          java.io.OutputStream out,
                          long count)
                   throws java.io.IOException
Decode bytes from input stream and write decoded bytes to output stream.

Parameters:
input - input stream
out - output stream
count - count of bytes to read and decode; -1 for all available bytes
Throws:
java.io.IOException - if an I/O error occurs

decode

public static byte[] decode(java.lang.String str)

decode

public static byte[] decode(byte[] data)
Decode given byte array into a decoded byte array.

Parameters:
data - Base64 byte array to be decoded.
Returns:
All decoded octets as byte array.

decode

public static byte[] decode(byte[] data,
                            int begin,
                            int end)
Decode given byte array into a decoded byte array.

Parameters:
data - Base64 byte array to be decoded
begin - index of the first byte to start from
end - index after the last byte
Returns:
All decoded octets as byte array.

translate

public StiBase64DecoderUtil translate(byte[] bytes)
                               throws java.io.IOException
Translate every base64 character from given byte array into a sextet byte value by using above translation array. The sextets are then shifted into an buffer until the buffer contains 4 sextets which are then decoded into 3 octets. The translate and decode process is continued until all bytes of given byte array are evaluated. If there are remaining sextets in the buffer they also will be converted into octets at the end. All the converted octets are written to the output stream.

Parameters:
bytes - the byte array to be decoded
Returns:
Base64Decoder
Throws:
java.io.IOException - if an I/O error occurs. In particular, an IOException may be thrown if the output stream has been closed.

translate

public StiBase64DecoderUtil translate(byte[] bytes,
                                      int begin,
                                      int end)
                               throws java.io.IOException
Translate every base64 character from given byte array into a sextet byte value by using above translation array. The sextets are then shifted into an buffer until the buffer contains 4 sextets which are then decoded into 3 octets. The translate and decode process is continued until all bytes of given byte array are evaluated. If there are remaining sextets in the buffer they also will be converted into octets at the end. All the converted octets are written to the output stream.

Parameters:
bytes - the byte array to be decoded
begin - index of the first byte to start from
end - index after the last byte
Returns:
Base64Decoder
Throws:
java.io.IOException - if an I/O error occurs. In particular, an IOException may be thrown if the output stream has been closed.

flush

public void flush()
           throws java.io.IOException
Writes all decoded octets.

Throws:
java.io.IOException - if an I/O error occurs. In particular, an IOException may be thrown if the output stream has been closed.