# Base64.Decoder

public static class **Base64.Decoder** extends [Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html)  
This class implements a decoder for decoding byte data using the
Base64 encoding scheme as specified in RFC 4648 and RFC 2045.

The Base64 padding character `'='` is accepted and
interpreted as the end of the encoded byte data, but is not
required. So if the final unit of the encoded byte data only has
two or three Base64 characters (without the corresponding padding
character(s) padded), they are decoded as if followed by padding
character(s). If there is a padding character present in the
final unit, the correct number of padding character(s) must be
present, otherwise `IllegalArgumentException` (
`IOException` when reading from a Base64 stream) is thrown
during decoding.

Instances of `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Base64.Decoder.html` class are safe for use by
multiple concurrent threads.

Unless otherwise noted, passing a `null` argument to
a method of this class will cause a
`https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/NullPointerException.html` to
be thrown.

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Base64.Encoder.html`

### Public Method Summary

|---|---|
| byte\[\] | [decode](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Base64.Decoder.html#decode(java.lang.String))([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) src) Decodes a Base64 encoded String into a newly-allocated byte array using the `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Base64.html` encoding scheme. |
| int | [decode](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Base64.Decoder.html#decode(byte[],%20byte[]))(byte\[\] src, byte\[\] dst) Decodes all bytes from the input byte array using the `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Base64.html` encoding scheme, writing the results into the given output byte array, starting at offset 0. |
| byte\[\] | [decode](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Base64.Decoder.html#decode(byte[]))(byte\[\] src) Decodes all bytes from the input byte array using the `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Base64.html` encoding scheme, writing the results into a newly-allocated output byte array. |
| [ByteBuffer](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/ByteBuffer.html) | [decode](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Base64.Decoder.html#decode(java.nio.ByteBuffer))([ByteBuffer](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/ByteBuffer.html) buffer) Decodes all bytes from the input byte buffer using the `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Base64.html` encoding scheme, writing the results into a newly-allocated ByteBuffer. |
| [InputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/InputStream.html) | [wrap](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Base64.Decoder.html#wrap(java.io.InputStream))([InputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/InputStream.html) is) Returns an input stream for decoding `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Base64.html` encoded byte stream. |

### Inherited Method Summary

From class [java.lang.Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html)

|---|---|
| [Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) | [clone](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#clone())() Creates and returns a copy of this `Object`. |
| boolean | [equals](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#equals(java.lang.Object))([Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) obj) Compares this instance with the specified object and indicates if they are equal. |
| void | [finalize](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#finalize())() Invoked when the garbage collector has detected that this instance is no longer reachable. |
| final [Class](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Class.html)\<?\> | [getClass](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#getClass())() Returns the unique instance of `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Class.html` that represents this object's class. |
| int | [hashCode](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#hashCode())() Returns an integer hash code for this object. |
| final void | [notify](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#notify())() Causes a thread which is waiting on this object's monitor (by means of calling one of the `wait()` methods) to be woken up. |
| final void | [notifyAll](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#notifyAll())() Causes all threads which are waiting on this object's monitor (by means of calling one of the `wait()` methods) to be woken up. |
| [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) | [toString](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#toString())() Returns a string containing a concise, human-readable description of this object. |
| final void | [wait](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#wait(long,%20int))(long timeout, int nanos) Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object or until the specified timeout expires. |
| final void | [wait](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#wait(long))(long timeout) Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object or until the specified timeout expires. |
| final void | [wait](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#wait())() Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object. |

## Public Methods

#### public byte\[\]
**decode**
([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) src)

Decodes a Base64 encoded String into a newly-allocated byte array
using the `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Base64.html` encoding scheme.

An invocation of this method has exactly the same effect as invoking
`decode(src.getBytes(StandardCharsets.ISO_8859_1))`

##### Parameters

| src | the string to decode |
|---|---|

##### Returns

- A newly-allocated byte array containing the decoded bytes.

##### Throws

| [IllegalArgumentException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/IllegalArgumentException.html) | if `src` is not in valid Base64 scheme |
|---|---|

#### public int
**decode**
(byte\[\] src, byte\[\] dst)

Decodes all bytes from the input byte array using the `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Base64.html`
encoding scheme, writing the results into the given output byte array,
starting at offset 0.

It is the responsibility of the invoker of this method to make
sure the output byte array `dst` has enough space for decoding
all bytes from the input byte array. No bytes will be be written to
the output byte array if the output byte array is not big enough.

If the input byte array is not in valid Base64 encoding scheme
then some bytes may have been written to the output byte array before
IllegalargumentException is thrown.

##### Parameters

| src | the byte array to decode |
| dst | the output byte array |
|---|---|

##### Returns

- The number of bytes written to the output byte array

##### Throws

| [IllegalArgumentException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/IllegalArgumentException.html) | if `src` is not in valid Base64 scheme, or `dst` does not have enough space for decoding all input bytes. |
|---|---|

#### public byte\[\]
**decode**
(byte\[\] src)

Decodes all bytes from the input byte array using the `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Base64.html`
encoding scheme, writing the results into a newly-allocated output
byte array. The returned byte array is of the length of the resulting
bytes.

##### Parameters

| src | the byte array to decode |
|---|---|

##### Returns

- A newly-allocated byte array containing the decoded bytes.

##### Throws

| [IllegalArgumentException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/IllegalArgumentException.html) | if `src` is not in valid Base64 scheme |
|---|---|

#### public [ByteBuffer](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/ByteBuffer.html)
**decode**
([ByteBuffer](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/ByteBuffer.html) buffer)

Decodes all bytes from the input byte buffer using the `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Base64.html`
encoding scheme, writing the results into a newly-allocated ByteBuffer.

Upon return, the source buffer's position will be updated to
its limit; its limit will not have been changed. The returned
output buffer's position will be zero and its limit will be the
number of resulting decoded bytes

`IllegalArgumentException` is thrown if the input buffer
is not in valid Base64 encoding scheme. The position of the input
buffer will not be advanced in this case.

##### Parameters

| buffer | the ByteBuffer to decode |
|---|---|

##### Returns

- A newly-allocated byte buffer containing the decoded bytes

##### Throws

| [IllegalArgumentException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/IllegalArgumentException.html) | if `src` is not in valid Base64 scheme. |
|---|---|

#### public [InputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/InputStream.html)
**wrap**
([InputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/InputStream.html) is)

Returns an input stream for decoding `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Base64.html` encoded byte stream.

The `read` methods of the returned `InputStream` will
throw `IOException` when reading bytes that cannot be decoded.

Closing the returned input stream will close the underlying
input stream.

##### Parameters

| is | the input stream |
|---|---|

##### Returns

- the input stream for decoding the specified Base64 encoded byte stream