Merge "IO#readFully: provide overload that fills the full array"
This commit is contained in:
commit
fb3fd69584
|
@ -91,7 +91,7 @@ public void testTimeout_readBuffer_Success1() throws IOException {
|
|||
final byte[] exp = new byte[] { 'a', 'b', 'c' };
|
||||
final byte[] act = new byte[exp.length];
|
||||
out.write(exp);
|
||||
IO.readFully(is, act, 0, act.length);
|
||||
IO.readFully(is, act);
|
||||
assertArrayEquals(exp, act);
|
||||
}
|
||||
|
||||
|
@ -110,7 +110,7 @@ public void testTimeout_readBuffer_Success2() throws IOException {
|
|||
public void testTimeout_readBuffer_Timeout() throws IOException {
|
||||
beginRead();
|
||||
try {
|
||||
IO.readFully(is, new byte[512], 0, 512);
|
||||
IO.readFully(is, new byte[512]);
|
||||
fail("incorrectly read bytes");
|
||||
} catch (InterruptedIOException e) {
|
||||
// expected
|
||||
|
|
|
@ -206,6 +206,25 @@ public static void readFully(final InputStream fd, final byte[] dst,
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read from input until the entire byte array filled, or throw an exception
|
||||
* if stream ends first.
|
||||
*
|
||||
* @param fd
|
||||
* input stream to read the data from.
|
||||
* @param dst
|
||||
* buffer that must be fully populated
|
||||
* @throws EOFException
|
||||
* the stream ended before dst was fully populated.
|
||||
* @throws java.io.IOException
|
||||
* there was an error reading from the stream.
|
||||
* @since 6.5
|
||||
*/
|
||||
public static void readFully(InputStream fd, byte[] dst)
|
||||
throws IOException {
|
||||
readFully(fd, dst, 0, dst.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read as much of the array as possible from a channel.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue