Package jodd.util

Class Base64


  • public class Base64
    extends java.lang.Object
    The fastest Base64 encoder/decoder implementations. Base64 is defined in RFC 2045.

    Encoding supports two modes - with or without line separator. When line separator flag is on, result will have lines with max size of 76 chars, as per spec.

    When decoding, input must be valid, without illegal characters. If input contains lines, they must be 76 chars long. Lines must end with CRLF ("\r\n"), as per spec.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      static char[] CHARS  
    • Constructor Summary

      Constructors 
      Constructor Description
      Base64()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static byte[] decode​(byte[] arr)
      Decodes BASE64 encoded byte array.
      static byte[] decode​(char[] arr)
      Decodes a BASE64 encoded char array.
      static byte[] decode​(java.lang.String s)
      Decodes a BASE64 encoded string.
      static java.lang.String decodeToString​(byte[] arr)  
      static java.lang.String decodeToString​(java.lang.String s)  
      static byte[] encodeToByte​(byte[] arr)  
      static byte[] encodeToByte​(byte[] arr, boolean lineSep)
      Encodes a raw byte array into a BASE64 char[].
      static byte[] encodeToByte​(java.lang.String s)  
      static byte[] encodeToByte​(java.lang.String s, boolean lineSep)  
      static char[] encodeToChar​(byte[] arr, boolean lineSeparator)
      Encodes a raw byte array into a BASE64 char[].
      static java.lang.String encodeToString​(byte[] arr)  
      static java.lang.String encodeToString​(byte[] arr, boolean lineSep)
      Encodes a raw byte array into a BASE64 String.
      static java.lang.String encodeToString​(java.lang.String s)  
      static java.lang.String encodeToString​(java.lang.String s, boolean lineSep)  
      • Methods inherited from class java.lang.Object

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

      • CHARS

        public static final char[] CHARS
    • Constructor Detail

      • Base64

        public Base64()
    • Method Detail

      • encodeToChar

        public static char[] encodeToChar​(byte[] arr,
                                          boolean lineSeparator)
        Encodes a raw byte array into a BASE64 char[].
        Parameters:
        lineSeparator - optional CRLF after 76 chars, unless EOF.
      • decode

        public static byte[] decode​(char[] arr)
        Decodes a BASE64 encoded char array.
      • encodeToByte

        public static byte[] encodeToByte​(java.lang.String s)
      • encodeToByte

        public static byte[] encodeToByte​(java.lang.String s,
                                          boolean lineSep)
      • encodeToByte

        public static byte[] encodeToByte​(byte[] arr)
      • encodeToByte

        public static byte[] encodeToByte​(byte[] arr,
                                          boolean lineSep)
        Encodes a raw byte array into a BASE64 char[].
        Parameters:
        lineSep - optional CRLF after 76 chars, unless EOF.
      • decodeToString

        public static java.lang.String decodeToString​(byte[] arr)
      • decode

        public static byte[] decode​(byte[] arr)
        Decodes BASE64 encoded byte array.
      • encodeToString

        public static java.lang.String encodeToString​(java.lang.String s)
      • encodeToString

        public static java.lang.String encodeToString​(java.lang.String s,
                                                      boolean lineSep)
      • encodeToString

        public static java.lang.String encodeToString​(byte[] arr)
      • encodeToString

        public static java.lang.String encodeToString​(byte[] arr,
                                                      boolean lineSep)
        Encodes a raw byte array into a BASE64 String.
      • decodeToString

        public static java.lang.String decodeToString​(java.lang.String s)
      • decode

        public static byte[] decode​(java.lang.String s)
        Decodes a BASE64 encoded string.