< prev index next >

src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/internal/frame/FramesDecoder.java

Print this page


   1 /*
   2  * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 264         byte[] bytes = new byte[n];
 265         int offset = 0;
 266         while (n > 0) {
 267             int length = Math.min(n, currentBuffer.remaining());
 268             currentBuffer.get(bytes, offset, length);
 269             offset += length;
 270             n -= length;
 271             nextBuffer();
 272         }
 273         return bytes;
 274 
 275     }
 276 
 277     private List<ByteBuffer> getBuffers(boolean isDataFrame, int bytecount) {
 278         List<ByteBuffer> res = new ArrayList<>();
 279         while (bytecount > 0) {
 280             int remaining = currentBuffer.remaining();
 281             int extract = Math.min(remaining, bytecount);
 282             ByteBuffer extractedBuf;
 283             if (isDataFrame) {
 284                 extractedBuf = Utils.slice(currentBuffer, extract);
 285                 slicedToDataFrame = true;
 286             } else {
 287                 // Header frames here
 288                 // HPACK decoding should performed under lock and immediately after frame decoding.
 289                 // in that case it is safe to release original buffer,
 290                 // because of sliced buffer has a very short life
 291                 extractedBuf = Utils.slice(currentBuffer, extract);
 292             }
 293             res.add(extractedBuf);
 294             bytecount -= extract;
 295             nextBuffer();
 296         }
 297         return res;
 298     }
 299 
 300     public void close(String msg) {
 301         closed = true;
 302         tailBuffers.clear();
 303         int bytes = tailSize;
 304         ByteBuffer b = currentBuffer;
 305         if (b != null) {
 306             bytes += b.remaining();
 307             b.position(b.limit());
 308         }
 309         tailSize = 0;
 310         currentBuffer = null;
 311         DEBUG_LOGGER.log(Level.DEBUG, "closed %s, ignoring %d bytes", msg, bytes);


   1 /*
   2  * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 264         byte[] bytes = new byte[n];
 265         int offset = 0;
 266         while (n > 0) {
 267             int length = Math.min(n, currentBuffer.remaining());
 268             currentBuffer.get(bytes, offset, length);
 269             offset += length;
 270             n -= length;
 271             nextBuffer();
 272         }
 273         return bytes;
 274 
 275     }
 276 
 277     private List<ByteBuffer> getBuffers(boolean isDataFrame, int bytecount) {
 278         List<ByteBuffer> res = new ArrayList<>();
 279         while (bytecount > 0) {
 280             int remaining = currentBuffer.remaining();
 281             int extract = Math.min(remaining, bytecount);
 282             ByteBuffer extractedBuf;
 283             if (isDataFrame) {
 284                 extractedBuf = Utils.sliceWithLimitedCapacity(currentBuffer, extract);
 285                 slicedToDataFrame = true;
 286             } else {
 287                 // Header frames here
 288                 // HPACK decoding should performed under lock and immediately after frame decoding.
 289                 // in that case it is safe to release original buffer,
 290                 // because of sliced buffer has a very short life
 291                 extractedBuf = Utils.sliceWithLimitedCapacity(currentBuffer, extract);
 292             }
 293             res.add(extractedBuf);
 294             bytecount -= extract;
 295             nextBuffer();
 296         }
 297         return res;
 298     }
 299 
 300     public void close(String msg) {
 301         closed = true;
 302         tailBuffers.clear();
 303         int bytes = tailSize;
 304         ByteBuffer b = currentBuffer;
 305         if (b != null) {
 306             bytes += b.remaining();
 307             b.position(b.limit());
 308         }
 309         tailSize = 0;
 310         currentBuffer = null;
 311         DEBUG_LOGGER.log(Level.DEBUG, "closed %s, ignoring %d bytes", msg, bytes);


< prev index next >