Decoder
open class Decoder
kotlin.Any | |
↳ | java.util.Base64.Decoder |
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 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 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 OutOfMemoryError
to be thrown.
Summary
Public methods | |
---|---|
open ByteArray! |
Decodes all bytes from the input byte array using the |
open ByteArray! |
Decodes a Base64 encoded String into a newly-allocated byte array using the |
open Int |
Decodes all bytes from the input byte array using the |
open ByteBuffer! |
decode(buffer: ByteBuffer!) Decodes all bytes from the input byte buffer using the |
open InputStream! |
wrap(is: InputStream!) Returns an input stream for decoding |
Public methods
decode
open fun decode(src: ByteArray!): ByteArray!
Decodes all bytes from the input byte array using the 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.
Parameters | |
---|---|
src |
ByteArray!: the byte array to decode |
Return | |
---|---|
ByteArray! |
A newly-allocated byte array containing the decoded bytes. |
Exceptions | |
---|---|
java.lang.IllegalArgumentException |
if src is not in valid Base64 scheme |
decode
open fun decode(src: String!): ByteArray!
Decodes a Base64 encoded String into a newly-allocated byte array using the Base64
encoding scheme.
An invocation of this method has exactly the same effect as invoking decode(src.getBytes(StandardCharsets.ISO_8859_1))
Parameters | |
---|---|
src |
String!: the string to decode |
Return | |
---|---|
ByteArray! |
A newly-allocated byte array containing the decoded bytes. |
Exceptions | |
---|---|
java.lang.IllegalArgumentException |
if src is not in valid Base64 scheme |
decode
open fun decode(
src: ByteArray!,
dst: ByteArray!
): Int
Decodes all bytes from the input byte array using the 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.
Parameters | |
---|---|
src |
ByteArray!: the byte array to decode |
dst |
ByteArray!: the output byte array |
Return | |
---|---|
Int |
The number of bytes written to the output byte array |
Exceptions | |
---|---|
java.lang.IllegalArgumentException |
if src is not in valid Base64 scheme, or dst does not have enough space for decoding all input bytes. |
decode
open fun decode(buffer: ByteBuffer!): ByteBuffer!
Decodes all bytes from the input byte buffer using the 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.
Parameters | |
---|---|
buffer |
ByteBuffer!: the ByteBuffer to decode |
Return | |
---|---|
ByteBuffer! |
A newly-allocated byte buffer containing the decoded bytes |
Exceptions | |
---|---|
java.lang.IllegalArgumentException |
if buffer is not in valid Base64 scheme |
wrap
open fun wrap(is: InputStream!): InputStream!
Returns an input stream for decoding 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.
Parameters | |
---|---|
is |
InputStream!: the input stream |
Return | |
---|---|
InputStream! |
the input stream for decoding the specified Base64 encoded byte stream |