private void sendHeaderBlockFrame(InterceptorChain chain, byte[] headerBlock, Http2Settings http2Settings,
                                      int streamId, boolean endStream) throws IOException  {
        int maxFrameSize = http2Settings == null ? Http2.INITIAL_MAX_FRAME_SIZE :
                http2Settings.getMaxFrameSize(Http2.INITIAL_MAX_FRAME_SIZE);
        int byteCount = headerBlock.length;
        int length = Math.min(maxFrameSize, byteCount);
        byte type = FrameType.HEADERS.get();
        byte flags = 0;
        if (byteCount == length) {
            flags |= Http2.FLAG_END_HEADERS;
            if (endStream) {
                flags |= Http2.FLAG_END_STREAM;
            }
        }
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        os.write(frameHeader(streamId, length, type, flags));
        os.write(headerBlock, 0, length);
        chain.process(ByteBuffer.wrap(os.toByteArray()));
        if (byteCount > length) {
            byte[] left = Arrays.copyOfRange(headerBlock, length, byteCount);
            sendContinuationFrame(chain, left, streamId, maxFrameSize, byteCount - length,
                    endStream);
        }
    }
Encodes HTTP2 request and response packets.

@author Megatron King
@since 2019/1/5 14:24
netbare-core/src/main/java/com/github/megatronking/netbare/http2/Http2EncodeInterceptor.java