From e5e7de4c9c404a46d4d8a920a993fba5444dc476 Mon Sep 17 00:00:00 2001 From: andrew Date: Mon, 13 Jan 2020 02:42:14 +0000 Subject: [PATCH] 8236984: Add compatibility wrapper for IOUtils.readFully Summary: Protect third party use following readFully removal in JDK-8231139 Reviewed-by: mbalao --- src/share/classes/sun/misc/IOUtils.java | 29 +++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/share/classes/sun/misc/IOUtils.java b/src/share/classes/sun/misc/IOUtils.java index 327477d91..5e6c79cb6 100644 --- a/src/share/classes/sun/misc/IOUtils.java +++ b/src/share/classes/sun/misc/IOUtils.java @@ -281,4 +281,33 @@ public class IOUtils { return n; } + /** + * Compatibility wrapper for third party users of + * {@code sun.misc.IOUtils.readFully} following its + * removal in JDK-8231139. + * + * Read up to {@code length} of bytes from {@code in} + * until EOF is detected. + * + * @param is input stream, must not be null + * @param length number of bytes to read + * @param readAll if true, an EOFException will be thrown if not enough + * bytes are read. + * @return bytes read + * @throws EOFException if there are not enough bytes in the stream + * @throws IOException if an I/O error occurs or {@code length} is negative + * @throws OutOfMemoryError if an array of the required size cannot be + * allocated. + */ + public static byte[] readFully(InputStream is, int length, boolean readAll) + throws IOException { + if (length < 0) { + throw new IOException("length cannot be negative: " + length); + } + if (readAll) { + return readExactlyNBytes(is, length); + } else { + return readNBytes(is, length); + } + } } -- GitLab