Class Base64


  • public class Base64
    extends java.lang.Object
    Utility to base64 encode and decode a string.
    Version:
    2.3
    Author:
    Stephen Uhler
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static byte[] decode​(java.lang.String s)
      A Base64 decoder.
      static java.lang.String encode​(byte[] src)
      base-64 encode a byte array
      static java.lang.String encode​(byte[] src, int start, int length)
      base-64 encode a byte array
      static java.lang.String encode​(java.lang.String s)
      base-64 encode a string
      static void main​(java.lang.String[] args)
      Test the decoder and encoder.
      • Methods inherited from class java.lang.Object

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

      • encode

        public static java.lang.String encode​(java.lang.String s)
        base-64 encode a string
        Parameters:
        s - The ascii string to encode
        Returns:
        The base64 encoded result
      • encode

        public static java.lang.String encode​(byte[] src)
        base-64 encode a byte array
        Parameters:
        src - The byte array to encode
        Returns:
        The base64 encoded result
      • encode

        public static java.lang.String encode​(byte[] src,
                                              int start,
                                              int length)
        base-64 encode a byte array
        Parameters:
        src - The byte array to encode
        start - The starting index
        len - The number of bytes
        Returns:
        The base64 encoded result
      • decode

        public static byte[] decode​(java.lang.String s)
        A Base64 decoder. This implementation is slow, and doesn't handle wrapped lines. The output is undefined if there are errors in the input.
        Parameters:
        s - a Base64 encoded string
        Returns:
        The byte array eith the decoded result
      • main

        public static void main​(java.lang.String[] args)
        Test the decoder and encoder. Call as Base64 [string].