@Test public void testMergeHeadersAndPayload() throws IOException { IPv4Packet referencePacket = new IPv4Packet(createMockPacket()); IPv4Header ipv4Header = referencePacket.getIpv4Header(); TransportHeader transportHeader = referencePacket.getTransportHeader(); byte[] data = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, (byte) 0x88}; ReadableByteChannel channel = Channels.newChannel(new ByteArrayInputStream(data)); Packetizer packetizer = new Packetizer(ipv4Header, transportHeader); IPv4Packet packet = packetizer.packetize(channel); Assert.assertEquals(36, packet.getIpv4Header().getTotalLength()); ByteBuffer packetPayload = packet.getPayload(); Assert.assertEquals(8, packetPayload.remaining()); Assert.assertEquals(0x1122334455667788L, packetPayload.getLong()); }
public IPv4Packet packetize(ReadableByteChannel channel, int maxChunkSize) throws IOException { payloadBuffer.limit(maxChunkSize).position(0); int payloadLength = channel.read(payloadBuffer); if (payloadLength == -1) { return null; } payloadBuffer.flip(); return inflate(); }
Packetizer { public IPv4Packet packetize(ReadableByteChannel channel, int maxChunkSize) throws IOException { payloadBuffer.limit(maxChunkSize).position(0); int payloadLength = channel.read(payloadBuffer); if (payloadLength == -1) { return null; } payloadBuffer.flip(); return inflate(); } }
Packetizer { public IPv4Packet packetize(ReadableByteChannel channel, int maxChunkSize) throws IOException { payloadBuffer.limit(maxChunkSize).position(0); int payloadLength = channel.read(payloadBuffer); if (payloadLength == -1) { return null; } payloadBuffer.flip(); return inflate(); } Packetizer(IPv4Header ipv4Header, TransportHeader transportHeader); }
Packetizer { public IPv4Packet packetize(ReadableByteChannel channel, int maxChunkSize) throws IOException { payloadBuffer.limit(maxChunkSize).position(0); int payloadLength = channel.read(payloadBuffer); if (payloadLength == -1) { return null; } payloadBuffer.flip(); return inflate(); } Packetizer(IPv4Header ipv4Header, TransportHeader transportHeader); IPv4Header getResponseIPv4Header(); TransportHeader getResponseTransportHeader(); IPv4Packet packetizeEmptyPayload(); IPv4Packet packetize(ReadableByteChannel channel, int maxChunkSize); IPv4Packet packetize(ReadableByteChannel channel); }
Packetizer { public IPv4Packet packetize(ReadableByteChannel channel, int maxChunkSize) throws IOException { payloadBuffer.limit(maxChunkSize).position(0); int payloadLength = channel.read(payloadBuffer); if (payloadLength == -1) { return null; } payloadBuffer.flip(); return inflate(); } Packetizer(IPv4Header ipv4Header, TransportHeader transportHeader); IPv4Header getResponseIPv4Header(); TransportHeader getResponseTransportHeader(); IPv4Packet packetizeEmptyPayload(); IPv4Packet packetize(ReadableByteChannel channel, int maxChunkSize); IPv4Packet packetize(ReadableByteChannel channel);  }