Update from review

reformat
Use ByteBuffer API

Signed-off-by: Greg Wilkins <gregw@webtide.com>
This commit is contained in:
Greg Wilkins 2019-09-12 21:39:36 +10:00
parent 905bf82f80
commit afa987ac64
2 changed files with 14 additions and 20 deletions

View File

@ -523,9 +523,6 @@ public class Huffman
long current = 0;
int n = 0;
byte[] array = buffer.array();
int p = buffer.arrayOffset() + buffer.position();
int len = b.length;
for (int i = 0; i < len; i++)
{
@ -540,7 +537,7 @@ public class Huffman
while (n >= 8)
{
n -= 8;
array[p++] = (byte)(current >> n);
buffer.put((byte)(current >> n));
}
}
@ -548,9 +545,7 @@ public class Huffman
{
current <<= (8 - n);
current |= (0xFF >>> n);
array[p++] = (byte)current;
buffer.put((byte)(current));
}
buffer.position(p - buffer.arrayOffset());
}
}

View File

@ -135,27 +135,26 @@ public class HpackTest
assertThat(e.getMessage(), containsString("Header too large"));
}
}
@Test
public void encodeDecodeNonAscii() throws Exception
{
HpackEncoder encoder = new HpackEncoder();
HpackDecoder decoder = new HpackDecoder(4096,8192);
ByteBuffer buffer = BufferUtil.allocate(16*1024);
HpackDecoder decoder = new HpackDecoder(4096, 8192);
ByteBuffer buffer = BufferUtil.allocate(16 * 1024);
HttpFields fields0 = new HttpFields();
fields0.add("Cookie","[\uD842\uDF9F]");
fields0.add("custom-key","[\uD842\uDF9F]");
Response original0 = new MetaData.Response(HttpVersion.HTTP_2,200,fields0);
fields0.add("Cookie", "[\uD842\uDF9F]");
fields0.add("custom-key", "[\uD842\uDF9F]");
Response original0 = new MetaData.Response(HttpVersion.HTTP_2, 200, fields0);
BufferUtil.clearToFill(buffer);
encoder.encode(buffer,original0);
BufferUtil.flipToFlush(buffer,0);
encoder.encode(buffer, original0);
BufferUtil.flipToFlush(buffer, 0);
Response decoded0 = (Response)decoder.decode(buffer);
assertMetadataSame(original0,decoded0);
assertMetadataSame(original0, decoded0);
}
@Test
public void evictReferencedFieldTest() throws Exception