Class Base64InputStream

  • All Implemented Interfaces:
    Closeable, AutoCloseable

    public class Base64InputStream
    extends FilterInputStream
    Variant of the Commons Codec project's class of the same name. See Base64 for an explanation of the rationale for creating the variants in this package.

    Provides Base64 encoding and decoding in a streaming fashion (unlimited size).

    The behaviour of the Base64OutputStream is to ENCODE, whereas the behaviour of the Base64InputStream is to DECODE.

    This class implements section 6.8. Base64 Content-Transfer-Encoding from RFC 2045 Multipurpose Internet Mail Extensions (MIME) Part One: Format of Internet Message Bodies by Freed and Borenstein.

    Since this class operates directly on byte streams, and not character streams, it is hard-coded to only encode/decode character encodings which are compatible with the lower 127 ASCII chart (ISO-8859-1, Windows-1252, UTF-8, etc).

    See Also:
    RFC 2045
    • Constructor Detail

      • Base64InputStream

        public Base64InputStream​(InputStream in)
        Creates a Base64InputStream such that all data read is Base64-decoded from the original provided InputStream.
        Parameters:
        in - InputStream to wrap.
    • Method Detail

      • mark

        public void mark​(int readLimit)
        Marks the current position in this input stream.

        The mark method of BaseNCodecInputStream does nothing.

        Overrides:
        mark in class FilterInputStream
        Parameters:
        readLimit - the maximum limit of bytes that can be read before the mark position becomes invalid.
        Since:
        1.7
      • read

        public int read()
                 throws IOException
        Reads one byte from this input stream.
        Overrides:
        read in class FilterInputStream
        Returns:
        the byte as an integer in the range 0 to 255. Returns -1 if EOF has been reached.
        Throws:
        IOException - if an I/O error occurs.
      • read

        public int read​(byte[] b,
                        int offset,
                        int len)
                 throws IOException
        Attempts to read len bytes into the specified b array starting at offset from this InputStream.
        Overrides:
        read in class FilterInputStream
        Parameters:
        b - destination byte array
        offset - where to start writing the bytes
        len - maximum number of bytes to read
        Returns:
        number of bytes read
        Throws:
        IOException - if an I/O error occurs.
        NullPointerException - if the byte array parameter is null
        IndexOutOfBoundsException - if offset, len or buffer size are invalid