Class Base64EncodeStream

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

    public class Base64EncodeStream
    extends java.io.OutputStream
    This class implements a Base64 Character encoder as specified in RFC1113. Unlike some other encoding schemes there is nothing in this encoding that indicates where a buffer starts or ends. This means that the encoded text will simply start with the first line of encoded text and end with the last line of encoded text.
    Version:
    $Id: Base64EncodeStream.java 1732018 2016-02-24 04:51:06Z gadams $ Originally authored by Thomas DeWeese, Vincent Hardy, and Chuck McManis.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      (package private) byte[] atom  
      (package private) int atomLen  
      (package private) boolean closeOutOnClose  
      (package private) byte[] encodeBuf  
      (package private) int lineLen  
      (package private) java.io.PrintStream out  
      private static byte[] PEM_ARRAY
      This array maps the 6 bit values to their characters
    • Constructor Summary

      Constructors 
      Constructor Description
      Base64EncodeStream​(java.io.OutputStream out)  
      Base64EncodeStream​(java.io.OutputStream out, boolean closeOutOnClose)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()  
      (package private) void encodeAtom()
      enocodeAtom - Take three bytes of input and encode it as 4 printable characters.
      (package private) void encodeFromArray​(byte[] data, int offset, int len)
      enocodeAtom - Take three bytes of input and encode it as 4 printable characters.
      void flush()
      This can't really flush out output since that may generate '=' chars which would indicate the end of the stream.
      void write​(byte[] data)  
      void write​(byte[] data, int off, int len)  
      void write​(int b)  
      • 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

      • PEM_ARRAY

        private static final byte[] PEM_ARRAY
        This array maps the 6 bit values to their characters
      • atom

        byte[] atom
      • atomLen

        int atomLen
      • encodeBuf

        byte[] encodeBuf
      • lineLen

        int lineLen
      • out

        java.io.PrintStream out
      • closeOutOnClose

        boolean closeOutOnClose
    • Constructor Detail

      • Base64EncodeStream

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

        public Base64EncodeStream​(java.io.OutputStream out,
                                  boolean closeOutOnClose)
    • Method Detail

      • close

        public void close()
                   throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Overrides:
        close in class java.io.OutputStream
        Throws:
        java.io.IOException
      • flush

        public void flush()
                   throws java.io.IOException
        This can't really flush out output since that may generate '=' chars which would indicate the end of the stream. Instead we flush out. You can only be sure all output is writen by closing this stream.
        Specified by:
        flush in interface java.io.Flushable
        Overrides:
        flush in class java.io.OutputStream
        Throws:
        java.io.IOException
      • write

        public void write​(int b)
                   throws java.io.IOException
        Specified by:
        write in class java.io.OutputStream
        Throws:
        java.io.IOException
      • write

        public void write​(byte[] data)
                   throws java.io.IOException
        Overrides:
        write in class java.io.OutputStream
        Throws:
        java.io.IOException
      • write

        public void write​(byte[] data,
                          int off,
                          int len)
                   throws java.io.IOException
        Overrides:
        write in class java.io.OutputStream
        Throws:
        java.io.IOException
      • encodeAtom

        void encodeAtom()
                 throws java.io.IOException
        enocodeAtom - Take three bytes of input and encode it as 4 printable characters. Note that if the length in len is less than three is encodes either one or two '=' signs to indicate padding characters.
        Throws:
        java.io.IOException
      • encodeFromArray

        void encodeFromArray​(byte[] data,
                             int offset,
                             int len)
                      throws java.io.IOException
        enocodeAtom - Take three bytes of input and encode it as 4 printable characters. Note that if the length in len is less than three is encodes either one or two '=' signs to indicate padding characters.
        Throws:
        java.io.IOException