Read until EOF or the buffer is filled. @param is The source to read from @param buf The buffer to write to @return The number of bytes read @throws IOException If an I/O error occurs during the read
(InputStream is, byte[] buf)
| 99 | * @throws IOException If an I/O error occurs during the read |
| 100 | */ |
| 101 | public static int readFully(InputStream is, byte[] buf) throws IOException { |
| 102 | int bytesRead = 0; |
| 103 | int read; |
| 104 | while (bytesRead < buf.length && ((read = is.read(buf, bytesRead, buf.length - bytesRead)) >= 0)) { |
| 105 | bytesRead += read; |
| 106 | } |
| 107 | return bytesRead; |
| 108 | } |
| 109 | } |
no test coverage detected