Class Base64InputStream

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

    public class Base64InputStream
    extends java.io.InputStream
    The Base64InputStream is used to read base64 text in the form of a string through a conventional input stream. This is provided for convenience so that it is possible to encode and decode binary data as base64 for implementations that would normally use a binary format.
    See Also:
    Base64Encoder
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private int count
      This is the total number of bytes that have been read.
      private byte[] decoded
      This is used to accumulate the decoded text as an array.
      private char[] encoded
      This is that original base64 text that is to be decoded.
      private byte[] temp
      This is a temporary buffer used to read one byte at a time.
    • Constructor Summary

      Constructors 
      Constructor Description
      Base64InputStream​(java.lang.String source)
      Constructor for the Base64InputStream object.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int read()
      This is used to read the next byte decoded from the text.
      int read​(byte[] array, int offset, int length)
      This is used to read the next byte decoded from the text.
      java.lang.String toString()
      This returns the original base64 text that was encoded.
      • Methods inherited from class java.io.InputStream

        available, close, mark, markSupported, nullInputStream, read, readAllBytes, readNBytes, readNBytes, reset, skip, transferTo
      • Methods inherited from class java.lang.Object

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

      • encoded

        private char[] encoded
        This is that original base64 text that is to be decoded.
      • decoded

        private byte[] decoded
        This is used to accumulate the decoded text as an array.
      • temp

        private byte[] temp
        This is a temporary buffer used to read one byte at a time.
      • count

        private int count
        This is the total number of bytes that have been read.
    • Constructor Detail

      • Base64InputStream

        public Base64InputStream​(java.lang.String source)
        Constructor for the Base64InputStream object. This takes an encoded string and reads it as binary data.
        Parameters:
        source - this string containing the encoded data
    • Method Detail

      • read

        public int read()
                 throws java.io.IOException
        This is used to read the next byte decoded from the text. If the data has been fully consumed then this will return the standard -1.
        Specified by:
        read in class java.io.InputStream
        Returns:
        this returns the next octet decoded
        Throws:
        java.io.IOException
      • read

        public int read​(byte[] array,
                        int offset,
                        int length)
                 throws java.io.IOException
        This is used to read the next byte decoded from the text. If the data has been fully consumed then this will return the standard -1.
        Overrides:
        read in class java.io.InputStream
        Parameters:
        array - this is the array to decode the text to
        offset - this is the offset to decode in to the array
        this - is the number of bytes available to decode to
        Returns:
        this returns the number of octets decoded
        Throws:
        java.io.IOException
      • toString

        public java.lang.String toString()
        This returns the original base64 text that was encoded. This is useful for debugging purposes to see the source data.
        Overrides:
        toString in class java.lang.Object
        Returns:
        this returns the original base64 text to decode