Class Base64


  • public class Base64
    extends java.lang.Object
    Encodes and decodes to and from Base64 notation.

    I am placing this code in the Public Domain. Do with it as you will. This software comes with no guarantees or warranties but with plenty of well-wishing instead! Please visit http://iharder.net/base64 periodically to check for updates or to contribute improvements.

    Version:
    2.1, stripped to minimum feature set used by JGit.
    Author:
    Robert Harder, rob@iharder.net
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static byte[] decode​(byte[] source, int off, int len)
      Low-level decoding ASCII characters from a byte array.
      static byte[] decode​(java.lang.String s)
      Decodes data from Base64 notation.
      static java.lang.String encodeBytes​(byte[] source)
      Encodes a byte array into Base64 notation.
      static java.lang.String encodeBytes​(byte[] source, int off, int len)
      Encodes a byte array into Base64 notation.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • encodeBytes

        public static java.lang.String encodeBytes​(byte[] source)
        Encodes a byte array into Base64 notation.
        Parameters:
        source - The data to convert
        Returns:
        encoded base64 representation of source.
      • encodeBytes

        public static java.lang.String encodeBytes​(byte[] source,
                                                   int off,
                                                   int len)
        Encodes a byte array into Base64 notation.
        Parameters:
        source - The data to convert
        off - Offset in array where conversion should begin
        len - Length of data to convert
        Returns:
        encoded base64 representation of source.
      • decode

        public static byte[] decode​(byte[] source,
                                    int off,
                                    int len)
        Low-level decoding ASCII characters from a byte array.
        Parameters:
        source - The Base64 encoded data
        off - The offset of where to begin decoding
        len - The length of characters to decode
        Returns:
        decoded data
        Throws:
        java.lang.IllegalArgumentException - the input is not a valid Base64 sequence.
      • decode

        public static byte[] decode​(java.lang.String s)
        Decodes data from Base64 notation.
        Parameters:
        s - the string to decode
        Returns:
        the decoded data