Reads some bytes from an input stream and stores them into the buffer array b. This method blocks until len bytes of input data have been read into the array, or end of file is detected. The number of bytes read is returned, possibly zero. Does not close the stream. A caller can
(InputStream in, byte[] b, int off, int len)
| 878 | */ |
| 879 | |
| 880 | @CanIgnoreReturnValue |
| 881 | // Sometimes you don't care how many bytes you actually read, I guess. |
| 882 | // (You know that it's either going to read len bytes or stop at EOF.) |
| 883 | public static int read(InputStream in, byte[] b, int off, int len) throws IOException { |
| 884 | checkNotNull(in); |
| 885 | checkNotNull(b); |
| 886 | if (len < 0) { |
| 887 | throw new IndexOutOfBoundsException("len is negative"); |
| 888 | } |
| 889 | |
| 890 | int total = 0; |
| 891 | while (total < len) { |
| 892 | int result = in.read(b, off + total, len - total); |
| 893 | if (result == -1) { |
| 894 | break; |
| 895 | } |
| 896 | total += result; |
| 897 | } |
| 898 | return total; |
| 899 | } |
| 900 | } |
no test coverage detected