Spec-Zone .ru
спецификации, руководства, описания, API
|
public static class Base64.Decoder extends Object
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 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 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
NullPointerException
to
be thrown.
Base64.Encoder
Modifier and Type | Method and Description |
---|---|
byte[] |
decode(byte[] src)
Decodes all bytes from the input byte array using the
Base64
encoding scheme, writing the results into a newly-allocated output
byte array. |
int |
decode(byte[] src,
byte[] dst)
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. |
ByteBuffer |
decode(ByteBuffer buffer)
Decodes all bytes from the input byte buffer using the
Base64
encoding scheme, writing the results into a newly-allocated ByteBuffer. |
int |
decode(ByteBuffer src,
ByteBuffer dst)
Decodes as many bytes as possible from the input byte buffer
using the
Base64 encoding scheme, writing the resulting
bytes to the given output byte buffer. |
byte[] |
decode(String src)
Decodes a Base64 encoded String into a newly-allocated byte array
using the
Base64 encoding scheme. |
InputStream |
wrap(InputStream is)
Returns an input stream for decoding
Base64 encoded byte stream. |
public byte[] decode(byte[] src)
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.src
- the byte array to decodeIllegalArgumentException
- if src
is not in valid Base64 schemepublic byte[] decode(String src)
Base64
encoding scheme.
An invocation of this method has exactly the same effect as invoking
decode(src.getBytes(StandardCharsets.ISO_8859_1))
src
- the string to decodeIllegalArgumentException
- if src
is not in valid Base64 schemepublic int decode(byte[] src, byte[] dst)
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 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.
src
- the byte array to decodedst
- the output byte arrayIllegalArgumentException
- if src
is not in valid Base64 scheme, or dst
does not have enough space for decoding all input bytes.public ByteBuffer decode(ByteBuffer buffer)
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
buffer
- the ByteBuffer to decodeIllegalArgumentException
- if src
is not in valid Base64 scheme.public int decode(ByteBuffer src, ByteBuffer dst)
Base64
encoding scheme, writing the resulting
bytes to the given output byte buffer.
The buffers are read from, and written to, starting at their current positions. Upon return, the input and output buffers' positions will be advanced to reflect the bytes read and written, but their limits will not be modified.
If the input buffer is not in valid Base64 encoding scheme then some bytes may have been written to the output buffer before IllegalArgumentException is thrown. The positions of both input and output buffer will not be advanced in this case.
The decoding operation will end and return if all remaining bytes in the input buffer have been decoded and written to the output buffer.
The decoding operation will stop and return if the output buffer has insufficient space to decode any more input bytes. The decoding operation can be continued, if there is more bytes in input buffer to be decoded, by invoking this method again with an output buffer that has more remaining bytes. This is typically done by draining any decoded bytes from the output buffer.
Recommended Usage Example
ByteBuffer src = ...; ByteBuffer dst = ...; Base64.Decoder dec = Base64.getDecoder(); while (src.hasRemaining()) { // prepare the output byte buffer dst.clear(); dec.decode(src, dst); // read bytes from the output buffer dst.flip(); ... }
src
- the input byte buffer to decodedst
- the output byte bufferIllegalArgumentException
- if src
is not in valid Base64 scheme.public InputStream wrap(InputStream is)
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.
is
- the input stream
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2013, Oracle and/or its affiliates. All rights reserved.
DRAFT ea-b92