Class Base64

java.lang.Object
org.apache.commons.net.util.Base64

@Deprecated public class Base64 extends Object
Deprecated.
Use Base64.
Provides Base64 encoding and decoding as defined by RFC 2045.

This class implements section 6.8. Base64 Content-Transfer-Encoding from RFC 2045 Multipurpose Internet Mail Extensions (MIME) Part One: Format of Internet Message Bodies by Freed and Borenstein.

The class can be parameterized in the following manner with various constructors:

  • URL-safe mode: Default off.
  • Line length: Default 76. Line length that aren't multiples of 4 will still essentially end up being multiples of 4 in the encoded data.
  • Line separator: Default is CRLF ("\r\n")

Since this class operates directly on byte streams, and not character streams, it is hard-coded to only encode/decode character encodings which are compatible with the lower 127 ASCII chart (ISO-8859-1, Windows-1252, UTF-8, etc).

Since:
2.2
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private byte[]
    Deprecated.
    Buffer for streaming.
    private static final byte[]
    Deprecated.
    Chunk separator per RFC 2045 section 2.1.
    (package private) static final int
    Deprecated.
    Chunk size per RFC 2045 section 6.8.
    private int
    Deprecated.
    Variable tracks how many characters have been written to the current line.
    private static final byte[]
    Deprecated.
    This array is a lookup table that translates Unicode characters drawn from the "Base64 Alphabet" (as specified in Table 1 of RFC 2045) into their 6-bit positive integer equivalents.
    private final int
    Deprecated.
    Convenience variable to help us determine when our buffer is going to run out of room and needs resizing.
    private static final int
    Deprecated.
     
    private static final int
    Deprecated.
     
    private final int
    Deprecated.
    Convenience variable to help us determine when our buffer is going to run out of room and needs resizing.
    private final byte[]
    Deprecated.
    Encode table to use: either STANDARD or URL_SAFE.
    private boolean
    Deprecated.
    Boolean flag to indicate the EOF has been reached.
    private final int
    Deprecated.
    Line length for encoding.
    private final byte[]
    Deprecated.
    Line separator for encoding.
    private static final int
    Deprecated.
    Mask used to extract 6 bits, used when encoding
    private static final int
    Deprecated.
    Mask used to extract 8 bits, used in decoding base64 bytes
    private int
    Deprecated.
    Writes to the buffer only occur after every 3 reads when encoding, an every 4 reads when decoding.
    private static final byte
    Deprecated.
    Byte used to pad output.
    private int
    Deprecated.
    Position where next character should be written in the buffer.
    private int
    Deprecated.
    Position where next character should be read from the buffer.
    private static final byte[]
    Deprecated.
    This array is a lookup table that translates 6-bit positive integer index values into their "Base64 Alphabet" equivalents as specified in Table 1 of RFC 2045.
    private static final byte[]
    Deprecated.
    This is a copy of the STANDARD_ENCODE_TABLE above, but with + and / changed to - and _ to make the encoded Base64 results more URL-SAFE.
    private int
    Deprecated.
    Placeholder for the 3 bytes we're dealing with for our base64 logic.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Deprecated.
    Creates a Base64 codec used for decoding (all modes) and encoding in URL-unsafe mode.
    Base64(boolean urlSafe)
    Deprecated.
    Creates a Base64 codec used for decoding (all modes) and encoding in the given URL-safe mode.
    Base64(int lineLength)
    Deprecated.
    Creates a Base64 codec used for decoding (all modes) and encoding in URL-unsafe mode.
    Base64(int lineLength, byte[] lineSeparator)
    Deprecated.
    Creates a Base64 codec used for decoding (all modes) and encoding in URL-unsafe mode.
    Base64(int lineLength, byte[] lineSeparator, boolean urlSafe)
    Deprecated.
    Creates a Base64 codec used for decoding (all modes) and encoding in URL-unsafe mode.
  • Method Summary

    Modifier and Type
    Method
    Description
    (package private) int
    Deprecated.
    Returns the amount of buffered data available for reading.
    private static boolean
    containsBase64Byte(byte[] arrayOctet)
    Deprecated.
    Tests a given byte array to see if it contains any valid character within the Base64 alphabet.
    byte[]
    decode(byte[] pArray)
    Deprecated.
    Decodes a byte array containing characters in the Base64 alphabet.
    (package private) void
    decode(byte[] in, int inPos, int inAvail)
    Deprecated.
    Decodes all of the provided data, starting at inPos, for inAvail bytes.
    byte[]
    decode(String pArray)
    Deprecated.
    Decodes a String containing characters in the Base64 alphabet.
    static byte[]
    decodeBase64(byte[] base64Data)
    Deprecated.
    Decodes Base64 data into octets.
    static byte[]
    decodeBase64(String base64String)
    Deprecated.
    Decodes a Base64 String into octets.
    static BigInteger
    decodeInteger(byte[] pArray)
    Deprecated.
    Decodes a byte64-encoded integer according to crypto standards such as W3C's XML-Signature
    byte[]
    encode(byte[] pArray)
    Deprecated.
    Encodes a byte[] containing binary data, into a byte[] containing characters in the Base64 alphabet.
    (package private) void
    encode(byte[] in, int inPos, int inAvail)
    Deprecated.
    Encodes all of the provided data, starting at inPos, for inAvail bytes.
    static byte[]
    encodeBase64(byte[] binaryData)
    Deprecated.
    Encodes binary data using the base64 algorithm but does not chunk the output.
    static byte[]
    encodeBase64(byte[] binaryData, boolean isChunked)
    Deprecated.
    Encodes binary data using the base64 algorithm, optionally chunking the output into 76 character blocks.
    static byte[]
    encodeBase64(byte[] binaryData, boolean isChunked, boolean urlSafe)
    Deprecated.
    Encodes binary data using the base64 algorithm, optionally chunking the output into 76 character blocks.
    static byte[]
    encodeBase64(byte[] binaryData, boolean isChunked, boolean urlSafe, int maxResultSize)
    Deprecated.
    Encodes binary data using the base64 algorithm, optionally chunking the output into 76 character blocks.
    static byte[]
    encodeBase64Chunked(byte[] binaryData)
    Deprecated.
    Encodes binary data using the base64 algorithm and chunks the encoded output into 76 character blocks
    static String
    encodeBase64String(byte[] binaryData)
    Deprecated.
    Encodes binary data using the base64 algorithm into 76 character blocks separated by CRLF.
    static String
    encodeBase64String(byte[] binaryData, boolean useChunking)
    Deprecated.
    Encodes binary data using the base64 algorithm.
    static String
    encodeBase64StringUnChunked(byte[] binaryData)
    Deprecated.
    Encodes binary data using the base64 algorithm, without using chunking.
    static byte[]
    encodeBase64URLSafe(byte[] binaryData)
    Deprecated.
    Encodes binary data using a URL-safe variation of the base64 algorithm but does not chunk the output.
    static String
    encodeBase64URLSafeString(byte[] binaryData)
    Deprecated.
    Encodes binary data using a URL-safe variation of the base64 algorithm but does not chunk the output.
    static byte[]
    Deprecated.
    Encodes to a byte64-encoded integer according to crypto standards such as W3C's XML-Signature
    encodeToString(byte[] pArray)
    Deprecated.
    Encodes a byte[] containing binary data, into a String containing characters in the Base64 alphabet.
    private byte[]
    Deprecated.
     
    private static long
    getEncodeLength(byte[] pArray, int chunkSize, byte[] chunkSeparator)
    Deprecated.
    Pre-calculates the amount of space needed to base64-encode the supplied array.
    (package private) int
    Deprecated.
     
    (package private) byte[]
    Deprecated.
     
    (package private) boolean
    Deprecated.
    Returns true if this Base64 object has buffered data for reading.
    static boolean
    isArrayByteBase64(byte[] arrayOctet)
    Deprecated.
    Tests a given byte array to see if it contains only valid characters within the Base64 alphabet.
    static boolean
    isBase64(byte octet)
    Deprecated.
    Returns whether or not the octet is in the base 64 alphabet.
    boolean
    Deprecated.
    Returns our current encode mode.
    private static boolean
    isWhiteSpace(byte byteToCheck)
    Deprecated.
    Checks if a byte value is whitespace or not.
    private static String
    newStringUtf8(byte[] encode)
    Deprecated.
     
    (package private) int
    readResults(byte[] b, int bPos, int bAvail)
    Deprecated.
    Extracts buffered data into the provided byte[] array, starting at position bPos, up to a maximum of bAvail bytes.
    private void
    Deprecated.
    Resets this Base64 object to its initial newly constructed state.
    private void
    Deprecated.
    Doubles our buffer.
    (package private) void
    setInitialBuffer(byte[] out, int outPos, int outAvail)
    Deprecated.
    Sets the streaming buffer.
    (package private) static byte[]
    Deprecated.
    Returns a byte-array representation of a BigInteger without sign bit.

    Methods inherited from class java.lang.Object

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

    • DEFAULT_BUFFER_RESIZE_FACTOR

      private static final int DEFAULT_BUFFER_RESIZE_FACTOR
      Deprecated.
      See Also:
    • DEFAULT_BUFFER_SIZE

      private static final int DEFAULT_BUFFER_SIZE
      Deprecated.
      See Also:
    • CHUNK_SIZE

      static final int CHUNK_SIZE
      Deprecated.
      Chunk size per RFC 2045 section 6.8.

      The 76 character limit does not count the trailing CRLF, but counts all other characters, including any equal signs.

      See Also:
    • CHUNK_SEPARATOR

      private static final byte[] CHUNK_SEPARATOR
      Deprecated.
      Chunk separator per RFC 2045 section 2.1.
      See Also:
    • STANDARD_ENCODE_TABLE

      private static final byte[] STANDARD_ENCODE_TABLE
      Deprecated.
      This array is a lookup table that translates 6-bit positive integer index values into their "Base64 Alphabet" equivalents as specified in Table 1 of RFC 2045. Thanks to "commons" project in ws.apache.org for this code.
    • URL_SAFE_ENCODE_TABLE

      private static final byte[] URL_SAFE_ENCODE_TABLE
      Deprecated.
      This is a copy of the STANDARD_ENCODE_TABLE above, but with + and / changed to - and _ to make the encoded Base64 results more URL-SAFE. This table is only used when the Base64's mode is set to URL-SAFE.
    • PAD

      private static final byte PAD
      Deprecated.
      Byte used to pad output.
      See Also:
    • DECODE_TABLE

      private static final byte[] DECODE_TABLE
      Deprecated.
      This array is a lookup table that translates Unicode characters drawn from the "Base64 Alphabet" (as specified in Table 1 of RFC 2045) into their 6-bit positive integer equivalents. Characters that are not in the Base64 alphabet but fall within the bounds of the array are translated to -1. Note: '+' and '-' both decode to 62. '/' and '_' both decode to 63. This means decoder seamlessly handles both URL_SAFE and STANDARD base64. (The encoder, on the other hand, needs to know ahead of time what to emit). Thanks to "commons" project in ws.apache.org for this code
    • MASK_6BITS

      private static final int MASK_6BITS
      Deprecated.
      Mask used to extract 6 bits, used when encoding
      See Also:
    • MASK_8BITS

      private static final int MASK_8BITS
      Deprecated.
      Mask used to extract 8 bits, used in decoding base64 bytes
      See Also:
    • encodeTable

      private final byte[] encodeTable
      Deprecated.
      Encode table to use: either STANDARD or URL_SAFE. Note: the DECODE_TABLE above remains static because it is able to decode both STANDARD and URL_SAFE streams, but the encodeTable must be a member variable, so we can switch between the two modes.
    • lineLength

      private final int lineLength
      Deprecated.
      Line length for encoding. Not used when decoding. A value of zero or less implies no chunking of the base64 encoded data.
    • lineSeparator

      private final byte[] lineSeparator
      Deprecated.
      Line separator for encoding. Not used when decoding. Only used if lineLength > 0.
    • decodeSize

      private final int decodeSize
      Deprecated.
      Convenience variable to help us determine when our buffer is going to run out of room and needs resizing. decodeSize = 3 + lineSeparator.length;
    • encodeSize

      private final int encodeSize
      Deprecated.
      Convenience variable to help us determine when our buffer is going to run out of room and needs resizing. encodeSize = 4 + lineSeparator.length;
    • buffer

      private byte[] buffer
      Deprecated.
      Buffer for streaming.
    • pos

      private int pos
      Deprecated.
      Position where next character should be written in the buffer.
    • readPos

      private int readPos
      Deprecated.
      Position where next character should be read from the buffer.
    • currentLinePos

      private int currentLinePos
      Deprecated.
      Variable tracks how many characters have been written to the current line. Only used when encoding. We use it to make sure each encoded line never goes beyond lineLength (if lineLength > 0).
    • modulus

      private int modulus
      Deprecated.
      Writes to the buffer only occur after every 3 reads when encoding, an every 4 reads when decoding. This variable helps track that.
    • eof

      private boolean eof
      Deprecated.
      Boolean flag to indicate the EOF has been reached. Once EOF has been reached, this Base64 object becomes useless, and must be thrown away.
    • x

      private int x
      Deprecated.
      Placeholder for the 3 bytes we're dealing with for our base64 logic. Bitwise operations store and extract the base64 encoding or decoding from this variable.
  • Constructor Details

    • Base64

      public Base64()
      Deprecated.
      Creates a Base64 codec used for decoding (all modes) and encoding in URL-unsafe mode.

      When encoding the line length is 76, the line separator is CRLF, and the encoding table is STANDARD_ENCODE_TABLE.

      When decoding all variants are supported.

    • Base64

      public Base64(boolean urlSafe)
      Deprecated.
      Creates a Base64 codec used for decoding (all modes) and encoding in the given URL-safe mode.

      When encoding the line length is 76, the line separator is CRLF, and the encoding table is STANDARD_ENCODE_TABLE.

      When decoding all variants are supported.

      Parameters:
      urlSafe - if true, URL-safe encoding is used. In most cases this should be set to false.
      Since:
      1.4
    • Base64

      public Base64(int lineLength)
      Deprecated.
      Creates a Base64 codec used for decoding (all modes) and encoding in URL-unsafe mode.

      When encoding the line length is given in the constructor, the line separator is CRLF, and the encoding table is STANDARD_ENCODE_TABLE.

      Line lengths that aren't multiples of 4 will still essentially end up being multiples of 4 in the encoded data.

      When decoding all variants are supported.

      Parameters:
      lineLength - Each line of encoded data will be at most of the given length (rounded down to the nearest multiple of 4). If lineLength <= 0, then the output will not be divided into lines (chunks). Ignored when decoding.
      Since:
      1.4
    • Base64

      public Base64(int lineLength, byte[] lineSeparator)
      Deprecated.
      Creates a Base64 codec used for decoding (all modes) and encoding in URL-unsafe mode.

      When encoding the line length and line separator are given in the constructor, and the encoding table is STANDARD_ENCODE_TABLE.

      Line lengths that aren't multiples of 4 will still essentially end up being multiples of 4 in the encoded data.

      When decoding all variants are supported.

      Parameters:
      lineLength - Each line of encoded data will be at most of the given length (rounded down to the nearest multiple of 4). If lineLength <= 0, then the output will not be divided into lines (chunks). Ignored when decoding.
      lineSeparator - Each line of encoded data will end with this sequence of bytes.
      Throws:
      IllegalArgumentException - Thrown when the provided lineSeparator included some base64 characters.
      Since:
      1.4
    • Base64

      public Base64(int lineLength, byte[] lineSeparator, boolean urlSafe)
      Deprecated.
      Creates a Base64 codec used for decoding (all modes) and encoding in URL-unsafe mode.

      When encoding the line length and line separator are given in the constructor, and the encoding table is STANDARD_ENCODE_TABLE.

      Line lengths that aren't multiples of 4 will still essentially end up being multiples of 4 in the encoded data.

      When decoding all variants are supported.

      Parameters:
      lineLength - Each line of encoded data will be at most of the given length (rounded down to the nearest multiple of 4). If lineLength <= 0, then the output will not be divided into lines (chunks). Ignored when decoding.
      lineSeparator - Each line of encoded data will end with this sequence of bytes.
      urlSafe - Instead of emitting '+' and '/' we emit '-' and '_' respectively. urlSafe is only applied to encode operations. Decoding seamlessly handles both modes.
      Throws:
      IllegalArgumentException - The provided lineSeparator included some base64 characters. That's not going to work!
      Since:
      1.4
  • Method Details

    • containsBase64Byte

      private static boolean containsBase64Byte(byte[] arrayOctet)
      Deprecated.
      Tests a given byte array to see if it contains any valid character within the Base64 alphabet.
      Parameters:
      arrayOctet - byte array to test
      Returns:
      true if any byte is a valid character in the Base64 alphabet; false otherwise
    • decodeBase64

      public static byte[] decodeBase64(byte[] base64Data)
      Deprecated.
      Decodes Base64 data into octets.
      Parameters:
      base64Data - Byte array containing Base64 data
      Returns:
      Array containing decoded data.
    • decodeBase64

      public static byte[] decodeBase64(String base64String)
      Deprecated.
      Decodes a Base64 String into octets.
      Parameters:
      base64String - String containing Base64 data
      Returns:
      Array containing decoded data.
      Since:
      1.4
    • decodeInteger

      public static BigInteger decodeInteger(byte[] pArray)
      Deprecated.
      Decodes a byte64-encoded integer according to crypto standards such as W3C's XML-Signature
      Parameters:
      pArray - a byte array containing base64 character data
      Returns:
      A BigInteger
      Since:
      1.4
    • encodeBase64

      public static byte[] encodeBase64(byte[] binaryData)
      Deprecated.
      Encodes binary data using the base64 algorithm but does not chunk the output.
      Parameters:
      binaryData - binary data to encode
      Returns:
      byte[] containing Base64 characters in their UTF-8 representation.
    • encodeBase64

      public static byte[] encodeBase64(byte[] binaryData, boolean isChunked)
      Deprecated.
      Encodes binary data using the base64 algorithm, optionally chunking the output into 76 character blocks.
      Parameters:
      binaryData - Array containing binary data to encode.
      isChunked - if true this encoder will chunk the base64 output into 76 character blocks
      Returns:
      Base64-encoded data.
      Throws:
      IllegalArgumentException - Thrown when the input array needs an output array bigger than Integer.MAX_VALUE
    • encodeBase64

      public static byte[] encodeBase64(byte[] binaryData, boolean isChunked, boolean urlSafe)
      Deprecated.
      Encodes binary data using the base64 algorithm, optionally chunking the output into 76 character blocks.
      Parameters:
      binaryData - Array containing binary data to encode.
      isChunked - if true this encoder will chunk the base64 output into 76 character blocks
      urlSafe - if true this encoder will emit - and _ instead of the usual + and / characters.
      Returns:
      Base64-encoded data.
      Throws:
      IllegalArgumentException - Thrown when the input array needs an output array bigger than Integer.MAX_VALUE
      Since:
      1.4
    • encodeBase64

      public static byte[] encodeBase64(byte[] binaryData, boolean isChunked, boolean urlSafe, int maxResultSize)
      Deprecated.
      Encodes binary data using the base64 algorithm, optionally chunking the output into 76 character blocks.
      Parameters:
      binaryData - Array containing binary data to encode.
      isChunked - if true this encoder will chunk the base64 output into 76 character blocks
      urlSafe - if true this encoder will emit - and _ instead of the usual + and / characters.
      maxResultSize - The maximum result size to accept.
      Returns:
      Base64-encoded data.
      Throws:
      IllegalArgumentException - Thrown when the input array needs an output array bigger than maxResultSize
      Since:
      1.4
    • encodeBase64Chunked

      public static byte[] encodeBase64Chunked(byte[] binaryData)
      Deprecated.
      Encodes binary data using the base64 algorithm and chunks the encoded output into 76 character blocks
      Parameters:
      binaryData - binary data to encode
      Returns:
      Base64 characters chunked in 76 character blocks
    • encodeBase64String

      public static String encodeBase64String(byte[] binaryData)
      Deprecated.
      Encodes binary data using the base64 algorithm into 76 character blocks separated by CRLF.

      For a non-chunking version, see encodeBase64StringUnChunked(byte[]).

      Parameters:
      binaryData - binary data to encode
      Returns:
      String containing Base64 characters.
      Since:
      1.4
    • encodeBase64String

      public static String encodeBase64String(byte[] binaryData, boolean useChunking)
      Deprecated.
      Encodes binary data using the base64 algorithm.
      Parameters:
      binaryData - binary data to encode
      useChunking - whether to split the output into chunks
      Returns:
      String containing Base64 characters.
      Since:
      3.2
    • encodeBase64StringUnChunked

      public static String encodeBase64StringUnChunked(byte[] binaryData)
      Deprecated.
      Encodes binary data using the base64 algorithm, without using chunking.

      For a chunking version, see encodeBase64String(byte[]).

      Parameters:
      binaryData - binary data to encode
      Returns:
      String containing Base64 characters.
      Since:
      3.2
    • encodeBase64URLSafe

      public static byte[] encodeBase64URLSafe(byte[] binaryData)
      Deprecated.
      Encodes binary data using a URL-safe variation of the base64 algorithm but does not chunk the output. The url-safe variation emits - and _ instead of + and / characters.
      Parameters:
      binaryData - binary data to encode
      Returns:
      byte[] containing Base64 characters in their UTF-8 representation.
      Since:
      1.4
    • encodeBase64URLSafeString

      public static String encodeBase64URLSafeString(byte[] binaryData)
      Deprecated.
      Encodes binary data using a URL-safe variation of the base64 algorithm but does not chunk the output. The url-safe variation emits - and _ instead of + and / characters.
      Parameters:
      binaryData - binary data to encode
      Returns:
      String containing Base64 characters
      Since:
      1.4
    • encodeInteger

      public static byte[] encodeInteger(BigInteger bigInt)
      Deprecated.
      Encodes to a byte64-encoded integer according to crypto standards such as W3C's XML-Signature
      Parameters:
      bigInt - a BigInteger
      Returns:
      A byte array containing base64 character data
      Throws:
      NullPointerException - if null is passed in
      Since:
      1.4
    • getEncodeLength

      private static long getEncodeLength(byte[] pArray, int chunkSize, byte[] chunkSeparator)
      Deprecated.
      Pre-calculates the amount of space needed to base64-encode the supplied array.
      Parameters:
      pArray - byte[] array which will later be encoded
      chunkSize - line-length of the output (invalid input: '<'= 0 means no chunking) between each chunkSeparator (e.g. CRLF).
      chunkSeparator - the sequence of bytes used to separate chunks of output (e.g. CRLF).
      Returns:
      amount of space needed to encode the supplied array. Returns a long since a max-len array will require Integer.MAX_VALUE + 33%.
    • isArrayByteBase64

      public static boolean isArrayByteBase64(byte[] arrayOctet)
      Deprecated.
      Tests a given byte array to see if it contains only valid characters within the Base64 alphabet. Currently, the method treats whitespace as valid.
      Parameters:
      arrayOctet - byte array to test
      Returns:
      true if all bytes are valid characters in the Base64 alphabet or if the byte array is empty; false, otherwise
    • isBase64

      public static boolean isBase64(byte octet)
      Deprecated.
      Returns whether or not the octet is in the base 64 alphabet.
      Parameters:
      octet - The value to test
      Returns:
      true if the value is defined in the base 64 alphabet, false otherwise.
      Since:
      1.4
    • isWhiteSpace

      private static boolean isWhiteSpace(byte byteToCheck)
      Deprecated.
      Checks if a byte value is whitespace or not.
      Parameters:
      byteToCheck - the byte to check
      Returns:
      true if byte is whitespace, false otherwise
    • newStringUtf8

      private static String newStringUtf8(byte[] encode)
      Deprecated.
    • toIntegerBytes

      static byte[] toIntegerBytes(BigInteger bigInt)
      Deprecated.
      Returns a byte-array representation of a BigInteger without sign bit.
      Parameters:
      bigInt - BigInteger to be converted
      Returns:
      a byte array representation of the BigInteger parameter
    • avail

      int avail()
      Deprecated.
      Returns the amount of buffered data available for reading.
      Returns:
      The amount of buffered data available for reading.
    • decode

      public byte[] decode(byte[] pArray)
      Deprecated.
      Decodes a byte array containing characters in the Base64 alphabet.
      Parameters:
      pArray - A byte array containing Base64 character data
      Returns:
      a byte array containing binary data; will return null if provided byte array is null.
    • decode

      void decode(byte[] in, int inPos, int inAvail)
      Deprecated.

      Decodes all of the provided data, starting at inPos, for inAvail bytes. Should be called at least twice: once with the data to decode, and once with inAvail set to "-1" to alert decoder that EOF has been reached. The "-1" call is not necessary when decoding, but it doesn't hurt, either.

      Ignores all non-base64 characters. This is how chunked (e.g. 76 character) data is handled, since CR and LF are silently ignored, but has implications for other bytes, too. This method subscribes to the garbage-in, garbage-out philosophy: it will not check the provided data for validity.

      Thanks to "commons" project in ws.apache.org for the bitwise operations, and general approach.

      See: http://svn.apache.org/repos/asf/webservices/commons/trunk/modules/util/

      Parameters:
      in - byte[] array of ascii data to base64 decode.
      inPos - Position to start reading data from.
      inAvail - Amount of bytes available from input for encoding.
    • decode

      public byte[] decode(String pArray)
      Deprecated.
      Decodes a String containing characters in the Base64 alphabet.
      Parameters:
      pArray - A String containing Base64 character data, must not be null
      Returns:
      a byte array containing binary data
      Since:
      1.4
    • encode

      public byte[] encode(byte[] pArray)
      Deprecated.
      Encodes a byte[] containing binary data, into a byte[] containing characters in the Base64 alphabet.
      Parameters:
      pArray - a byte array containing binary data
      Returns:
      A byte array containing only Base64 character data
    • encode

      void encode(byte[] in, int inPos, int inAvail)
      Deprecated.

      Encodes all of the provided data, starting at inPos, for inAvail bytes. Must be called at least twice: once with the data to encode, and once with inAvail set to "-1" to alert encoder that EOF has been reached, so flush last remaining bytes (if not multiple of 3).

      Thanks to "commons" project in ws.apache.org for the bitwise operations, and general approach.

      See: http://svn.apache.org/repos/asf/webservices/commons/trunk/modules/util/

      Parameters:
      in - byte[] array of binary data to base64 encode.
      inPos - Position to start reading data from.
      inAvail - Amount of bytes available from input for encoding.
    • encodeToString

      public String encodeToString(byte[] pArray)
      Deprecated.
      Encodes a byte[] containing binary data, into a String containing characters in the Base64 alphabet.
      Parameters:
      pArray - a byte array containing binary data
      Returns:
      A String containing only Base64 character data
      Since:
      1.4
    • getBytesUtf8

      private byte[] getBytesUtf8(String pArray)
      Deprecated.
    • getLineLength

      int getLineLength()
      Deprecated.
    • getLineSeparator

      byte[] getLineSeparator()
      Deprecated.
    • hasData

      boolean hasData()
      Deprecated.
      Returns true if this Base64 object has buffered data for reading.
      Returns:
      true if there is Base64 object still available for reading.
    • isUrlSafe

      public boolean isUrlSafe()
      Deprecated.
      Returns our current encode mode. True if we're URL-SAFE, false otherwise.
      Returns:
      true if we're in URL-SAFE mode, false otherwise.
      Since:
      1.4
    • readResults

      int readResults(byte[] b, int bPos, int bAvail)
      Deprecated.
      Extracts buffered data into the provided byte[] array, starting at position bPos, up to a maximum of bAvail bytes. Returns how many bytes were actually extracted.
      Parameters:
      b - byte[] array to extract the buffered data into.
      bPos - position in byte[] array to start extraction at.
      bAvail - amount of bytes we're allowed to extract. We may extract fewer (if fewer are available).
      Returns:
      The number of bytes successfully extracted into the provided byte[] array.
    • reset

      private void reset()
      Deprecated.
      Resets this Base64 object to its initial newly constructed state.
    • resizeBuffer

      private void resizeBuffer()
      Deprecated.
      Doubles our buffer.
    • setInitialBuffer

      void setInitialBuffer(byte[] out, int outPos, int outAvail)
      Deprecated.
      Sets the streaming buffer. This is a small optimization where we try to buffer directly to the consumer's output array for one round (if the consumer calls this method first) instead of starting our own buffer.
      Parameters:
      out - byte[] array to buffer directly to.
      outPos - Position to start buffering into.
      outAvail - Amount of bytes available for direct buffering.