- java.lang.Object
- 
- java.util.Base64.Decoder
 
- 
- Enclosing class:
- Base64
 
 public static class Base64.Decoder extends Object 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, otherwiseIllegalArgumentException(IOExceptionwhen reading from a Base64 stream) is thrown during decoding.Instances of Base64.Decoderclass are safe for use by multiple concurrent threads.Unless otherwise noted, passing a nullargument to a method of this class will cause aNullPointerExceptionto be thrown.- Since:
- 1.8
- See Also:
- Base64.Encoder
 
- 
- 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description byte[]decode(byte[] src)Decodes all bytes from the input byte array using theBase64encoding scheme, writing the results into a newly-allocated output byte array.intdecode(byte[] src, byte[] dst)Decodes all bytes from the input byte array using theBase64encoding scheme, writing the results into the given output byte array, starting at offset 0.byte[]decode(String src)Decodes a Base64 encoded String into a newly-allocated byte array using theBase64encoding scheme.ByteBufferdecode(ByteBuffer buffer)Decodes all bytes from the input byte buffer using theBase64encoding scheme, writing the results into a newly-allocated ByteBuffer.InputStreamwrap(InputStream is)Returns an input stream for decodingBase64encoded byte stream.
 
- 
- 
- 
Method Detail- 
decodepublic byte[] decode(byte[] src) Decodes all bytes from the input byte array using theBase64encoding 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- if- srcis not in valid Base64 scheme
 
 - 
decodepublic byte[] decode(String src) Decodes a Base64 encoded String into a newly-allocated byte array using theBase64encoding 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- if- srcis not in valid Base64 scheme
 
 - 
decodepublic int decode(byte[] src, byte[] dst)Decodes all bytes from the input byte array using theBase64encoding 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 dsthas 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- the byte array to decode
- dst- the output byte array
- Returns:
- The number of bytes written to the output byte array
- Throws:
- IllegalArgumentException- if- srcis not in valid Base64 scheme, or- dstdoes not have enough space for decoding all input bytes.
 
 - 
decodepublic ByteBuffer decode(ByteBuffer buffer) Decodes all bytes from the input byte buffer using theBase64encoding 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 IllegalArgumentExceptionis 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- if- srcis not in valid Base64 scheme.
 
 - 
wrappublic InputStream wrap(InputStream is) Returns an input stream for decodingBase64encoded byte stream.The readmethods of the returnedInputStreamwill throwIOExceptionwhen 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
 
 
- 
 
-