Class Base64OutputStream

All Implemented Interfaces:
Closeable, Flushable, AutoCloseable

@NotThreadSafe public class Base64OutputStream extends WrappedOutputStream
A Base64OutputStream will write data to another OutputStream , given in the constructor, and encode/decode to/from Base64 notation on the fly.
Since:
1.3
See Also:
  • Constructor Details

    • Base64OutputStream

      public Base64OutputStream(@Nonnull OutputStream aOS)
      Constructs a Base64OutputStream in ENCODE mode.
      Parameters:
      aOS - the OutputStream to which data will be written.
      Since:
      1.3
    • Base64OutputStream

      public Base64OutputStream(@Nonnull OutputStream aOS, int nOptions)
      Constructs a Base64OutputStream in either ENCODE or DECODE mode.

      Valid options:

         ENCODE or DECODE: Encode or Decode as data is read.
         DO_BREAK_LINES: don't break lines at 76 characters
           (only meaningful when encoding)
       

      Example: new Base64.OutputStream( out, Base64.ENCODE )

      Parameters:
      aOS - the OutputStream to which data will be written.
      nOptions - Specified options.
      Since:
      1.3
      See Also:
  • Method Details

    • setNewLineBytes

      public void setNewLineBytes(@Nonnull @Nonempty byte[] aNewLineBytes)
      Set the newline bytes to be used, so that "\r\n" can be used instead of the default "\n"
      Parameters:
      aNewLineBytes - The newline bytes to be used. May neither be null nor empty.
      Since:
      9.3.4
    • write

      public void write(int theByte) throws IOException
      Writes the byte to the output stream after converting to/from Base64 notation. When encoding, bytes are buffered three at a time before the output stream actually gets a write() call. When decoding, bytes are buffered four at a time.
      Overrides:
      write in class FilterOutputStream
      Parameters:
      theByte - the byte to write
      Throws:
      IOException
      Since:
      1.3
    • write

      public void write(@Nonnull byte[] aBytes, @Nonnegative int nOfs, @Nonnegative int nLen) throws IOException
      Calls write(int) repeatedly until len bytes are written.
      Overrides:
      write in class WrappedOutputStream
      Parameters:
      aBytes - array from which to read bytes
      nOfs - offset for array
      nLen - max number of bytes to read into array
      Throws:
      IOException
      Since:
      1.3
    • flushBase64

      public void flushBase64() throws IOException
      Method added by PHIL. [Thanks, PHIL. -Rob] This pads the buffer without closing the stream.
      Throws:
      IOException - if there's an error.
    • close

      public void close() throws IOException
      Flushes and closes (I think, in the superclass) the stream.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class FilterOutputStream
      Throws:
      IOException
      Since:
      1.3
    • suspendEncoding

      public void suspendEncoding() throws IOException
      Suspends encoding of the stream. May be helpful if you need to embed a piece of base64-encoded data in a stream.
      Throws:
      IOException - if there's an error flushing
      Since:
      1.5.1
    • resumeEncoding

      public void resumeEncoding()
      Resumes encoding of the stream. May be helpful if you need to embed a piece of base64-encoded data in a stream.
      Since:
      1.5.1