Class Base64Helper

java.lang.Object
org.HdrHistogram.Base64Helper

class Base64Helper extends 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 pretzel-twisting 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 Details

    • decodeMethod

      private static Method decodeMethod
    • encodeMethod

      private static Method encodeMethod
    • decoderObj

      private static Object decoderObj
    • encoderObj

      private static Object encoderObj
  • Constructor Details

    • Base64Helper

      Base64Helper()
  • Method Details

    • printBase64Binary

      static 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(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