### Question:
ByteCountingDataInput implements DataInput { @Override public String readUTF() throws IOException { String value = dataInput.readUTF(); count += 2; 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();  }### Answer:
@Test public void testReadUTF() throws Exception { ByteArrayOutputStream stream = new ByteArrayOutputStream(); DataOutput output = new DataOutputStream(stream); output.writeUTF(alphabet); ByteCountingDataInput bcdi = new ByteCountingDataInput(new DataInputStream(new ByteArrayInputStream(stream.toByteArray()))); String readAlphabet = bcdi.readUTF(); assertEquals("Incorrect byte count read for string", 28, bcdi.getCount()); long countBefore = bcdi.getCount(); try { bcdi.readUTF(); } catch (IOException expected) {} assertEquals(countBefore, bcdi.getCount()); }