/** Reads all data from the underlying {@link InputStream}, while notifying the * observers. * @throws IOException The underlying {@link InputStream}, or either of the * observers has thrown an exception. */ public void consume() throws IOException { final byte[] buffer = new byte[8192]; for (;;) { final int res = read(buffer); if (res == -1) { return; } } }
final byte[] readBuffer = new byte[23]; assertEquals(null, lko.buffer); ois.read(readBuffer); assertEquals(null, lko.buffer); ois.add(lko); for (;;) { if (bais.available() >= 2048) { final int result = ois.read(readBuffer); if (result == -1) { ois.close(); final int result = ois.read(readBuffer, 1, 11); if (result == -1) { ois.close();
/** Tests, that {@link Observer#data(int)} is called. */ @Test public void testDataByteCalled() throws Exception { final byte[] buffer = MessageDigestCalculatingInputStreamTest.generateRandomByteStream(4096); final ObservableInputStream ois = new ObservableInputStream(new ByteArrayInputStream(buffer)); final LastByteKeepingObserver lko = new LastByteKeepingObserver(); assertEquals(-1, lko.lastByteSeen); ois.read(); assertEquals(-1, lko.lastByteSeen); assertFalse(lko.finished); assertFalse(lko.closed); ois.add(lko); for (int i = 1; i < buffer.length; i++) { final int result = ois.read(); assertEquals((byte) result, buffer[i]); assertEquals(result, lko.lastByteSeen); assertFalse(lko.finished); assertFalse(lko.closed); } final int result = ois.read(); assertEquals(-1, result); assertTrue(lko.finished); assertFalse(lko.closed); ois.close(); assertTrue(lko.finished); assertTrue(lko.closed); }
/** Reads all data from the underlying {@link InputStream}, while notifying the * observers. * @throws IOException The underlying {@link InputStream}, or either of the * observers has thrown an exception. */ public void consume() throws IOException { final byte[] buffer = new byte[8192]; for (;;) { final int res = read(buffer); if (res == -1) { return; } } }