Package org.glassfish.grizzly

Examples of org.glassfish.grizzly.Buffer


            throw new IllegalStateException(LogMessages.WARNING_GRIZZLY_HTTP_SERVER_REQUEST_POST_TOO_LARGE());
        }

        int read = 0;
        try {
            final Buffer formData = getPostBody(len);
            read = formData.remaining();
            parameters.processParameters(formData, formData.position(), read);
        } catch (Exception ignored) {
        } finally {
            try {
                skipPostBody(read);
            } catch (Exception e) {
View Full Code Here


                content = encodedHttpContent;
                wasContentAlreadyEncoded = true;
            }
        }

        final Buffer encoded = super.encodeHttpPacket(ctx, header, content,
                wasContentAlreadyEncoded);
        if (!isHeaderPacket) {
            input.recycle();
        }
        return encoded;
View Full Code Here

    /*
     * caller has the responsibility to set the status of th response.
     */
    private void commitAndCloseAsError(FilterChainContext ctx, HttpResponsePacket response) {
        final HttpContent errorHttpResponse = customizeErrorResponse(response);
        final Buffer resBuf = encodeHttpPacket(ctx, errorHttpResponse);
        ctx.write(resBuf);
        response.getProcessingState().getHttpContext().close();
    }
View Full Code Here

               
                final Pool newPool = getPoolFor(newSize);
                if (newPool != oldPoolBuffer.owner().owner) {
                    final int pos = Math.min(oldPoolBuffer.position(), newSize);

                    final Buffer newPoolBuffer = newPool.allocate();
                    Buffers.setPositionLimit(oldPoolBuffer, 0, newSize);
                    newPoolBuffer.put(oldPoolBuffer);
                    Buffers.setPositionLimit(newPoolBuffer, pos, newSize);

                    oldPoolBuffer.tryDispose();

                    return newPoolBuffer;
                }

                return oldPoolBuffer.limit(newSize);
            } else {
                final int pos = oldBuffer.position();
                Buffers.setPositionLimit(oldBuffer, 0, curBufSize);

                if (newSize <= maxPooledBufferSize) {

                    final Pool newPool = getPoolFor(newSize);

                    final Buffer newPoolBuffer = newPool.allocate();
                    newPoolBuffer.put(oldBuffer);
                    Buffers.setPositionLimit(newPoolBuffer, pos, newSize);
                   
                    oldBuffer.tryDispose();
                   
                    return newPoolBuffer;
View Full Code Here

     * @return {@link NextAction}
     * @throws IOException
     */
    @Override
    public NextAction handleRead(FilterChainContext ctx) throws IOException {
        Buffer input = ctx.getMessage();
        final Connection connection = ctx.getConnection();
        ClientHttpResponseImpl httpResponse = httpResponseInProcessAttr.get(connection);
        if (httpResponse == null) {
            httpResponse = ClientHttpResponseImpl.create();
            final Queue<HttpRequestPacket> requestQueue = getRequestQueue(connection);
            httpResponse.setRequest(requestQueue.poll());
            httpResponse.initialize(this, input.position(), maxHeadersSize, MimeHeaders.MAX_NUM_HEADERS_UNBOUNDED);
            httpResponse.setSecure(isSecure(connection));
            httpResponseInProcessAttr.set(connection, httpResponse);
        }
       
        final HttpRequestPacket request = httpResponse.getRequest();
View Full Code Here

            if (contentDecodingRemainders == null ||
                    i >= contentDecodingRemainders.length) {
                return null;
            }
           
            final Buffer remainder = contentDecodingRemainders[i];
            contentDecodingRemainders[i] = null;
            return remainder;
        }
View Full Code Here

        /**
         * Send next CHUNK_SIZE of file
         */
        private boolean sendChunk () throws IOException {
            // allocate Buffer
            Buffer buffer = null;
           
            if (!mm.willAllocateDirect(chunkSize)) {
                buffer = mm.allocate(chunkSize);
                final int len;
                if (!buffer.isComposite()) {
                    len = inputStream.read(buffer.array(),
                            buffer.position() + buffer.arrayOffset(),
                            chunkSize);
                } else {
                    final BufferArray bufferArray = buffer.toBufferArray();
                    final int size = bufferArray.size();
                    final Buffer[] buffers = bufferArray.getArray();

                    int lenCounter = 0;
                    for (int i = 0; i < size; i++) {
                        final Buffer subBuffer = buffers[i];
                        final int subBufferLen = subBuffer.remaining();
                        final int justReadLen = inputStream.read(subBuffer.array(),
                                subBuffer.position() + subBuffer.arrayOffset(),
                                subBufferLen);
                       
                        if (justReadLen > 0) {
                            lenCounter += justReadLen;
                        }
View Full Code Here

            if (!initializeInput(input, state)) {
                return TransformationResult.createIncompletedResult(input);
            }
        }

        Buffer decodedBuffer = null;

        if (state.getDecodeStatus() == DecodeStatus.PAYLOAD) {
            if (input.hasRemaining()) {
                decodedBuffer = decodeBuffer(memoryManager, input, state);
            }
        }

        if (state.getDecodeStatus() == DecodeStatus.TRAILER && input.hasRemaining()) {
            if (decodeTrailer(input, state)) {
                state.setDecodeStatus(DecodeStatus.DONE);
                state.setInitialized(false);
            }
        }

        final boolean hasRemainder = input.hasRemaining();

        if (decodedBuffer == null || !decodedBuffer.hasRemaining()) {
            return TransformationResult.createIncompletedResult(hasRemainder ? input : null);
        }

        return TransformationResult.createCompletedResult(decodedBuffer,
                hasRemainder ? input : null);
View Full Code Here

        final ByteBufferArray byteBufferArray = buffer.toByteBufferArray();
        final ByteBuffer[] byteBuffers = byteBufferArray.getArray();
        final int size = byteBufferArray.size();

        Buffer resultBuffer = null;

        for (int i = 0; i < size; i++) {
            final ByteBuffer byteBuffer = byteBuffers[i];
            final int len = byteBuffer.remaining();

            final byte[] array;
            final int offset;
            if (byteBuffer.hasArray()) {
                array = byteBuffer.array();
                offset = byteBuffer.arrayOffset() + byteBuffer.position();
            } else {
                // @TODO allocate byte array via MemoryUtils
                array = new byte[len];
                offset = 0;
                byteBuffer.get(array);
                byteBuffer.position(byteBuffer.position() - len);
            }

            inflater.setInput(array, offset, len);

            int lastInflated;
            do {
                final Buffer decodedBuffer = memoryManager.allocate(bufferSize);
                final ByteBuffer decodedBB = decodedBuffer.toByteBuffer();
                final byte[] decodedArray = decodedBB.array();
                final int decodedArrayOffs = decodedBB.arrayOffset() + decodedBB.position();

                try {
                    lastInflated = inflater.inflate(decodedArray, decodedArrayOffs, bufferSize);
                } catch (DataFormatException e) {
                    decodedBuffer.dispose();
                    String s = e.getMessage();
                    throw new IllegalStateException(s != null ? s : "Invalid ZLIB data format");
                }

                if (lastInflated > 0) {
                    inCrc32.update(decodedArray, decodedArrayOffs, lastInflated);
                    decodedBuffer.position(lastInflated);
                    decodedBuffer.trim();
                    resultBuffer = Buffers.appendBuffers(memoryManager,
                            resultBuffer, decodedBuffer);
                } else {
                    decodedBuffer.dispose();
                    if (inflater.finished() || inflater.needsDictionary()) {
                        final int remainder = inflater.getRemaining();

                        final int remaining = byteBuffer.remaining();
View Full Code Here

        final int bufferStart = bufferChunk.getStart();
        final int bufferLength = bufferChunk.getLength();
        allocate(bufferLength, -1);

        final Buffer buffer = bufferChunk.getBuffer();
       
        if (Charsets.UTF8_CHARSET.equals(encoding)) {
            try {
//                final char[] ccBuf = getChars();
//                final int ccStart = getStart();

                end = UTF8_DECODER.convert(buffer,
                        bufferStart, buff, end,
                        bufferLength);
//                cc.setEnd(ccEnd);
            } catch (IOException e) {
                if (!(e instanceof CharConversionException)) {
                    throw new CharConversionException();
                }

                throw (CharConversionException) e;
            }
//            uri.setChars(cc.getChars(), cc.getStart(), cc.getEnd());
            return;
        } else if (!DEFAULT_HTTP_CHARSET.equals(encoding)) {
            final ByteBuffer bb = buffer.toByteBuffer(
                    bufferStart, bufferStart + bufferLength);
//            final char[] ccBuf = cc.getChars();
//            final int ccStart = cc.getStart();
            final CharBuffer cb = CharBuffer.wrap(buff, start, buff.length - start);

            final CharsetDecoder decoder = Charsets.getCharsetDecoder(encoding);
            final CoderResult cr = decoder.decode(bb, cb, true);

            if (cr != CoderResult.UNDERFLOW) {
                throw new CharConversionException("Decoding error");
            }

            end = start + cb.position();
//            uri.setChars(cc.getChars(), cc.getStart(), cc.getEnd());

            return;
        }

        // Default encoding: fast conversion
        for (int i = 0; i < bufferLength; i++) {
            buff[i] = (char) (buffer.get(i + bufferStart) & 0xff);
        }
        end = bufferLength;
       
//        return cc;
//        uri.setChars(cbuf, 0, bc.getLength());
View Full Code Here

TOP

Related Classes of org.glassfish.grizzly.Buffer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.