Package io.protostuff

Class B64Code

java.lang.Object
io.protostuff.B64Code

public final class B64Code extends Object
Fast B64 Encoder/Decoder as described in RFC 1421.

Does not insert or interpret whitespace as described in RFC 1521. If you require this you must pre/post process your data.

Note that in a web context the usual case is to not want linebreaks or other white space in the encoded output.

All methods that begin with 'c' will use char arrays (as output on encode, as input on decode).

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    (package private) static final byte[]
     
    (package private) static final byte[]
     
    (package private) static final byte
     
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static byte[]
    cdecode(char[] b)
    Fast Base 64 decode as described in RFC 1421.
    static byte[]
    cdecode(char[] input, int inOffset, int inLen)
    Fast Base 64 decode as described in RFC 1421.
    private static void
    cdecode(char[] input, int inOffset, int inLen, byte[] output, int outOffset, int outLen)
     
    static char[]
    cencode(byte[] input)
    Fast Base 64 encode as described in RFC 1421.
    static char[]
    cencode(byte[] input, int inOffset, int inLen)
    Fast Base 64 encode as described in RFC 1421.
    private static void
    cencode(byte[] input, int inOffset, int inLen, char[] output, int outOffset)
    Fast Base 64 encode as described in RFC 1421.
    static byte[]
    decode(byte[] b)
    Fast Base 64 decode as described in RFC 1421.
    static byte[]
    decode(byte[] input, int inOffset, int inLen)
    Fast Base 64 decode as described in RFC 1421.
    private static void
    decode(byte[] input, int inOffset, int inLen, byte[] output, int outOffset, int outLen)
     
    static byte[]
    Returns the base 64 decoded bytes.
    static byte[]
    decode(String str, int inOffset, int inLen)
    Returns the base 64 decoded bytes.
    private static void
    decode(String str, int inOffset, int inLen, byte[] output, int outOffset, int outLen)
     
    static int
    decodeTo(byte[] output, int outOffset, byte[] input, int inOffset, int inLen)
    Returns the length of the decoded base64 input (written to the provided output byte array).
    static int
    decodeTo(byte[] output, int outOffset, String str, int inOffset, int inLen)
    Returns the length of the decoded base64 input (written to the provided output byte array).
    static byte[]
    encode(byte[] input)
    Fast Base 64 encode as described in RFC 1421.
    static byte[]
    encode(byte[] input, int inOffset, int inLen)
    Fast Base 64 encode as described in RFC 1421.
    private static void
    encode(byte[] input, int inOffset, int inLen, byte[] output, int outOffset)
    Fast Base 64 encode as described in RFC 1421.
    encode(byte[] input, int inOffset, int inLen, WriteSession session, LinkedBuffer lb)
    Encodes the byte array into the LinkedBuffer and grows when full.
    sencode(byte[] input, int inOffset, int inLen, WriteSession session, LinkedBuffer lb)
    Encodes the byte array into the LinkedBuffer and flushes to the OutputStream when buffer is full.

    Methods inherited from class java.lang.Object

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

    • pad

      static final byte pad
      See Also:
    • nibble2code

      static final byte[] nibble2code
    • code2nibble

      static final byte[] code2nibble
  • Constructor Details

    • B64Code

      private B64Code()
  • Method Details

    • encode

      public static byte[] encode(byte[] input)
      Fast Base 64 encode as described in RFC 1421.
    • encode

      public static byte[] encode(byte[] input, int inOffset, int inLen)
      Fast Base 64 encode as described in RFC 1421.
    • cencode

      public static char[] cencode(byte[] input)
      Fast Base 64 encode as described in RFC 1421.
    • cencode

      public static char[] cencode(byte[] input, int inOffset, int inLen)
      Fast Base 64 encode as described in RFC 1421.
    • encode

      private static void encode(byte[] input, int inOffset, int inLen, byte[] output, int outOffset)
      Fast Base 64 encode as described in RFC 1421.

      Does not insert whitespace as described in RFC 1521.

      Avoids creating extra copies of the input/output.

    • cencode

      private static void cencode(byte[] input, int inOffset, int inLen, char[] output, int outOffset)
      Fast Base 64 encode as described in RFC 1421.

      Does not insert whitespace as described in RFC 1521.

      Avoids creating extra copies of the input/output.

    • encode

      public static LinkedBuffer encode(byte[] input, int inOffset, int inLen, WriteSession session, LinkedBuffer lb) throws IOException
      Encodes the byte array into the LinkedBuffer and grows when full.
      Throws:
      IOException
    • sencode

      public static LinkedBuffer sencode(byte[] input, int inOffset, int inLen, WriteSession session, LinkedBuffer lb) throws IOException
      Encodes the byte array into the LinkedBuffer and flushes to the OutputStream when buffer is full.
      Throws:
      IOException
    • decode

      public static byte[] decode(byte[] b)
      Fast Base 64 decode as described in RFC 1421.
    • cdecode

      public static byte[] cdecode(char[] b)
      Fast Base 64 decode as described in RFC 1421.
    • decode

      public static byte[] decode(byte[] input, int inOffset, int inLen)
      Fast Base 64 decode as described in RFC 1421.

      Does not attempt to cope with extra whitespace as described in RFC 1521.

      Avoids creating extra copies of the input/output.

      Note this code has been flattened for performance.

      Parameters:
      input - byte array to decode.
      inOffset - the offset.
      inLen - the length.
      Returns:
      byte array containing the decoded form of the input.
      Throws:
      IllegalArgumentException - if the input is not a valid B64 encoding.
    • cdecode

      public static byte[] cdecode(char[] input, int inOffset, int inLen)
      Fast Base 64 decode as described in RFC 1421.

      Does not attempt to cope with extra whitespace as described in RFC 1521.

      Avoids creating extra copies of the input/output.

      Note this code has been flattened for performance.

      Parameters:
      input - char array to decode.
      inOffset - the offset.
      inLen - the length.
      Returns:
      byte array containing the decoded form of the input.
      Throws:
      IllegalArgumentException - if the input is not a valid B64 encoding.
    • decodeTo

      public static int decodeTo(byte[] output, int outOffset, byte[] input, int inOffset, int inLen)
      Returns the length of the decoded base64 input (written to the provided output byte array). The output byte array must have enough capacity or it will fail.
    • decode

      private static void decode(byte[] input, int inOffset, int inLen, byte[] output, int outOffset, int outLen)
    • cdecode

      private static void cdecode(char[] input, int inOffset, int inLen, byte[] output, int outOffset, int outLen)
    • decode

      public static byte[] decode(String str)
      Returns the base 64 decoded bytes. The provided str must already be base-64 encoded.
    • decode

      public static byte[] decode(String str, int inOffset, int inLen)
      Returns the base 64 decoded bytes. The provided str must already be base-64 encoded.
    • decodeTo

      public static int decodeTo(byte[] output, int outOffset, String str, int inOffset, int inLen)
      Returns the length of the decoded base64 input (written to the provided output byte array). The output byte array must have enough capacity or it will fail.
    • decode

      private static void decode(String str, int inOffset, int inLen, byte[] output, int outOffset, int outLen)