diff options
author | andrew <unknown> | 2020-01-13 02:42:14 +0000 |
---|---|---|
committer | bell-sw <liberica@bell-sw.com> | 2020-01-19 09:13:25 +0300 |
commit | 5e7b05bf6ddfdb49ceee54ce112253ed795d68b6 (patch) | |
tree | 219182cf584ed391cbdeefe527e78b845dec5516 | |
parent | 1e7b93fa2b8e39e94a309474d1e0729340a88e87 (diff) | |
download | jdk8u_jdk-5e7b05bf6ddfdb49ceee54ce112253ed795d68b6.tar.gz |
8236984: Add compatibility wrapper for IOUtils.readFully
Summary: Protect third party use following readFully removal in JDK-8231139
Reviewed-by: mbalao
-rw-r--r-- | src/share/classes/sun/misc/IOUtils.java | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/share/classes/sun/misc/IOUtils.java b/src/share/classes/sun/misc/IOUtils.java index 327477d912..5e6c79cb64 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); + } + } } |