Class Base64EncoderStream

  • All Implemented Interfaces:
    java.io.Closeable, java.io.Flushable, java.lang.AutoCloseable

    public class Base64EncoderStream
    extends java.io.FilterOutputStream
    This class implements a BASE64 Encoder. It is implemented as a FilterOutputStream, so one can just wrap this class around any output stream and write bytes into this filter. The Encoding is done as the bytes are written out.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private byte[] buffer  
      private int bufsize  
      private javax.xml.stream.XMLStreamWriter outWriter  
      private static char[] pem_array
      This array maps the characters to their 6 bit values
      • Fields inherited from class java.io.FilterOutputStream

        out
    • Constructor Summary

      Constructors 
      Constructor Description
      Base64EncoderStream​(java.io.OutputStream out)  
      Base64EncoderStream​(javax.xml.stream.XMLStreamWriter outWriter, java.io.OutputStream out)
      Create a BASE64 encoder that encodes the specified input stream
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      Forces any buffered output bytes to be encoded out to the stream and closes this output stream
      private void encode()  
      void flush()
      Flushes this output stream and forces any buffered output bytes to be encoded out to the stream.
      void write​(byte[] b)
      Encodes b.length bytes to this output stream.
      void write​(byte[] b, int off, int len)
      Encodes len bytes from the specified byte array starting at offset off to this output stream.
      void write​(int c)
      Encodes the specified byte to this output stream.
      • Methods inherited from class java.io.OutputStream

        nullOutputStream
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • buffer

        private byte[] buffer
      • bufsize

        private int bufsize
      • outWriter

        private javax.xml.stream.XMLStreamWriter outWriter
      • pem_array

        private static final char[] pem_array
        This array maps the characters to their 6 bit values
    • Constructor Detail

      • Base64EncoderStream

        public Base64EncoderStream​(java.io.OutputStream out)
      • Base64EncoderStream

        public Base64EncoderStream​(javax.xml.stream.XMLStreamWriter outWriter,
                                   java.io.OutputStream out)
        Create a BASE64 encoder that encodes the specified input stream
    • Method Detail

      • write

        public void write​(byte[] b,
                          int off,
                          int len)
                   throws java.io.IOException
        Encodes len bytes from the specified byte array starting at offset off to this output stream.
        Overrides:
        write in class java.io.FilterOutputStream
        Parameters:
        b - the data.
        off - the start offset in the data.
        len - the number of bytes to write.
        Throws:
        java.io.IOException - if an I/O error occurs.
      • write

        public void write​(byte[] b)
                   throws java.io.IOException
        Encodes b.length bytes to this output stream.
        Overrides:
        write in class java.io.FilterOutputStream
        Parameters:
        b - the data to be written.
        Throws:
        java.io.IOException - if an I/O error occurs.
      • write

        public void write​(int c)
                   throws java.io.IOException
        Encodes the specified byte to this output stream.
        Overrides:
        write in class java.io.FilterOutputStream
        Parameters:
        c - the byte.
        Throws:
        java.io.IOException - if an I/O error occurs.
      • flush

        public void flush()
                   throws java.io.IOException
        Flushes this output stream and forces any buffered output bytes to be encoded out to the stream.
        Specified by:
        flush in interface java.io.Flushable
        Overrides:
        flush in class java.io.FilterOutputStream
        Throws:
        java.io.IOException - if an I/O error occurs.
      • close

        public void close()
                   throws java.io.IOException
        Forces any buffered output bytes to be encoded out to the stream and closes this output stream
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Overrides:
        close in class java.io.FilterOutputStream
        Throws:
        java.io.IOException
      • encode

        private void encode()
                     throws java.io.IOException
        Throws:
        java.io.IOException