Class Base64


  • public class Base64
    extends Object
    Performs Base64 encoding and/or decoding. This is an on-the-fly decoder: Unlike, for example, the commons-codec classes, it doesn't depend on byte arrays. In other words, it has an extremely low memory profile. This is well suited even for very large byte streams.
    • Constructor Detail

      • Base64

        public Base64()
    • Method Detail

      • newEncoder

        public static OutputStream newEncoder​(Writer pWriter)
        Returns an OutputStream, that encodes its input in Base64 and writes it to the given Writer. If the Base64 stream ends, then the output streams OutputStream.close() method must be invoked. Note, that this will not close the target Writer!
        Parameters:
        pWriter - Target writer.
        Returns:
        An output stream, encoding its input in Base64 and writing the output to the writer pWriter.
      • newEncoder

        public static OutputStream newEncoder​(Writer pWriter,
                                              int pLineSize,
                                              String pSeparator)
        Returns an OutputStream, that encodes its input in Base64 and writes it to the given Writer. If the Base64 stream ends, then the output streams OutputStream.close() method must be invoked. Note, that this will not close the target Writer!
        Parameters:
        pWriter - Target writer.
        pLineSize - Size of one line in characters, must be a multiple of four. Zero indicates, that no line wrapping should occur.
        pSeparator - Line separator or null, in which case the default value LINE_SEPARATOR is used.
        Returns:
        An output stream, encoding its input in Base64 and writing the output to the writer pWriter.
      • encode

        public static String encode​(byte[] pBuffer,
                                    int pOffset,
                                    int pLength)
        Converts the given byte array into a base64 encoded character array.
        Parameters:
        pBuffer - The buffer being encoded.
        pOffset - Offset in buffer, where to begin encoding.
        pLength - Number of bytes being encoded.
        Returns:
        Character array of encoded bytes.
      • encode

        public static String encode​(byte[] pBuffer,
                                    int pOffset,
                                    int pLength,
                                    int pLineSize,
                                    String pSeparator)
        Converts the given byte array into a base64 encoded character array.
        Parameters:
        pBuffer - The buffer being encoded.
        pOffset - Offset in buffer, where to begin encoding.
        pLength - Number of bytes being encoded.
        pLineSize - Size of one line in characters, must be a multiple of four. Zero indicates, that no line wrapping should occur.
        pSeparator - Line separator or null, in which case the default value LINE_SEPARATOR is used.
        Returns:
        Character array of encoded bytes.
      • encode

        public static String encode​(byte[] pBuffer)
        Converts the given byte array into a base64 encoded character array with the line size LINE_SIZE and the separator LINE_SEPARATOR.
        Parameters:
        pBuffer - The buffer being encoded.
        Returns:
        Character array of encoded bytes.
      • newDecoder

        public static Writer newDecoder​(OutputStream pStream)
        Returns a Writer, that decodes its Base64 encoded input and writes it to the given OutputStream. Note, that the writers Writer.close() method will not close the output stream pStream!
        Parameters:
        pStream - Target output stream.
        Returns:
        An output stream, encoding its input in Base64 and writing the output to the writer pWriter.
      • decode

        public static byte[] decode​(char[] pBuffer,
                                    int pOffset,
                                    int pLength)
                             throws Base64.DecodingException
        Converts the given base64 encoded character buffer into a byte array.
        Parameters:
        pBuffer - The character buffer being decoded.
        pOffset - Offset of first character being decoded.
        pLength - Number of characters being decoded.
        Returns:
        Converted byte array
        Throws:
        Base64.DecodingException - The input character stream contained invalid data.
      • decode

        public static byte[] decode​(char[] pBuffer)
                             throws Base64.DecodingException
        Converts the given base64 encoded character buffer into a byte array.
        Parameters:
        pBuffer - The character buffer being decoded.
        Returns:
        Converted byte array
        Throws:
        Base64.DecodingException - The input character stream contained invalid data.
      • decode

        public static byte[] decode​(String pBuffer)
                             throws Base64.DecodingException
        Converts the given base64 encoded String into a byte array.
        Parameters:
        pBuffer - The string being decoded.
        Returns:
        Converted byte array
        Throws:
        Base64.DecodingException - The input character stream contained invalid data.