/** * Invokes the delegate's <code>read(byte[])</code> method. * @param b the buffer to read the bytes into * @return the number of bytes read or -1 if the end of stream or * the limit has been reached. * @throws IOException if an I/O error occurs */ @Override public int read(final byte[] b) throws IOException { return this.read(b, 0, b.length); }
@Test public void testReadSingle() throws Exception { BoundedInputStream bounded; final byte[] helloWorld = "Hello World".getBytes(); final byte[] hello = "Hello".getBytes(); // limit = length bounded = new BoundedInputStream(new ByteArrayInputStream(helloWorld), helloWorld.length); for (int i = 0; i < helloWorld.length; i++) { assertEquals("limit = length byte[" + i + "]", helloWorld[i], bounded.read()); } assertEquals("limit = length end", -1, bounded.read()); // limit > length bounded = new BoundedInputStream(new ByteArrayInputStream(helloWorld), helloWorld.length + 1); for (int i = 0; i < helloWorld.length; i++) { assertEquals("limit > length byte[" + i + "]", helloWorld[i], bounded.read()); } assertEquals("limit > length end", -1, bounded.read()); // limit < length bounded = new BoundedInputStream(new ByteArrayInputStream(helloWorld), hello.length); for (int i = 0; i < hello.length; i++) { assertEquals("limit < length byte[" + i + "]", hello[i], bounded.read()); } assertEquals("limit < length end", -1, bounded.read()); }
/** * Invokes the delegate's <code>read(byte[])</code> method. * @param b the buffer to read the bytes into * @return the number of bytes read or -1 if the end of stream or * the limit has been reached. * @throws IOException if an I/O error occurs */ @Override public int read(byte[] b) throws IOException { return this.read(b, 0, b.length); }
/** * Invokes the delegate's <code>read(byte[])</code> method. * @param b the buffer to read the bytes into * @return the number of bytes read or -1 if the end of stream or * the limit has been reached. * @throws IOException if an I/O error occurs */ @Override public int read(byte[] b) throws IOException { return this.read(b, 0, b.length); }
public int read(byte[] buf, int off, int len) throws IOException { return currentLogData.read(buf, off, len); }
/** * Invokes the delegate's <code>read(byte[])</code> method. * @param b the buffer to read the bytes into * @return the number of bytes read or -1 if the end of stream or * the limit has been reached. * @throws IOException if an I/O error occurs */ @Override public int read(final byte[] b) throws IOException { return this.read(b, 0, b.length); }
/** * Invokes the delegate's <code>read(byte[])</code> method. * @param b the buffer to read the bytes into * @return the number of bytes read or -1 if the end of stream or * the limit has been reached. * @throws IOException if an I/O error occurs */ @Override public int read(final byte[] b) throws IOException { return this.read(b, 0, b.length); }
public int read() throws IOException { return currentLogData.read(); }
public int read() throws IOException { return currentLogData.read(); }
public int read(byte[] buf, int off, int len) throws IOException { return currentLogData.read(buf, off, len); }
public int read() throws IOException { return currentLogData.read(); }
public int read(byte[] buf, int off, int len) throws IOException { return currentLogData.read(buf, off, len); }
public String nextLog() throws IOException { if (currentLogData != null && currentLogLength > 0) { // seek to the end of the current log, relying on BoundedInputStream // to prevent seeking past the end of the current log do { if (currentLogData.skip(currentLogLength) < 0) { break; } } while (currentLogData.read() != -1); } currentLogType = null; currentLogLength = 0; currentLogData = null; currentLogISR = null; try { String logType = valueStream.readUTF(); String logLengthStr = valueStream.readUTF(); currentLogLength = Long.parseLong(logLengthStr); currentLogData = new BoundedInputStream(valueStream, currentLogLength); currentLogData.setPropagateClose(false); currentLogISR = new InputStreamReader(currentLogData, Charset.forName("UTF-8")); currentLogType = logType; } catch (EOFException e) { } return currentLogType; }
public String nextLog() throws IOException { if (currentLogData != null && currentLogLength > 0) { // seek to the end of the current log, relying on BoundedInputStream // to prevent seeking past the end of the current log do { if (currentLogData.skip(currentLogLength) < 0) { break; } } while (currentLogData.read() != -1); } currentLogType = null; currentLogLength = 0; currentLogData = null; currentLogISR = null; try { String logType = valueStream.readUTF(); String logLengthStr = valueStream.readUTF(); currentLogLength = Long.parseLong(logLengthStr); currentLogData = new BoundedInputStream(valueStream, currentLogLength); currentLogData.setPropagateClose(false); currentLogISR = new InputStreamReader(currentLogData, Charset.forName("UTF-8")); currentLogType = logType; } catch (EOFException e) { } return currentLogType; }
public String nextLog() throws IOException { if (currentLogData != null && currentLogLength > 0) { // seek to the end of the current log, relying on BoundedInputStream // to prevent seeking past the end of the current log do { if (currentLogData.skip(currentLogLength) < 0) { break; } } while (currentLogData.read() != -1); } currentLogType = null; currentLogLength = 0; currentLogData = null; currentLogISR = null; try { String logType = valueStream.readUTF(); String logLengthStr = valueStream.readUTF(); currentLogLength = Long.parseLong(logLengthStr); currentLogData = new BoundedInputStream(valueStream, currentLogLength); currentLogData.setPropagateClose(false); currentLogISR = new InputStreamReader(currentLogData, Charset.forName("UTF-8")); currentLogType = logType; } catch (EOFException e) { } return currentLogType; }
while ((readBytes = boundedInputStream.read(buffer)) != -1)
while ((readBytes = boundedInputStream.read(buffer)) != -1)