Class Base64InputStream

  • All Implemented Interfaces:
    com.oracle.coherence.common.io.InputStreaming, InputStreaming, Closeable, AutoCloseable

    public class Base64InputStream
    extends InputStream
    implements InputStreaming
    Reads binary data from a Reader using IETF RFC 2045 Base64 Content Transfer Encoding. Static helpers are available for decoding directly from a char array to a byte array.
    Author:
    cp 2000.09.07
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected static byte[] EMPTY
      Empty binary data.
      protected int[] m_abGroup
      Group of bytes (stored as ints 0..255).
      protected boolean m_fClosed
      True after close is invoked.
      protected boolean m_fEOF
      True after eof is determined.
      protected int m_ofbGroup
      The offset in the group of bytes.
      protected Reader m_reader
      The Reader object from which the Base64 encoded data is read.
    • Constructor Summary

      Constructors 
      Constructor Description
      Base64InputStream​(Reader reader)
      Construct a Base64InputStream on a Reader object.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int available()
      Returns the number of bytes that can be read (or skipped over) from this input stream without blocking by the next caller of a method for this input stream.
      void close()
      Close the stream, flushing any accumulated bytes.
      static int decode​(char ch)
      Decode one base64 alphabet character.
      static byte[] decode​(char[] ach)
      Decode the passed character data that was encoded using Base64 encoding.
      static byte[] decode​(char[] ach, boolean fJunk)
      Decode the passed character data that was encoded using Base64 encoding.
      static byte[] decode​(char[] ach, int of, int cch)
      Decode the passed character data that was encoded using Base64 encoding.
      static byte[] decode​(char[] ach, int of, int cch, boolean fJunk)
      Decode the passed character data that was encoded using Base64 encoding.
      int read()
      Reads the next byte of data from the input stream.
      • Methods inherited from interface com.oracle.coherence.common.io.InputStreaming

        mark, markSupported, read, read, reset, skip
    • Field Detail

      • EMPTY

        protected static final byte[] EMPTY
        Empty binary data.
      • m_fClosed

        protected boolean m_fClosed
        True after close is invoked.
      • m_fEOF

        protected boolean m_fEOF
        True after eof is determined.
      • m_reader

        protected Reader m_reader
        The Reader object from which the Base64 encoded data is read.
      • m_abGroup

        protected int[] m_abGroup
        Group of bytes (stored as ints 0..255).
      • m_ofbGroup

        protected int m_ofbGroup
        The offset in the group of bytes.
    • Constructor Detail

      • Base64InputStream

        public Base64InputStream​(Reader reader)
        Construct a Base64InputStream on a Reader object.
        Parameters:
        reader - the Reader to read the Base64 encoded data from
    • Method Detail

      • read

        public int read()
                 throws IOException
        Reads the next byte of data from the input stream. The value byte is returned as an int in the range 0 to 255. If no byte is available because the end of the stream has been reached, the value -1 is returned. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown.
        Specified by:
        read in interface com.oracle.coherence.common.io.InputStreaming
        Specified by:
        read in class InputStream
        Returns:
        the next byte of data, or -1 if the end of the stream is reached.
        Throws:
        IOException - if an I/O error occurs.
      • available

        public int available()
                      throws IOException
        Returns the number of bytes that can be read (or skipped over) from this input stream without blocking by the next caller of a method for this input stream. The next caller might be the same thread or or another thread.
        Specified by:
        available in interface com.oracle.coherence.common.io.InputStreaming
        Overrides:
        available in class InputStream
        Returns:
        the number of bytes that can be read from this input stream without blocking.
        Throws:
        IOException - if an I/O error occurs.
      • close

        public void close()
                   throws IOException
        Close the stream, flushing any accumulated bytes. The underlying reader is not closed.
        Specified by:
        close in interface AutoCloseable
        Specified by:
        close in interface Closeable
        Specified by:
        close in interface com.oracle.coherence.common.io.InputStreaming
        Overrides:
        close in class InputStream
        Throws:
        IOException - if an I/O error occurs.
      • decode

        public static byte[] decode​(char[] ach)
        Decode the passed character data that was encoded using Base64 encoding.
        Parameters:
        ach - the array containing the characters to decode
        Returns:
        the decoded binary data as a byte array
      • decode

        public static byte[] decode​(char[] ach,
                                    boolean fJunk)
        Decode the passed character data that was encoded using Base64 encoding.
        Parameters:
        ach - the array containing the characters to decode
        fJunk - true if the char array may contain whitespace or linefeeds
        Returns:
        the decoded binary data as a byte array
      • decode

        public static byte[] decode​(char[] ach,
                                    int of,
                                    int cch)
        Decode the passed character data that was encoded using Base64 encoding.
        Parameters:
        ach - the array containing the characters to decode
        of - the start offset in the char array
        cch - the number of characters to decode
        Returns:
        the decoded binary data as a byte array
      • decode

        public static byte[] decode​(char[] ach,
                                    int of,
                                    int cch,
                                    boolean fJunk)
        Decode the passed character data that was encoded using Base64 encoding.
        Parameters:
        ach - the array containing the characters to decode
        of - the start offset in the char array
        cch - the number of characters to decode
        fJunk - true if the char array may contain whitespace or linefeeds
        Returns:
        the decoded binary data as a byte array
      • decode

        public static int decode​(char ch)
        Decode one base64 alphabet character.
        Parameters:
        ch - the character
        Returns:
        the ordinal value of the character