diff --git a/jetty-http2/http2-hpack/src/main/java/org/eclipse/jetty/http2/hpack/Huffman.java b/jetty-http2/http2-hpack/src/main/java/org/eclipse/jetty/http2/hpack/Huffman.java index 85cc3a9ebc6..9edd8a0fd7f 100644 --- a/jetty-http2/http2-hpack/src/main/java/org/eclipse/jetty/http2/hpack/Huffman.java +++ b/jetty-http2/http2-hpack/src/main/java/org/eclipse/jetty/http2/hpack/Huffman.java @@ -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()); } } diff --git a/jetty-http2/http2-hpack/src/test/java/org/eclipse/jetty/http2/hpack/HpackTest.java b/jetty-http2/http2-hpack/src/test/java/org/eclipse/jetty/http2/hpack/HpackTest.java index c2a2306fee5..b45ee3b49e5 100644 --- a/jetty-http2/http2-hpack/src/test/java/org/eclipse/jetty/http2/hpack/HpackTest.java +++ b/jetty-http2/http2-hpack/src/test/java/org/eclipse/jetty/http2/hpack/HpackTest.java @@ -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