Module swim.codec
Package swim.codec

Class Base64

java.lang.Object
swim.codec.Base64

public abstract class Base64 extends Object
Base-64 (7-bit ASCII) encoding Parser/Writer factory.
  • Method Summary

    Modifier and Type
    Method
    Description
    abstract String
    Returns a 64 character string, where the character at index i is the encoding of the base-64 digit i.
    Writer<byte[],?>
    Returns a Writer that, when fed an input byte[] array, returns a continuation that writes the base-64 (7-bit ASCII) encoding of the input byte array.
    Writer<?,byte[]>
    byteArrayWriter(byte[] input)
    Returns a Writer continuation that writes the base-64 (7-bit ASCII) encoding of the input byte array.
    Returns a Writer that, when fed an input ByteBuffer, returns a continuation that writes the base-64 (7-bit ASCII) encoding of the input byte buffer.
    Returns a Writer continuation that writes the base-64 (7-bit ASCII) encoding of the input byte buffer.
    int
    decodeDigit(int c)
    Returns the 7-bit quantity represented by the base-64 digit c.
    char
    encodeDigit(int b)
    Returns the Unicode code point of the base-64 digit that encodes the given 7-bit quantity.
    abstract boolean
    isDigit(int c)
    Returns true if the Unicode code point c is a valid base-64 digit.
    abstract boolean
    Returns true if this base-64 encoding requires padding.
    abstract Base64
    isPadded(boolean isPadded)
    Returns this Base64 encoding with required padding, if isPadded is true.
    <O> Parser<O>
    parse(Input input, Output<O> output)
    Parses the base-64 (7-bit ASCII) encoded input, and writes the decoded bytes to output, returning a Parser continuation that knows how to parse any additional input.
    Parser<byte[]>
    Parses the base-64 (7-bit ASCII) encoded input, and writes the decoded bytes to a growable array, returning a Parser continuation that knows how to parse any additional input.
    Parses the base-64 (t-bit ASCII) encoded input, and writes the decoded bytes to a growable buffer, returning a Parser continuation that knows how to parse any additional input.
    <O> Parser<O>
    parser(Output<O> output)
    Returns a Parser that decodes base-64 (7-bit ASCII) encoded input, and writes the decoded bytes to output.
    static Base64
    Returns the Base64 encoding with the standard alphabet.
    static Base64
    standard(boolean isPadded)
    Returns the Base64 encoding with the standard alphabet, and required padding, if isPadded is true.
    static Base64
    url()
    Returns the Base64 encoding with the url and filename safe alphabet.
    static Base64
    url(boolean isPadded)
    Returns the Base64 encoding with the url and filename safe alphabet, and required padding, if isPadded is true.
    static Base64
     
    Writer<?,?>
    writeByteArray(Output<?> output, byte[] input)
    Writes the base-64 (7-bit ASCII) encoding of the input byte array to the output, returning a Writer continuation that knows how to write any remaining output that couldn't be immediately generated.
    Writer<?,?>
    writeByteBuffer(Output<?> output, ByteBuffer input)
    Writes the base-64 (7-bit ASCII) encoding of the input byte buffer to the output, returning a Writer continuation that knows how to write any remaining output that couldn't be immediately generated.
    <T> Output<T>
    writeQuantum(Output<T> output, int c1, int c2, int c3, int c4)
    Decodes the base-64 digits c1, c2, c3, and c4, and writes the 8 to 24 bit quantity they represent to the given output.

    Methods inherited from class java.lang.Object

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

    • alphabet

      public abstract String alphabet()
      Returns a 64 character string, where the character at index i is the encoding of the base-64 digit i.
    • isPadded

      public abstract boolean isPadded()
      Returns true if this base-64 encoding requires padding.
    • isPadded

      public abstract Base64 isPadded(boolean isPadded)
      Returns this Base64 encoding with required padding, if isPadded is true.
    • isDigit

      public abstract boolean isDigit(int c)
      Returns true if the Unicode code point c is a valid base-64 digit.
    • decodeDigit

      public int decodeDigit(int c)
      Returns the 7-bit quantity represented by the base-64 digit c.
      Throws:
      IllegalArgumentException - if c is not a valid base-64 digit.
    • encodeDigit

      public char encodeDigit(int b)
      Returns the Unicode code point of the base-64 digit that encodes the given 7-bit quantity.
    • writeQuantum

      public <T> Output<T> writeQuantum(Output<T> output, int c1, int c2, int c3, int c4)
      Decodes the base-64 digits c1, c2, c3, and c4, and writes the 8 to 24 bit quantity they represent to the given output.
      Returns:
      the continuation of the output.
    • parser

      public <O> Parser<O> parser(Output<O> output)
      Returns a Parser that decodes base-64 (7-bit ASCII) encoded input, and writes the decoded bytes to output.
    • parse

      public <O> Parser<O> parse(Input input, Output<O> output)
      Parses the base-64 (7-bit ASCII) encoded input, and writes the decoded bytes to output, returning a Parser continuation that knows how to parse any additional input.
    • parseByteArray

      public Parser<byte[]> parseByteArray(Input input)
      Parses the base-64 (7-bit ASCII) encoded input, and writes the decoded bytes to a growable array, returning a Parser continuation that knows how to parse any additional input. The returned Parser binds a byte[] array containing all parsed base-64 data.
    • parseByteBuffer

      public Parser<ByteBuffer> parseByteBuffer(Input input)
      Parses the base-64 (t-bit ASCII) encoded input, and writes the decoded bytes to a growable buffer, returning a Parser continuation that knows how to parse any additional input. The returned Parser binds a ByteBuffer containing all parsed base-64 data.
    • byteArrayWriter

      public Writer<byte[],?> byteArrayWriter()
      Returns a Writer that, when fed an input byte[] array, returns a continuation that writes the base-64 (7-bit ASCII) encoding of the input byte array.
    • byteArrayWriter

      public Writer<?,byte[]> byteArrayWriter(byte[] input)
      Returns a Writer continuation that writes the base-64 (7-bit ASCII) encoding of the input byte array.
    • byteBufferWriter

      public Writer<ByteBuffer,?> byteBufferWriter()
      Returns a Writer that, when fed an input ByteBuffer, returns a continuation that writes the base-64 (7-bit ASCII) encoding of the input byte buffer.
    • byteBufferWriter

      public Writer<?,ByteBuffer> byteBufferWriter(ByteBuffer input)
      Returns a Writer continuation that writes the base-64 (7-bit ASCII) encoding of the input byte buffer.
    • writeByteArray

      public Writer<?,?> writeByteArray(Output<?> output, byte[] input)
      Writes the base-64 (7-bit ASCII) encoding of the input byte array to the output, returning a Writer continuation that knows how to write any remaining output that couldn't be immediately generated.
    • writeByteBuffer

      public Writer<?,?> writeByteBuffer(Output<?> output, ByteBuffer input)
      Writes the base-64 (7-bit ASCII) encoding of the input byte buffer to the output, returning a Writer continuation that knows how to write any remaining output that couldn't be immediately generated.
    • standard

      public static Base64 standard()
      Returns the Base64 encoding with the standard alphabet.
    • standard

      public static Base64 standard(boolean isPadded)
      Returns the Base64 encoding with the standard alphabet, and required padding, if isPadded is true.
    • url

      public static Base64 url()
      Returns the Base64 encoding with the url and filename safe alphabet.
    • urlUnpadded

      public static Base64 urlUnpadded()
    • url

      public static Base64 url(boolean isPadded)
      Returns the Base64 encoding with the url and filename safe alphabet, and required padding, if isPadded is true.