@Test public void testReadLine() throws IOException { ByteArrayOutputStream stream = new ByteArrayOutputStream(); DataOutput output = new DataOutputStream(stream); String expectedString = "A perfectly formed sentence"; String nextExpectedString = "With other nonsense on the end"; String theString = expectedString + "\r\n" + nextExpectedString + "\n"; output.write(theString.getBytes()); ByteCountingDataInput bcdi = new ByteCountingDataInput(new DataInputStream(new ByteArrayInputStream(stream.toByteArray()))); assertEquals(expectedString, bcdi.readLine()); long count= bcdi.getCount(); assertEquals("Incorrect byte count returned", expectedString.getBytes().length, count); assertEquals(nextExpectedString, bcdi.readLine()); assertEquals("Incorrect byte count returned", nextExpectedString.getBytes().length, bcdi.getCount() - count); }
@Override @Deprecated public String readLine() throws IOException { String value = dataInput.readLine(); if (value != null) { count += value.getBytes().length; } return value; }
ByteCountingDataInput implements DataInput { @Override @Deprecated public String readLine() throws IOException { String value = dataInput.readLine(); if (value != null) { count += value.getBytes().length; } return value; } }
ByteCountingDataInput implements DataInput { @Override @Deprecated public String readLine() throws IOException { String value = dataInput.readLine(); if (value != null) { count += value.getBytes().length; } return value; } ByteCountingDataInput(DataInput dataInput); }
ByteCountingDataInput implements DataInput { @Override @Deprecated public String readLine() throws IOException { String value = dataInput.readLine(); if (value != null) { count += value.getBytes().length; } return value; } ByteCountingDataInput(DataInput dataInput); @Override void readFully(byte[] b); @Override void readFully(byte[] b, int off, int len); @Override int skipBytes(int n); @Override boolean readBoolean(); @Override byte readByte(); @Override int readUnsignedByte(); @Override short readShort(); @Override int readUnsignedShort(); @Override char readChar(); @Override int readInt(); @Override long readLong(); @Override float readFloat(); @Override double readDouble(); @Override @Deprecated String readLine(); @Override String readUTF(); long getCount(); }
ByteCountingDataInput implements DataInput { @Override @Deprecated public String readLine() throws IOException { String value = dataInput.readLine(); if (value != null) { count += value.getBytes().length; } return value; } ByteCountingDataInput(DataInput dataInput); @Override void readFully(byte[] b); @Override void readFully(byte[] b, int off, int len); @Override int skipBytes(int n); @Override boolean readBoolean(); @Override byte readByte(); @Override int readUnsignedByte(); @Override short readShort(); @Override int readUnsignedShort(); @Override char readChar(); @Override int readInt(); @Override long readLong(); @Override float readFloat(); @Override double readDouble(); @Override @Deprecated String readLine(); @Override String readUTF(); long getCount();  }