Class Base64Coder

java.lang.Object
cz.metacentrum.perun.core.impl.Base64Coder

public class Base64Coder extends Object
A Base64 encoder/decoder.

This class is used to encode and decode data in Base64 format as described in RFC 1521.

Project home page: www.source-code.biz/base64coder/java
Author: Christian d'Heureuse, Inventec Informatik AG, Zurich, Switzerland
Multi-licensed: EPL / LGPL / GPL / AL / BSD.

  • Method Summary

    Modifier and Type
    Method
    Description
    static byte[]
    decode(char[] in)
    Decodes a byte array from Base64 format.
    static byte[]
    decode(char[] in, int inputOffset, int inputLength)
    Decodes a byte array from Base64 format.
    static byte[]
    Decodes a byte array from Base64 format.
    static byte[]
    Decodes a byte array from Base64 format and ignores line separators, tabs and blanks.
    static String
    Decodes a string from Base64 format.
    static char[]
    encode(byte[] in)
    Encodes a byte array into Base64 format.
    static char[]
    encode(byte[] in, int inputLength)
    Encodes a byte array into Base64 format.
    static char[]
    encode(byte[] in, int inputOffset, int inputLength)
    Encodes a byte array into Base64 format.
    static String
    encodeLines(byte[] in)
    Encodes a byte array into Base 64 format and breaks the output into lines of 76 characters.
    static String
    encodeLines(byte[] in, int inputOffset, int inputLength, int lineLen, String lineSeparator)
    Encodes a byte array into Base 64 format and breaks the output into lines.
    static String
    Encodes a string into Base64 format.

    Methods inherited from class java.lang.Object

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

    • decode

      public static byte[] decode(String s)
      Decodes a byte array from Base64 format. No blanks or line breaks are allowed within the Base64 encoded input data.
      Parameters:
      s - A Base64 String to be decoded.
      Returns:
      An array containing the decoded data bytes.
      Throws:
      IllegalArgumentException - If the input is not valid Base64 encoded data.
    • decode

      public static byte[] decode(char[] in)
      Decodes a byte array from Base64 format. No blanks or line breaks are allowed within the Base64 encoded input data.
      Parameters:
      in - A character array containing the Base64 encoded data.
      Returns:
      An array containing the decoded data bytes.
      Throws:
      IllegalArgumentException - If the input is not valid Base64 encoded data.
    • decode

      public static byte[] decode(char[] in, int inputOffset, int inputLength)
      Decodes a byte array from Base64 format. No blanks or line breaks are allowed within the Base64 encoded input data.
      Parameters:
      in - A character array containing the Base64 encoded data.
      inputOffset - Offset of the first character in in to be processed.
      inputLength - Number of characters to process in in, starting at inputOffset.
      Returns:
      An array containing the decoded data bytes.
      Throws:
      IllegalArgumentException - If the input is not valid Base64 encoded data.
    • decodeLines

      public static byte[] decodeLines(String s)
      Decodes a byte array from Base64 format and ignores line separators, tabs and blanks. CR, LF, Tab and Space characters are ignored in the input data. This method is compatible with sun.misc.BASE64Decoder.decodeBuffer(String).
      Parameters:
      s - A Base64 String to be decoded.
      Returns:
      An array containing the decoded data bytes.
      Throws:
      IllegalArgumentException - If the input is not valid Base64 encoded data.
    • decodeString

      public static String decodeString(String s)
      Decodes a string from Base64 format. No blanks or line breaks are allowed within the Base64 encoded input data.
      Parameters:
      s - A Base64 String to be decoded.
      Returns:
      A String containing the decoded data.
      Throws:
      IllegalArgumentException - If the input is not valid Base64 encoded data.
    • encode

      public static char[] encode(byte[] in)
      Encodes a byte array into Base64 format. No blanks or line breaks are inserted in the output.
      Parameters:
      in - An array containing the data bytes to be encoded.
      Returns:
      A character array containing the Base64 encoded data.
    • encode

      public static char[] encode(byte[] in, int inputOffset, int inputLength)
      Encodes a byte array into Base64 format. No blanks or line breaks are inserted in the output.
      Parameters:
      in - An array containing the data bytes to be encoded.
      inputOffset - Offset of the first byte in in to be processed.
      inputLength - Number of bytes to process in in, starting at inputOffset.
      Returns:
      A character array containing the Base64 encoded data.
    • encode

      public static char[] encode(byte[] in, int inputLength)
      Encodes a byte array into Base64 format. No blanks or line breaks are inserted in the output.
      Parameters:
      in - An array containing the data bytes to be encoded.
      inputLength - Number of bytes to process in in.
      Returns:
      A character array containing the Base64 encoded data.
    • encodeLines

      public static String encodeLines(byte[] in)
      Encodes a byte array into Base 64 format and breaks the output into lines of 76 characters. This method is compatible with sun.misc.BASE64Encoder.encodeBuffer(byte[]).
      Parameters:
      in - An array containing the data bytes to be encoded.
      Returns:
      A String containing the Base64 encoded data, broken into lines.
    • encodeLines

      public static String encodeLines(byte[] in, int inputOffset, int inputLength, int lineLen, String lineSeparator)
      Encodes a byte array into Base 64 format and breaks the output into lines.
      Parameters:
      in - An array containing the data bytes to be encoded.
      inputOffset - Offset of the first byte in in to be processed.
      inputLength - Number of bytes to be processed in in, starting at inputOffset.
      lineLen - Line length for the output data. Should be a multiple of 4.
      lineSeparator - The line separator to be used to separate the output lines.
      Returns:
      A String containing the Base64 encoded data, broken into lines.
    • encodeString

      public static String encodeString(String s)
      Encodes a string into Base64 format. No blanks or line breaks are inserted.
      Parameters:
      s - A String to be encoded.
      Returns:
      A String containing the Base64 encoded data.