Hpai { public Hpai(InetSocketAddress address) { this.address = address; } Hpai(InetSocketAddress address);  Hpai(InputStream is); void write(OutputStream os); InetSocketAddress getAddress();  }
@Test public void testHpai() throws IOException { Hpai h1 = new Hpai(new InetSocketAddress(InetAddress.getByName("255.128.127.1"), 2555)); ByteArrayOutputStream os = new ByteArrayOutputStream(); h1.write(os); byte[] r = os.toByteArray(); Assert.assertArrayEquals(new byte[] { 0x08, 0x01, (byte) 255, (byte) 128, 127, 1, 0x09, (byte) 0xFB }, r); byte[] i = new byte[] { 0x08, 0x01, (byte) 255, (byte) 128, 127, 1, 0x09, (byte) 0xFB }; ByteArrayInputStream is = new ByteArrayInputStream(i); Hpai h2 = new Hpai(is); Assert.assertEquals(new InetSocketAddress(InetAddress.getByName("255.128.127.1"), 2555), h2.getAddress()); }