Package io.netty.buffer

Examples of io.netty.buffer.ByteBuf.release()


                break;
            }
            final String escaped = escapeCharacters(jsonEndocder.quoteAsString(element));
            final ByteBuf escapedBuf = Unpooled.copiedBuffer(escaped, CharsetUtil.UTF_8);
            content.writeBytes(escapedBuf).writeByte('"');
            escapedBuf.release();
            if (i < size - 1) {
                content.writeByte(',');
            }
        }
        return content.writeByte(']');
View Full Code Here


    private ByteBuf wrapWithFunction(final ByteBuf data, final ChannelHandlerContext ctx) {
        final ByteBuf content = ctx.alloc().buffer();
        Transports.escapeJson(data, content);
        final String function = callback + "(\"" + content.toString(UTF_8) + "\");\r\n";
        content.release();
        return Unpooled.copiedBuffer(function, UTF_8);
    }

    private static void respond(final ChannelHandlerContext ctx,
                                final HttpVersion httpVersion,
View Full Code Here

    public static void writeContent(final FullHttpResponse response, final String content, final String contentType) {
        final ByteBuf buf = copiedBuffer(content, CharsetUtil.UTF_8);
        response.headers().set(CONTENT_LENGTH, buf.readableBytes());
        response.content().writeBytes(buf);
        response.headers().set(CONTENT_TYPE, contentType);
        buf.release();
    }

    /**
     * Sets the following Http response headers
     * - SET_COOKIE  if {@link org.jboss.aerogear.io.netty.handler.codec.sockjs.SockJsConfig#areCookiesNeeded()} is true
View Full Code Here

                final HttpResponse response = createResponse(Transports.CONTENT_TYPE_HTML);
                final ByteBuf header = ctx.alloc().buffer();
                header.writeBytes(HEADER_PART1.duplicate());
                final ByteBuf content = copiedBuffer(callback, UTF_8);
                header.writeBytes(content);
                content.release();
                header.writeBytes(HEADER_PART2.duplicate());
                final int spaces = 1024 * header.readableBytes();
                final ByteBuf paddedBuffer = ctx.alloc().buffer(1024 + 50);
                paddedBuffer.writeBytes(header);
                header.release();
View Full Code Here

                        // keep on reading as we use epoll ET and need to consume everything from the socket
                        pipeline.fireChannelReadComplete();
                        pipeline.fireExceptionCaught(t);
                    } finally {
                        if (data != null) {
                            data.release();
                        }
                    }
                }
            } finally {
                // Check if there is a readPending which was not processed yet.
View Full Code Here

                    ByteBuf buf = decoder.readInbound();
                    if (buf == null) {
                        break;
                    }
                    // Release the buffer
                    buf.release();
                }
            }
            decoder = null;
        }
    }
View Full Code Here

            ByteBuf buf = decoder.readInbound();
            if (buf == null) {
                break;
            }
            if (!buf.isReadable()) {
                buf.release();
                continue;
            }
            out.add(new DefaultHttpContent(buf));
        }
    }
View Full Code Here

    private static FullHttpRequest request(final String body, HttpVersion httpVersion) {
        final DefaultFullHttpRequest r = new DefaultFullHttpRequest(httpVersion, HttpMethod.GET, "/test");
        if (body != null) {
            final ByteBuf buf = Unpooled.copiedBuffer(body, CharsetUtil.UTF_8);
            r.content().writeBytes(buf);
            buf.release();
        }
        return r;
    }

}
View Full Code Here

    private static FullHttpRequest wsUpgradeRequestWithBody() {
        final FullHttpRequest request = wsUpgradeRequest();
        final ByteBuf body = Unpooled.copiedBuffer("^n:ds[4U", CharsetUtil.US_ASCII);
        request.content().writeBytes(body);
        body.release();
        return request;
    }

}
View Full Code Here

    private static FullHttpRequest requestWithBody(final String body, HttpVersion httpVersion) {
        final DefaultFullHttpRequest r = new DefaultFullHttpRequest(httpVersion, HttpMethod.GET, "/test");
        if (body != null) {
            final ByteBuf content = Unpooled.copiedBuffer(body, CharsetUtil.UTF_8);
            r.content().writeBytes(content);
            content.release();
        }
        return r;
    }

    private static FullHttpRequest requestWithFormData(final String data) {
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.