DefaultHttp2HeadersEncoder implements Http2HeadersEncoder, Http2HeadersEncoder.Configuration { @Override public void encodeHeaders(Http2Headers headers, ByteBuf buffer) throws Http2Exception { final OutputStream stream = new ByteBufOutputStream(buffer); try { if (headers.size() > headerTable.maxHeaderListSize()) { throw connectionError(PROTOCOL_ERROR, "Number of headers (%d) exceeds maxHeaderListSize (%d)", headers.size(), headerTable.maxHeaderListSize()); } if (tableSizeChangeOutput.size() > 0) { buffer.writeBytes(tableSizeChangeOutput.toByteArray()); tableSizeChangeOutput.reset(); } for (Entry<CharSequence, CharSequence> header : headers) { encodeHeader(header.getKey(), header.getValue(), stream); } } catch (Http2Exception e) { throw e; } catch (Throwable t) { throw connectionError(COMPRESSION_ERROR, t, "Failed encoding headers block: %s", t.getMessage()); } finally { try { stream.close(); } catch (IOException e) { throw connectionError(INTERNAL_ERROR, e, e.getMessage()); } } } DefaultHttp2HeadersEncoder();  DefaultHttp2HeadersEncoder(int maxHeaderTableSize, SensitivityDetector sensitivityDetector); @Override void encodeHeaders(Http2Headers headers, ByteBuf buffer); @Override Http2HeaderTable headerTable(); @Override Configuration configuration();  }
@Test public void encodeShouldSucceed() throws Http2Exception { Http2Headers headers = headers(); ByteBuf buf = Unpooled.buffer(); try { encoder.encodeHeaders(headers, buf); assertTrue(buf.writerIndex() > 0); } finally { buf.release(); } }