Class Base64Helper


  • class Base64Helper
    extends java.lang.Object
    Base64Helper exists to bridge inconsistencies in Java SE support of Base64 encoding and decoding. Earlier Java SE platforms (up to and including Java SE 8) supported base64 encode/decode via the javax.xml.bind.DatatypeConverter class, which was deprecated and eventually removed in Java SE 9. Later Java SE platforms (Java SE 8 and later) support base64 encode/decode via the java.util.Base64 class (first introduced in Java SE 8, and not available on e.g. Java SE 6 or 7). This makes it "hard" to write a single piece of source code that deals with base64 encodings and will compile and run on e.g. Java SE 7 AND Java SE 9. And such common source is a common need for libraries. This class is intended to encapsulate this "hard"-ness and hide the ugly pretzle-twising needed under the covers. Base64Helper provides a common API that works across Java SE 6..9 (and beyond hopefully), and uses late binding (Reflection) internally to avoid javac-compile-time dependencies on a specific Java SE version (e.g. beyond 7 or before 9).
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static java.lang.reflect.Method decodeMethod  
      private static java.lang.Object decoderObj  
      private static java.lang.reflect.Method encodeMethod  
      private static java.lang.Object encoderObj  
    • Constructor Summary

      Constructors 
      Constructor Description
      Base64Helper()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      (package private) static byte[] parseBase64Binary​(java.lang.String base64input)
      Converts a Base64 encoded String to a byte array
      (package private) static java.lang.String printBase64Binary​(byte[] binaryArray)
      Converts an array of bytes into a Base64 string.
      • Methods inherited from class java.lang.Object

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

      • decodeMethod

        private static java.lang.reflect.Method decodeMethod
      • encodeMethod

        private static java.lang.reflect.Method encodeMethod
      • decoderObj

        private static java.lang.Object decoderObj
      • encoderObj

        private static java.lang.Object encoderObj
    • Constructor Detail

      • Base64Helper

        Base64Helper()
    • Method Detail

      • printBase64Binary

        static java.lang.String printBase64Binary​(byte[] binaryArray)
        Converts an array of bytes into a Base64 string.
        Parameters:
        binaryArray - A binary encoded input array
        Returns:
        a String containing the Base64 encoded equivalent of the binary input
      • parseBase64Binary

        static byte[] parseBase64Binary​(java.lang.String base64input)
        Converts a Base64 encoded String to a byte array
        Parameters:
        base64input - A base64-encoded input String
        Returns:
        a byte array containing the binary representation equivalent of the Base64 encoded input