@Test public void testCounting() throws Exception { final String text = "A piece of text"; final byte[] bytes = text.getBytes(); final ByteArrayInputStream bais = new ByteArrayInputStream(bytes); final CountingInputStream cis = new CountingInputStream(bais); final byte[] result = new byte[21]; final byte[] ba = new byte[5]; int found = cis.read(ba); System.arraycopy(ba, 0, result, 0, 5); assertEquals( found, cis.getCount() ); final int value = cis.read(); found++; result[5] = (byte)value; assertEquals( found, cis.getCount() ); found += cis.read(result, 6, 5); assertEquals( found, cis.getCount() ); found += cis.read(result, 11, 10); assertEquals( found, cis.getCount() ); final String textResult = new String(result).trim(); assertEquals(textResult, text); cis.close(); }
public int getCount() { final long result = getByteCount(); if (result > Integer.MAX_VALUE) { throw new ArithmeticException("The byte count " + result + " is too large to be converted to an int"); } return (int) result; }
CountingInputStream extends ProxyInputStream { public int getCount() { final long result = getByteCount(); if (result > Integer.MAX_VALUE) { throw new ArithmeticException("The byte count " + result + " is too large to be converted to an int"); } return (int) result; } }
CountingInputStream extends ProxyInputStream { public int getCount() { final long result = getByteCount(); if (result > Integer.MAX_VALUE) { throw new ArithmeticException("The byte count " + result + " is too large to be converted to an int"); } return (int) result; } CountingInputStream(final InputStream in); }
CountingInputStream extends ProxyInputStream { public int getCount() { final long result = getByteCount(); if (result > Integer.MAX_VALUE) { throw new ArithmeticException("The byte count " + result + " is too large to be converted to an int"); } return (int) result; } CountingInputStream(final InputStream in); @Override synchronized long skip(final long length); int getCount(); int resetCount(); synchronized long getByteCount(); synchronized long resetByteCount(); }
CountingInputStream extends ProxyInputStream { public int getCount() { final long result = getByteCount(); if (result > Integer.MAX_VALUE) { throw new ArithmeticException("The byte count " + result + " is too large to be converted to an int"); } return (int) result; } CountingInputStream(final InputStream in); @Override synchronized long skip(final long length); int getCount(); int resetCount(); synchronized long getByteCount(); synchronized long resetByteCount();  }