Added in [API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Methods](https://developer.android.com/reference/java/util/Base64.Decoder#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/java/util/Base64.Decoder#inhmethods)

# Base64.Decoder


`
public
static


class
Base64.Decoder
`


`

extends https://developer.android.com/reference/java/lang/Object


`

`


`

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | java.util.Base64.Decoder |

<br />

*** ** * ** ***

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://developer.android.com/reference/java/util/Base64.Decoder` 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://developer.android.com/reference/java/lang/NullPointerException` to
be thrown.

If the decoded byte output of the needed size can not
be allocated, the decode methods of this class will
cause an `https://developer.android.com/reference/java/lang/OutOfMemoryError`
to be thrown.
**See also:**

- `https://developer.android.com/reference/java/util/Base64.Encoder`

## Summary

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

| ### Inherited methods |
|---|---|
| From class ` https://developer.android.com/reference/java/lang/Object ` |---|---| | ` https://developer.android.com/reference/java/lang/Object` | ` https://developer.android.com/reference/java/lang/Object#clone()() ` Creates and returns a copy of this object. | | ` boolean` | ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) ` Indicates whether some other object is "equal to" this one. | | ` void` | ` https://developer.android.com/reference/java/lang/Object#finalize()() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. | | ` final https://developer.android.com/reference/java/lang/Class<?>` | ` https://developer.android.com/reference/java/lang/Object#getClass()() ` Returns the runtime class of this `Object`. | | ` int` | ` https://developer.android.com/reference/java/lang/Object#hashCode()() ` Returns a hash code value for the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notify()() ` Wakes up a single thread that is waiting on this object's monitor. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notifyAll()() ` Wakes up all threads that are waiting on this object's monitor. | | ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/java/lang/Object#toString()() ` Returns a string representation of the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait()() ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*. | ||

## Public methods

### decode

Added in [API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public byte[] decode (String src)
```

Decodes a Base64 encoded String into a newly-allocated byte array
using the `https://developer.android.com/reference/java/util/Base64` encoding scheme.

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

<br />

| Parameters ||
|---|---|
| `src` | `String`: the string to decode <br /> |

| Returns ||
|---|---|
| `byte[]` | A newly-allocated byte array containing the decoded bytes. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if `src` is not in valid Base64 scheme |

### decode

Added in [API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int decode (byte[] src, 
                byte[] dst)
```

Decodes all bytes from the input byte array using the `https://developer.android.com/reference/java/util/Base64`
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 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.

<br />

| Parameters ||
|---|---|
| `src` | `byte`: the byte array to decode <br /> |
| `dst` | `byte`: the output byte array <br /> |

| Returns ||
|---|---|
| `int` | The number of bytes written to the output byte array <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if `src` is not in valid Base64 scheme, or `dst` does not have enough space for decoding all input bytes. |

### decode

Added in [API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public byte[] decode (byte[] src)
```

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

<br />

| Parameters ||
|---|---|
| `src` | `byte`: the byte array to decode <br /> |

| Returns ||
|---|---|
| `byte[]` | A newly-allocated byte array containing the decoded bytes. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if `src` is not in valid Base64 scheme |

### decode

Added in [API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public ByteBuffer decode (ByteBuffer buffer)
```

Decodes all bytes from the input byte buffer using the `https://developer.android.com/reference/java/util/Base64`
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.

<br />

| Parameters ||
|---|---|
| `buffer` | `ByteBuffer`: the ByteBuffer to decode <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/nio/ByteBuffer` | A newly-allocated byte buffer containing the decoded bytes <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if `buffer` is not in valid Base64 scheme |

### wrap

Added in [API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public InputStream wrap (InputStream is)
```

Returns an input stream for decoding `https://developer.android.com/reference/java/util/Base64` 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.

<br />

| Parameters ||
|---|---|
| `is` | `InputStream`: the input stream <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/io/InputStream` | the input stream for decoding the specified Base64 encoded byte stream <br /> |