### Question:
ExactSizeInputStream extends FilterInputStream { @Override public int read() throws IOException { if (remaining <= 0) { return -1; } final int result = super.read(); if (result >= 0) { --remaining; } else if (remaining > 0) { throw new EOFException( "Premature EOF. Expected " + remaining + "more bytes"); } return result; } ExactSizeInputStream(InputStream in, int numBytes); @Override int available(); @Override int read(); @Override int read(final byte[] b, final int off, int len); @Override long skip(final long n); @Override boolean markSupported(); @Override void mark(int readlimit);  }### Answer:
@Test public void testReadArrayNotEnough() throws IOException { ExactSizeInputStream s = new ExactSizeInputStream(byteStream("he"), 5); byte[] buf = new byte[10]; assertEquals(2, s.read(buf, 0, 5)); try { s.read(buf, 2, 3); fail("Read buf when should be out of data"); } catch (EOFException e) { } }