< prev index next >

src/share/classes/sun/misc/IOUtils.java

Print this page
rev 12546 : 8181432: Better processing of unresolved permissions
Reviewed-by: mullan

*** 1,7 **** /* ! * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this --- 1,7 ---- /* ! * Copyright (c) 2009, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this
*** 35,47 **** import java.util.Arrays; public class IOUtils { /** ! * Read up to <code>length</code> of bytes from <code>in</code> * until EOF is detected. ! * @param in input stream, must not be null * @param length number of bytes to read, -1 or Integer.MAX_VALUE means * read as much as possible * @param readAll if true, an EOFException will be thrown if not enough * bytes are read. Ignored when length is -1 or Integer.MAX_VALUE * @return bytes read --- 35,47 ---- import java.util.Arrays; public class IOUtils { /** ! * 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, -1 or Integer.MAX_VALUE means * read as much as possible * @param readAll if true, an EOFException will be thrown if not enough * bytes are read. Ignored when length is -1 or Integer.MAX_VALUE * @return bytes read
*** 75,80 **** --- 75,98 ---- } pos += cc; } return output; } + + /** + * Read {@code length} of bytes from {@code in}. An exception is + * thrown if there are not enough bytes in the stream. + * + * @param is input stream, must not be null + * @param length number of bytes to read, must not be negative + * @return bytes read + * @throws IOException if any IO error or a premature EOF is detected, or + * if {@code length} is negative since this length is usually also + * read from {@code is}. + */ + public static byte[] readNBytes(InputStream is, int length) throws IOException { + if (length < 0) { + throw new IOException("length cannot be negative: " + length); + } + return readFully(is, length, true); + } }
< prev index next >