Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * JBoss, Home of Professional Open Source.
   * Copyright 2014 Red Hat, Inc., and individual contributors
   * as indicated by the @author tags.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
  *     http://www.apache.org/licenses/LICENSE-2.0
  *
  *  Unless required by applicable law or agreed to in writing, software
  *  distributed under the License is distributed on an "AS IS" BASIS,
  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
 
 package io.undertow.protocols.spdy;
 
 

Author(s):
Stuart Douglas
 
 
     private final HeaderMap headers;
     private boolean first = true;
     private final Deflater deflater;
 
     SpdySynStreamStreamSinkChannel(SpdyChannel channelHeaderMap headersint streamIdDeflater deflater) {
         super(channelstreamId);
         this. = headers;
         this. = deflater;
     }
 
     @Override
     protected SendFrameHeader createFrameHeaderImpl() {
 
         int fcWindow = grabFlowControlBytes(getBuffer().remaining());
         if (fcWindow == 0 && getBuffer().hasRemaining()) {
             return new SendFrameHeader(getBuffer().remaining(), null);
         }
         final boolean finalFrame = isWritesShutdown() && fcWindow >= getBuffer().remaining();
         Pooled<ByteBufferfirstHeaderBuffer = getChannel().getBufferPool().allocate();
         Pooled<ByteBuffer>[] allHeaderBuffers = null;
         ByteBuffer firstBuffer = firstHeaderBuffer.getResource();
         boolean firstFrame = false;
         if () {
             firstFrame = true;
              = false;
             int firstInt = . | (getChannel().getSpdyVersion() << 16) | 1;
             SpdyProtocolUtils.putInt(firstBufferfirstInt);
             SpdyProtocolUtils.putInt(firstBuffer, 0); //we back fill the length
             HeaderMap headers = this.;
 
             SpdyProtocolUtils.putInt(firstBuffergetStreamId());
             SpdyProtocolUtils.putInt(firstBuffer, 0);
             firstBuffer.put((byte) 0);
             firstBuffer.put((byte) 0);
 
 
             headers.remove(.); //todo: should this be here?
             headers.remove(.);
             headers.remove(.);
 
             allHeaderBuffers = createHeaderBlock(firstHeaderBufferallHeaderBuffersfirstBufferheaders);
         }
         Pooled<ByteBuffercurrentPooled = allHeaderBuffers == null ? firstHeaderBuffer : allHeaderBuffers[allHeaderBuffers.length - 1];
         ByteBuffer currentBuffer = currentPooled.getResource();
         int remainingInBuffer = 0;
         if (getBuffer().remaining() > 0) {
             remainingInBuffer = getBuffer().remaining() - fcWindow;
             getBuffer().limit(getBuffer().position() + fcWindow);
             if (currentBuffer.remaining() < 8) {
                 allHeaderBuffers = allocateAll(allHeaderBufferscurrentPooled);
                 currentPooled = allHeaderBuffers[allHeaderBuffers.length - 1];
                 currentBuffer = currentPooled.getResource();
             }
             SpdyProtocolUtils.putInt(currentBuffergetStreamId());
             SpdyProtocolUtils.putInt(currentBuffer, ((finalFrame ? . : 0) << 24) + fcWindow);
         } else if(finalFrame && !firstFrame) {
             SpdyProtocolUtils.putInt(currentBuffergetStreamId());
             SpdyProtocolUtils.putInt(currentBuffer.  << 24);
         }
         if (allHeaderBuffers == null) {
             //only one buffer required
             currentBuffer.flip();
             return new SendFrameHeader(remainingInBuffercurrentPooled);
         } else {
             //headers were too big to fit in one buffer
            //for now we will just copy them into a big buffer
            int length = 0;
            for (int i = 0; i < allHeaderBuffers.length; ++i) {
                length += allHeaderBuffers[i].getResource().position();
                allHeaderBuffers[i].getResource().flip();
            }
            try {
                ByteBuffer newBuf = ByteBuffer.allocate(length);
                for (int i = 0; i < allHeaderBuffers.length; ++i) {
                    newBuf.put(allHeaderBuffers[i].getResource());
                }
                newBuf.flip();
                return new SendFrameHeader(remainingInBuffernew ImmediatePooled<ByteBuffer>(newBuf));
            } finally {
                //the allocate can oome
                for (int i = 0; i < allHeaderBuffers.length; ++i) {
                    allHeaderBuffers[i].free();
                }
            }
        }
    }
    @Override
    protected Deflater getDeflater() {
        return ;
    }
New to GrepCode? Check out our FAQ X