List of usage examples for io.netty.buffer Unpooled EMPTY_BUFFER
ByteBuf EMPTY_BUFFER
To view the source code for io.netty.buffer Unpooled EMPTY_BUFFER.
Click Source Link
From source file:io.hekate.network.netty.NettyMessageReadWritTest.java
License:Apache License
@Test(expected = UnsupportedOperationException.class) public void testReset() throws IOException { NettyMessage reader = new NettyMessage(Unpooled.EMPTY_BUFFER, fakeCodec); reader.reset();/*w ww . ja v a 2 s .c o m*/ }
From source file:io.jafka.http.HttpServerHandler.java
License:Apache License
@Override protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception { if (msg instanceof HttpRequest) { HttpRequest request = this.request = (HttpRequest) msg; if (HttpHeaders.is100ContinueExpected(request)) { send100Continue(ctx);//w w w .ja va2 s . c om } body = new ByteArrayOutputStream(64); args = new HashMap<String, String>(4); // if (request.getMethod() != HttpMethod.POST) { sendStatusMessage(ctx, HttpResponseStatus.METHOD_NOT_ALLOWED, "POST METHOD REQUIRED"); return; } HttpHeaders headers = request.headers(); String contentType = headers.get("Content-Type"); // ? text or octstream String key = headers.get("key"); key = key != null ? key : headers.get("request_key"); args.put("key", key); args.put("topic", headers.get("topic")); args.put("partition", headers.get("partition")); } if (msg instanceof HttpContent) { HttpContent httpContent = (HttpContent) msg; ByteBuf content = httpContent.content(); if (content.isReadable()) { //body.write(content.array()); content.readBytes(body, content.readableBytes()); //body.append(content.toString(CharsetUtil.UTF_8)); } if (msg instanceof LastHttpContent) { //process request if (server.handler != null) { server.handler.handle(args, body.toByteArray()); } if (!writeResponse(ctx)) { // If keep-alive is off, close the connection once the content is fully written. ctx.writeAndFlush(Unpooled.EMPTY_BUFFER).addListener(ChannelFutureListener.CLOSE); } body = null; args = null; } } }
From source file:io.jsync.http.impl.AsyncHttpHandler.java
License:Open Source License
@Override protected Object safeObject(Object msg, ByteBufAllocator allocator) throws Exception { if (msg instanceof HttpContent) { HttpContent content = (HttpContent) msg; ByteBuf buf = content.content(); if (buf != Unpooled.EMPTY_BUFFER && buf.isDirect()) { ByteBuf newBuf = safeBuffer(content, allocator); if (msg instanceof LastHttpContent) { LastHttpContent last = (LastHttpContent) msg; return new AssembledLastHttpContent(newBuf, last.trailingHeaders(), last.decoderResult()); } else { return new DefaultHttpContent(newBuf); }/*from w w w.j a va 2 s . co m*/ } } else if (msg instanceof WebSocketFrame) { ByteBuf payload = safeBuffer((WebSocketFrame) msg, allocator); boolean isFinal = ((WebSocketFrame) msg).isFinalFragment(); FrameType frameType; if (msg instanceof BinaryWebSocketFrame) { frameType = BINARY; } else if (msg instanceof CloseWebSocketFrame) { frameType = CLOSE; } else if (msg instanceof PingWebSocketFrame) { frameType = PING; } else if (msg instanceof PongWebSocketFrame) { frameType = PONG; } else if (msg instanceof TextWebSocketFrame) { frameType = TEXT; } else if (msg instanceof ContinuationWebSocketFrame) { frameType = CONTINUATION; } else { throw new IllegalStateException("Unsupported websocket msg " + msg); } return new DefaultWebSocketFrame(frameType, payload, isFinal); } return msg; }
From source file:io.jsync.http.impl.AsyncHttpHandler.java
License:Open Source License
@Override public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { if (msg instanceof WebSocketFrameInternal) { WebSocketFrameInternal frame = (WebSocketFrameInternal) msg; ByteBuf buf = frame.getBinaryData(); if (buf != Unpooled.EMPTY_BUFFER) { buf = safeBuffer(buf, ctx.alloc()); }//from w w w . j av a2 s . c o m switch (frame.type()) { case BINARY: msg = new BinaryWebSocketFrame(buf); break; case TEXT: msg = new TextWebSocketFrame(buf); break; case CLOSE: msg = new CloseWebSocketFrame(true, 0, buf); break; case CONTINUATION: msg = new ContinuationWebSocketFrame(buf); break; case PONG: msg = new PongWebSocketFrame(buf); break; case PING: msg = new PingWebSocketFrame(buf); break; default: throw new IllegalStateException("Unsupported websocket msg " + msg); } } ctx.write(msg, promise); }
From source file:io.jsync.http.impl.DefaultHttpClientRequest.java
License:Open Source License
@Override public void end() { check(); write(Unpooled.EMPTY_BUFFER, true); }
From source file:io.jsync.http.impl.DefaultHttpClientRequest.java
License:Open Source License
private synchronized void connected(ClientConnection conn) { conn.setCurrentRequest(this); this.conn = conn; // If anything was written or the request ended before we got the connection, then // we need to write it now if (pendingMaxSize != -1) { conn.doSetWriteQueueMaxSize(pendingMaxSize); }//w ww . j av a2s .c o m if (pendingChunks != null) { ByteBuf pending = pendingChunks; pendingChunks = null; if (completed) { // we also need to write the head so optimize this and write all out in once writeHeadWithContent(pending, true); conn.endRequest(); } else { writeHeadWithContent(pending, false); } } else { if (completed) { // we also need to write the head so optimize this and write all out in once writeHeadWithContent(Unpooled.EMPTY_BUFFER, true); conn.endRequest(); } else { if (writeHead) { writeHead(); } } } }
From source file:io.jsync.http.impl.DefaultHttpServerResponse.java
License:Open Source License
@Override public MultiMap trailers() { if (trailers == null) { if (trailing == null) { trailing = new DefaultLastHttpContent(Unpooled.EMPTY_BUFFER, false); }/*from ww w.j a va2 s . c o m*/ trailers = new HttpHeadersAdapter(trailing.trailingHeaders()); } return trailers; }
From source file:io.jsync.http.impl.DefaultHttpServerResponse.java
License:Open Source License
@Override public void end() { end0(Unpooled.EMPTY_BUFFER); }
From source file:io.jsync.http.impl.ws.DefaultWebSocketFrame.java
License:Open Source License
/** * Creates a new empty text frame. */ public DefaultWebSocketFrame() { this(null, Unpooled.EMPTY_BUFFER, true); }
From source file:io.jsync.http.impl.ws.DefaultWebSocketFrame.java
License:Open Source License
/** * Creates a new empty text frame. */ public DefaultWebSocketFrame(FrameType frameType) { this(frameType, Unpooled.EMPTY_BUFFER, true); }