public ArrayList < Frame > prepareHeaders ( byte [ ] marshalledHeaders , boolean complete ) { //Create the HeaderFrame //Passback the header frame if ( TraceComponent . isAnyTracingEnabled ( ) && tc . isDebugEnabled ( ) ) { Tr . debug ( tc , "prepareHeaders entry: stream: marked as complete: " + complete ) ; } int maxFrameSize = muxLink . getRemoteConnectionSettings ( ) . getMaxFrameSize ( ) ; ArrayList < Frame > frameList = new ArrayList < Frame > ( ) ; boolean endHeaders = true ; /** * If this stream's header block is larger than the maximum frame size, we need to break it up into a header frame * followed by continuation frames as necessary. */ if ( marshalledHeaders . length > maxFrameSize ) { int remaining = marshalledHeaders . length ; // how many bytes we still need to process in this header block int frameSize = maxFrameSize ; // the current frame size int position = 0 ; // our position in the original header block endHeaders = false ; // create the first header block fragment, of size maxFrameSize, put it in a header frame, // then add the bytes for that frame to a list byte [ ] firstFragment = Arrays . copyOfRange ( marshalledHeaders , position , frameSize ) ; FrameHeaders fh = new FrameHeaders ( streamID , firstFragment , complete , endHeaders ) ; frameList . add ( fh ) ; remaining = remaining - frameSize ; // continue creating continuation frames until we've completely copied the original header block while ( remaining > 0 ) { position = position + frameSize ; // figure out the frame size for this frame and set how many bytes remain if ( remaining >= maxFrameSize ) { frameSize = maxFrameSize ; } else { frameSize = remaining ; } remaining = remaining - frameSize ; // copy the data for the corresponding header block fragment byte [ ] fragment = Arrays . copyOfRange ( marshalledHeaders , position , position + frameSize ) ; // if this is the last continuation frame we need, set endHeaders to false for this frame endHeaders = remaining == 0 ? true : false ; FrameContinuation continued = new FrameContinuation ( streamID , fragment , endHeaders , false , false ) ; frameList . add ( continued ) ; // if this is the last continuation frame, we can go ahead and return the bytes for the entire collection of // necessary headers and continuation frames if ( endHeaders ) { if ( TraceComponent . isAnyTracingEnabled ( ) && tc . isDebugEnabled ( ) ) { Tr . debug ( tc , "prepareHeaders exit : " + frameList ) ; } return frameList ; } } } // if the current headers fit into the max frame size, then return a single header frame FrameHeaders fh = new FrameHeaders ( streamID , marshalledHeaders , complete , endHeaders ) ; frameList . add ( fh ) ; if ( TraceComponent . isAnyTracingEnabled ( ) && tc . isDebugEnabled ( ) ) { Tr . debug ( tc , "prepareHeaders exit : " + frameList ) ; } return frameList ; }
Create Header frames corresponding to a byte array of http headers