Package org.glassfish.grizzly

Examples of org.glassfish.grizzly.Buffer


        final MemoryManager memoryManager = obtainMemoryManager(storage);

        final LZMAInputState state = (LZMAInputState) obtainStateObject(storage);
        state.setMemoryManager(memoryManager);

        Buffer decodedBuffer = null;
        Decoder.State decState = null;
        if (input.hasRemaining()) {
            decState = decodeBuffer(memoryManager, input, state);
            decodedBuffer = state.getDst();
        }

        final boolean hasRemainder = input.hasRemaining();

        if (decState == Decoder.State.NEED_MORE_DATA
                || decodedBuffer == null) {
            return TransformationResult.createIncompletedResult(hasRemainder ? input : null);
        }

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


        return decState;

    }

    private static void disposeDstBuffer(LZMAInputState state) {
        final Buffer dstBuffer = state.getDst();
        if (dstBuffer != null) {
            dstBuffer.dispose();
            state.setDst(null);
        }
    }
View Full Code Here

        }

        int src = bc.getStart();
        int end = bc.getEnd();
        int dest = src;
        Buffer buffer = bc.getBuffer();

        while (src < end) {
            if (buffer.get(src) == '\\' && src < end && buffer.get(src + 1) == '"') {
                src++;
            }
            buffer.put(dest, buffer.get(src));
            dest++;
            src++;
        }

        bc.setEnd(dest);
View Full Code Here


    @Override
    public NextAction handleRead(FilterChainContext ctx) throws IOException {
        final Connection connection = ctx.getConnection();
        final Buffer input = (Buffer) ctx.getMessage();
        final TransformationResult<Buffer, Buffer> result =
                decoder.transform(connection, input);

        final Buffer remainder = result.getExternalRemainder();

        if (remainder == null) {
            input.tryDispose();
        } else {
            input.shrink();
View Full Code Here

    }

    @Override
    public NextAction handleWrite(FilterChainContext ctx) throws IOException {
        final Connection connection = ctx.getConnection();
        final Buffer input = (Buffer) ctx.getMessage();
        final TransformationResult<Buffer, Buffer> result =
                encoder.transform(connection, input);

        if (!input.hasRemaining()) {
            input.tryDispose();
        } else {
            input.shrink();
        }

        try {
            switch (result.getStatus()) {
                case COMPLETE:
                    encoder.finish(connection);
                case INCOMPLETE: {
                    final Buffer readyBuffer = result.getMessage();
                    if (readyBuffer != null) {
                        ctx.setMessage(readyBuffer);
                        return ctx.getInvokeAction();
                    } else {
                        return ctx.getStopAction();
View Full Code Here

        } catch(UnsupportedEncodingException e) {
            throw new TransformationException("Charset " +
                    charset.name() + " is not supported", e);
        }

        final Buffer output =
                obtainMemoryManager(storage).allocate(byteRepresentation.length + 4);

        if (stringTerminator == null) {
            output.putInt(byteRepresentation.length);
        }

        output.put(byteRepresentation);

        output.flip();
        output.allowBufferDispose(true);

        return TransformationResult.createCompletedResult(output, null);
    }
View Full Code Here

    public Buffer asServerCookieBuffer(MemoryManager memoryManager) {
        if (memoryManager == null) memoryManager =
                MemoryManager.DEFAULT_MEMORY_MANAGER;
       
        final Buffer buffer = memoryManager.allocate(4096);
        CookieSerializerUtils.serializeServerCookie(buffer, this);
        buffer.trim();

        return buffer;
    }
View Full Code Here

    public Buffer asClientCookieBuffer(MemoryManager memoryManager) {
        if (memoryManager == null) memoryManager =
                MemoryManager.DEFAULT_MEMORY_MANAGER;

        final Buffer buffer = memoryManager.allocate(4096);
        CookieSerializerUtils.serializeClientCookies(buffer, this);
        buffer.trim();

        return buffer;
    }
View Full Code Here

     * @return {@link NextAction}
     * @throws IOException
     */
    @Override
    public NextAction handleRead(final FilterChainContext ctx) throws IOException {
        final Buffer input = ctx.getMessage();
        final Connection connection = ctx.getConnection();
        ServerHttpRequestImpl httpRequest = httpRequestInProcessAttr.get(connection);
       
        if (httpRequest == null) {
            final boolean isSecureLocal = isSecure(connection);
            httpRequest = ServerHttpRequestImpl.create();
            httpRequest.initialize(connection, this, input.position(), maxHeadersSize, maxRequestHeaders);
            httpRequest.setSecure(isSecureLocal);
            final HttpResponsePacket response = httpRequest.getResponse();
            response.setSecure(isSecureLocal);
            response.getHeaders().setMaxNumHeaders(maxResponseHeaders);
            httpRequest.setResponse(response);
View Full Code Here

        isDisposed = false;
        hasClonedArray = false;
    }

    Buffer cloneContent(final MemoryManager memoryManager) {
        final Buffer buffer;
       
        final int length = remaining();
       
        if (!hasClonedArray) {
            buffer = memoryManager.allocate(length);
            buffer.put(heap, offset + pos, length);
            buffer.flip();
        } else {
            buffer = Buffers.wrap(memoryManager, heap, offset + pos, length);
        }

        buffer.allowBufferDispose(true);
        dispose();
       
        return buffer;
    }
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.