diff -r f67951f722a4 src/java.base/share/classes/java/util/Base64.java --- a/src/java.base/share/classes/java/util/Base64.java Wed Feb 26 21:24:02 2020 +0100 +++ b/src/java.base/share/classes/java/util/Base64.java Thu Feb 27 02:30:49 2020 +0100 @@ -667,6 +667,37 @@ throw iae; } } + /** + * Decodes a Base64 encoded String into a newly-allocated byte array + * using the {@link Base64} encoding scheme. + * + *

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. + * + * @param src + * the byte array to decode + * @param srcFrom + * the index in the {@code src} to start decoding from + * @param srcTo + * the index in the {@code src} to decoding to, exclusive + * + * @return The number of bytes written to the output byte array + * + * @throws IllegalArgumentException + * if {@code src} is not in valid Base64 scheme + * @throws IndexOutOfBoundsException if the sub-range {@code srcFrom} + * to {@code srcTo} is out of bounds. + */ + public byte[] decode(byte[] src, int srcFrom, int srcTo) { + Objects.checkFromToIndex(srcFrom, srcTo, src.length); + byte[] dst = new byte[decodedOutLength(src, srcFrom, srcTo)]; + int ret = decode0(src, srcFrom, srcTo, dst); + if (ret != dst.length) { + dst = Arrays.copyOf(dst, ret); + } + return dst; + } /** * Returns an input stream for decoding {@link Base64} encoded byte stream.