private void sendDataFrame(InterceptorChain chain, byte[] data, 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 = data.length;
        byte type = FrameType.DATA.get();
        int offset = 0;
        while (byteCount > 0) {
            int length = Math.min(maxFrameSize, byteCount);
            byteCount -= length;
            ByteArrayOutputStream os = new ByteArrayOutputStream();
            byte flags = 0;
            if (byteCount == 0 && endStream) {
                mLog.i("Http2 stream end: " + streamId);
                flags |= Http2.FLAG_END_STREAM;
            }
            os.write(frameHeader(streamId, length, type, flags));
            os.write(data, offset, length);
            offset += length;
            chain.process(ByteBuffer.wrap(os.toByteArray()));
        }
    }
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