public class Base64extends Encoding
Base64 encoding implementation.
  • Constructor Details

    • Base64

      public Base64()
      Create a new Base64 encoder.
  • Method Details

    • getName

      public String getName()
      Description copied from class: Encoding
      Returns the name of this encoding.
      Specified by:
      getName in class Encoding
      Returns:
      the encoding name
    • encode

      public String encode(byte[] in) throws EncodingException
      Encode the bytes as base64.
      Specified by:
      encode in class Encoding
      Parameters:
      in - the byte array to encode
      Returns:
      Base64-encoded String.
      Throws:
      EncodingException - if encoding fails
    • encode

      public void encode(InputStream in, Writer strBuf) throws IOException
      More efficient than super.
      Overrides:
      encode in class Encoding
      Parameters:
      in - the input stream to encode
      strBuf - the writer to write encoded output to
      Throws:
      IOException - if reading from stream or writing fails
      See Also:
    • encodeByte

      private static int encodeByte(int b)
      The base64 character for a 6-bit value.
      Parameters:
      b - the 6-bit value to encode
      Returns:
      Encoded single byte.
    • decodeByte

      private static byte decodeByte(int c) throws IOException
      Maps one base64 character to its 6-bit value.
      Parameters:
      c - the character read
      Returns:
      the value, 0 for the = padding character
      Throws:
      IOException - if the input ended before a character
    • readIn

      private static int readIn(InputStream in) throws IOException
      Reads the next byte that is not a space or a line break.
      Parameters:
      in - the stream to read
      Returns:
      the byte, or -1 at the end of the stream
      Throws:
      IOException - if the read fails
    • decode

      public void decode(InputStream in, Buffer bout) throws IOException
      Decode base64 input into the buffer.
      Specified by:
      decode in class Encoding
      Parameters:
      in - the input stream to read data from
      bout - the buffer to write decoded data to
      Throws:
      IOException - if reading from input stream fails
      See Also: