Here you can find the source of readBytes(InputStream input, byte[] data, int capacity)
Parameter | Description |
---|---|
input | a parameter |
data | a parameter |
capacity | a parameter |
Parameter | Description |
---|---|
IOException | an exception |
private static int readBytes(InputStream input, byte[] data, int capacity) throws IOException
//package com.java2s; //License from project: Apache License import java.io.IOException; import java.io.InputStream; public class Main { /**//w w w.j a v a2 s .c o m * Read bytes up to capacity from the input stream into the given array. * @param input * @param data * @param capacity * @return the number of bytes read * @throws IOException */ private static int readBytes(InputStream input, byte[] data, int capacity) throws IOException { int bytes = 0; while (bytes < capacity) { // try to read (capacity - bytes) length of data int size = input.read(data, bytes, capacity - bytes); if (size < 0) { // end of file has met before the data is done. break; } bytes = bytes + size; } return bytes; } }