asclass InputStreamPlusReadFully extends InputStream { public void readFully(byte[] destination) throws IOException { readFully(destination, 0, destination.length); } public void readFully(byte[] destination, int offset, int length) throws IOException { int read = 0; while (read < length) { int r = read(destination, offset+read, length-read); if (r == -1) throw new EOFException("Asked to read " + length + " bytes from " + offset + " but hit EoF at " + read); else read += r; } } }