# Base64.Encoder

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

Instances of `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Base64.Encoder.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.Decoder.html`

### Public Method Summary

|---|---|
| int | [encode](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Base64.Encoder.html#encode(byte[],%20byte[]))(byte\[\] src, byte\[\] dst) Encodes all bytes from the specified byte array using the `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Base64.html` encoding scheme, writing the resulting bytes to the given output byte array, starting at offset 0. |
| byte\[\] | [encode](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Base64.Encoder.html#encode(byte[]))(byte\[\] src) Encodes all bytes from the specified byte array into a newly-allocated byte array using the `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Base64.html` encoding scheme. |
| [ByteBuffer](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/ByteBuffer.html) | [encode](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Base64.Encoder.html#encode(java.nio.ByteBuffer))([ByteBuffer](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/ByteBuffer.html) buffer) Encodes all remaining bytes from the specified byte buffer into a newly-allocated ByteBuffer using the `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Base64.html` encoding scheme. |
| [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) | [encodeToString](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Base64.Encoder.html#encodeToString(byte[]))(byte\[\] src) Encodes the specified byte array into a String using the `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Base64.html` encoding scheme. |
| [Base64.Encoder](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Base64.Encoder.html) | [withoutPadding](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Base64.Encoder.html#withoutPadding())() Returns an encoder instance that encodes equivalently to this one, but without adding any padding character at the end of the encoded byte data. |
| [OutputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/OutputStream.html) | [wrap](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Base64.Encoder.html#wrap(java.io.OutputStream))([OutputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/OutputStream.html) os) Wraps an output stream for encoding byte data using the `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Base64.html` encoding scheme. |

### 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 int
**encode**
(byte\[\] src, byte\[\] dst)

Encodes all bytes from the specified byte array using the
`https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Base64.html` encoding scheme, writing the resulting bytes to 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 encoding
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.

##### Parameters

| src | the byte array to encode |
| 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 `dst` does not have enough space for encoding all input bytes. |
|---|---|

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

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

##### Parameters

| src | the byte array to encode |
|---|---|

##### Returns

- A newly-allocated byte array containing the resulting encoded bytes.

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

Encodes all remaining bytes from the specified byte buffer into
a newly-allocated ByteBuffer using the `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Base64.html` encoding
scheme.

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 encoded bytes.

##### Parameters

| buffer | the source ByteBuffer to encode |
|---|---|

##### Returns

- A newly-allocated byte buffer containing the encoded bytes.

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

Encodes the specified byte array into a String using the `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Base64.html`
encoding scheme.

This method first encodes all input bytes into a base64 encoded
byte array and then constructs a new String by using the encoded byte
array and the `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/charset/StandardCharsets.html#ISO_8859_1` charset.

In other words, an invocation of this method has exactly the same
effect as invoking
`new String(encode(src), StandardCharsets.ISO_8859_1)`.

##### Parameters

| src | the byte array to encode |
|---|---|

##### Returns

- A String containing the resulting Base64 encoded characters

#### public [Base64.Encoder](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Base64.Encoder.html)
**withoutPadding**
()

Returns an encoder instance that encodes equivalently to this one,
but without adding any padding character at the end of the encoded
byte data.

The encoding scheme of this encoder instance is unaffected by
this invocation. The returned encoder instance should be used for
non-padding encoding operation.

##### Returns

- an equivalent encoder that encodes without adding any padding character at the end

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

Wraps an output stream for encoding byte data using the `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Base64.html`
encoding scheme.

It is recommended to promptly close the returned output stream after
use, during which it will flush all possible leftover bytes to the underlying
output stream. Closing the returned output stream will close the underlying
output stream.

##### Parameters

| os | the output stream. |
|---|---|

##### Returns

- the output stream for encoding the byte data into the specified Base64 encoded format