@Test public void testCopyTo() { ByteBuffer buffer = createMockHeaders(); UDPHeader header = new UDPHeader(buffer); ByteBuffer target = ByteBuffer.allocate(32); target.position(12); UDPHeader copy = header.copyTo(target); copy.setSourcePort(9999); Assert.assertEquals(20, target.position()); Assert.assertEquals("Header must modify target", 9999, target.getShort(12)); Assert.assertEquals("Header must not modify buffer", 1234, buffer.getShort(0)); }
@Override public UDPHeader copyTo(ByteBuffer target) { raw.rewind(); ByteBuffer slice = Binary.slice(target, target.position(), getHeaderLength()); target.put(raw); return new UDPHeader(slice); }
UDPHeader implements TransportHeader { @Override public UDPHeader copyTo(ByteBuffer target) { raw.rewind(); ByteBuffer slice = Binary.slice(target, target.position(), getHeaderLength()); target.put(raw); return new UDPHeader(slice); } }
UDPHeader implements TransportHeader { @Override public UDPHeader copyTo(ByteBuffer target) { raw.rewind(); ByteBuffer slice = Binary.slice(target, target.position(), getHeaderLength()); target.put(raw); return new UDPHeader(slice); } UDPHeader(ByteBuffer raw); }
UDPHeader implements TransportHeader { @Override public UDPHeader copyTo(ByteBuffer target) { raw.rewind(); ByteBuffer slice = Binary.slice(target, target.position(), getHeaderLength()); target.put(raw); return new UDPHeader(slice); } UDPHeader(ByteBuffer raw); @Override int getSourcePort(); @Override int getDestinationPort(); @Override void setSourcePort(int sourcePort); @Override void setDestinationPort(int destinationPort); @Override int getHeaderLength(); @Override void setPayloadLength(int payloadLength); @Override ByteBuffer getRaw(); @Override UDPHeader copyTo(ByteBuffer target); @Override void computeChecksum(IPv4Header ipv4Header, ByteBuffer payload); }
UDPHeader implements TransportHeader { @Override public UDPHeader copyTo(ByteBuffer target) { raw.rewind(); ByteBuffer slice = Binary.slice(target, target.position(), getHeaderLength()); target.put(raw); return new UDPHeader(slice); } UDPHeader(ByteBuffer raw); @Override int getSourcePort(); @Override int getDestinationPort(); @Override void setSourcePort(int sourcePort); @Override void setDestinationPort(int destinationPort); @Override int getHeaderLength(); @Override void setPayloadLength(int payloadLength); @Override ByteBuffer getRaw(); @Override UDPHeader copyTo(ByteBuffer target); @Override void computeChecksum(IPv4Header ipv4Header, ByteBuffer payload);  }