test_class.file: cache-client/src/test/java/net/runelite/protocol/update/encoders/ArchiveResponseEncoderTest.java
test_class.identifier: ArchiveResponseEncoderTest
test_case.body: @Test
  	public void testEncode() throws Exception
  	{
  		byte[] data = new byte[1000];
  		Random random = new Random(42L);
  		random.nextBytes(data);
  
  		Container container = new Container(CompressionType.NONE, -1);
  		container.compress(data, null);
  		byte[] compressedData = container.data;
  
  		ArchiveResponsePacket archiveResponse = new ArchiveResponsePacket();
  		archiveResponse.setIndex(0);
  		archiveResponse.setArchive(1);
  		archiveResponse.setData(compressedData);
  
  		ByteBuf buf = Unpooled.buffer(1024);
  		ArchiveResponseEncoder encoder = new ArchiveResponseEncoder();
  		encoder.encode(null, archiveResponse, buf);
  
  		ArchiveResponseDecoder decoder = new ArchiveResponseDecoder();
  		List<Object> out = new ArrayList<>();
  		decoder.decode(null, buf, out);
  
  		Assert.assertEquals(1, out.size());
  		ArchiveResponsePacket response = (ArchiveResponsePacket) out.get(0);
  
  		Assert.assertEquals(archiveResponse.getIndex(), response.getIndex());
  		Assert.assertEquals(archiveResponse.getArchive(), response.getArchive());
  		Assert.assertArrayEquals(archiveResponse.getData(), response.getData());
  
  		byte[] decompressedData = Container.decompress(response.getData(), null).data;
  		Assert.assertArrayEquals(data, decompressedData);
  	}
test_case.class_method_signature: ArchiveResponseEncoderTest.testEncode()
test_case.full_signature: @Test public void testEncode()
test_case.identifier: testEncode
test_case.invocations: nextBytes compress setIndex setArchive setData buffer encode decode assertEquals size get assertEquals getIndex getIndex assertEquals getArchive getArchive assertArrayEquals getData getData decompress getData assertArrayEquals
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testEncode()
focal_class.declarator: logger = LoggerFactory.getLogger(ArchiveResponseEncoder.class)
focal_class.modifier: private static final
focal_class.original_string: private static final Logger logger = LoggerFactory.getLogger(ArchiveResponseEncoder.class);
focal_class.type: Logger
focal_class.var_name: logger
focal_class.declarator: CHUNK_SIZE = 512
focal_class.modifier: private static final
focal_class.original_string: private static final int CHUNK_SIZE = 512;
focal_class.type: int
focal_class.var_name: CHUNK_SIZE
focal_class.file: cache-client/src/main/java/net/runelite/protocol/update/encoders/ArchiveResponseEncoder.java
focal_class.identifier: ArchiveResponseEncoder
focal_class.class_method_signature: ArchiveResponseEncoder.encode(ChannelHandlerContext ctx, ArchiveResponsePacket archiveResponse, ByteBuf out)
focal_class.full_signature: @Override protected void encode(ChannelHandlerContext ctx, ArchiveResponsePacket archiveResponse, ByteBuf out)
focal_class.identifier: encode
focal_class.modifiers: @Override protected
focal_class.parameters: (ChannelHandlerContext ctx, ArchiveResponsePacket archiveResponse, ByteBuf out)
focal_class.return: void
focal_class.signature: void encode(ChannelHandlerContext ctx, ArchiveResponsePacket archiveResponse, ByteBuf out)
focal_class.class_method_signature: ArchiveResponseEncoder.writeChunk(ByteBuf chunk, ByteBuf out)
focal_class.full_signature: private void writeChunk(ByteBuf chunk, ByteBuf out)
focal_class.identifier: writeChunk
focal_class.modifiers: private
focal_class.parameters: (ByteBuf chunk, ByteBuf out)
focal_class.return: void
focal_class.signature: void writeChunk(ByteBuf chunk, ByteBuf out)
focal_class.superclass: extends MessageToByteEncoder<ArchiveResponsePacket>
focal_method.body: @Override
  	protected void encode(ChannelHandlerContext ctx, ArchiveResponsePacket archiveResponse, ByteBuf out) throws Exception
  	{
  		// archive file header
  		// 1 byte index
  		// 2 byte archive
  		out.writeByte(archiveResponse.getIndex());
  		out.writeShort(archiveResponse.getArchive());
  
  		int pos = out.readableBytes();
  
  		// next is the compressed data which starts with compression
  		// type and length
  		ByteBuf file = Unpooled.wrappedBuffer(archiveResponse.getData());
  		// - 3 for the header
  		int chunkSize = Math.min(file.readableBytes(), CHUNK_SIZE - 3);
  
  		writeChunk(file.readBytes(chunkSize), out);
  
  		while (file.isReadable())
  		{
  			out.writeByte(0xff);
  
  			chunkSize = Math.min(file.readableBytes(), CHUNK_SIZE - 1);
  			writeChunk(file.readBytes(chunkSize), out);
  		}
  
  		int size = out.readableBytes() - pos;
  		logger.debug("Wrote index {} archive {} (size {}) in {} bytes",
  			archiveResponse.getIndex(), archiveResponse.getArchive(),
  			archiveResponse.getData().length, size);
  	}
focal_method.class_method_signature: ArchiveResponseEncoder.encode(ChannelHandlerContext ctx, ArchiveResponsePacket archiveResponse, ByteBuf out)
focal_method.full_signature: @Override protected void encode(ChannelHandlerContext ctx, ArchiveResponsePacket archiveResponse, ByteBuf out)
focal_method.identifier: encode
focal_method.invocations: writeByte getIndex writeShort getArchive readableBytes wrappedBuffer getData min readableBytes writeChunk readBytes isReadable writeByte min readableBytes writeChunk readBytes readableBytes debug getIndex getArchive getData
focal_method.modifiers: @Override protected
focal_method.parameters: (ChannelHandlerContext ctx, ArchiveResponsePacket archiveResponse, ByteBuf out)
focal_method.return: void
focal_method.signature: void encode(ChannelHandlerContext ctx, ArchiveResponsePacket archiveResponse, ByteBuf out)