HexOutputStream extends OutputStream { @Override public void write(int b) throws IOException { out.write('0' + ((b >> 4) & 0x0F)); out.write('0' + ((b) & 0x0F)); }  @Override void write(int b);  }
@Test public void testWrite() throws IOException { final ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); final HexOutputStream hexOut = new HexOutputStream(byteOut); hexOut.write('A'); assertEquals('A', Integer.parseInt(new String(byteOut.toByteArray()), 16)); }