Class Base64OutputStream

java.lang.Object
java.io.OutputStream
org.simpleframework.common.encode.Base64OutputStream
All Implemented Interfaces:
Closeable, Flushable, AutoCloseable

public class Base64OutputStream extends OutputStream
The Base64OutputStream is used to write base64 text in the form of a string through a conventional output stream. This is provided for convenience so that it is possible to encode and decode binary data as base64 for implementations that would normally use a binary format.
Author:
Niall Gallagher
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructor for the Base64OutputStream object.
    Base64OutputStream(int capacity)
    Constructor for the Base64OutputStream object.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    This is used to close the stream and encode the buffered bytes to base64.
    This returns the base64 text encoded from the bytes written to the stream.
    void
    write(byte[] array, int offset, int length)
    This method is used to write data as base64 to an internal buffer.
    void
    write(int octet)
    This method is used to write data as base64 to an internal buffer.

    Methods inherited from class OutputStream

    flush, nullOutputStream, write

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Base64OutputStream

      public Base64OutputStream()
      Constructor for the Base64OutputStream object. A stream created with this constructor uses an initial capacity of one kilobyte, the capacity is increased as bytes are written.
    • Base64OutputStream

      public Base64OutputStream(int capacity)
      Constructor for the Base64OutputStream object. A stream created with this constructor can have an initial capacity specified. Typically it is a good rule of thumb to use a capacity that is just over an additional third of the source binary data.
      Parameters:
      capacity - this is the initial capacity of the buffer
  • Method Details

    • write

      public void write(int octet) throws IOException
      This method is used to write data as base64 to an internal buffer. The toString method can be used to acquire the text encoded from the written binary data.
      Specified by:
      write in class OutputStream
      Parameters:
      octet - the octet to encode in to the internal buffer
      Throws:
      IOException
    • write

      public void write(byte[] array, int offset, int length) throws IOException
      This method is used to write data as base64 to an internal buffer. The toString method can be used to acquire the text encoded from the written binary data.
      Overrides:
      write in class OutputStream
      Parameters:
      array - the octets to encode to the internal buffer
      offset - this is the offset in the array to encode from
      length - this is the number of bytes to be encoded
      Throws:
      IOException
    • close

      public void close() throws IOException
      This is used to close the stream and encode the buffered bytes to base64. Once this method is invoked no further data can be encoded with the stream. The toString method can be used to acquire the base64 encoded text.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class OutputStream
      Throws:
      IOException
    • toString

      public String toString()
      This returns the base64 text encoded from the bytes written to the stream. This is the primary means for acquiring the base64 encoded text once the stream has been closed.
      Overrides:
      toString in class Object
      Returns:
      this returns the base64 text encoded