List of usage examples for io.netty.buffer Unpooled wrappedBuffer
public static ByteBuf wrappedBuffer(ByteBuffer... buffers)
From source file:com.imaginarycode.minecraft.bungeejson.impl.httpserver.HttpServerHandler.java
License:Open Source License
private HttpResponse getResponse(ChannelHandlerContext channelHandlerContext, HttpRequest hr) { QueryStringDecoder query = new QueryStringDecoder(hr.getUri()); Multimap<String, String> params = createMultimapFromMap(query.parameters()); Object reply;//from w ww. ja va 2 s . com HttpResponseStatus hrs; final RequestHandler handler = BungeeJSONPlugin.getRequestManager().getHandlerForEndpoint(query.path()); if (handler == null) { reply = BungeeJSONUtilities.error("No such endpoint exists."); hrs = HttpResponseStatus.NOT_FOUND; } else { final ApiRequest ar = new HttpServerApiRequest( ((InetSocketAddress) channelHandlerContext.channel().remoteAddress()).getAddress(), params, bodyBuilder.toString()); try { reply = handler.handle(ar); hrs = HttpResponseStatus.OK; } catch (Throwable throwable) { hrs = HttpResponseStatus.INTERNAL_SERVER_ERROR; reply = BungeeJSONUtilities .error("An internal error has occurred. Information has been logged to the console."); BungeeJSONPlugin.getPlugin().getLogger().log(Level.WARNING, "Error while handling " + hr.getUri() + " from " + ar.getRemoteIp(), throwable); } } String json = BungeeJSONPlugin.getPlugin().getGson().toJson(reply); DefaultFullHttpResponse hreply = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, hrs, Unpooled.wrappedBuffer(json.getBytes(CharsetUtil.UTF_8))); // Add a reminder that we're still running the show. hreply.headers().set("Content-Type", "application/json; charset=UTF-8"); hreply.headers().set("Access-Control-Allow-Origin", "*"); hreply.headers().set("Server", "BungeeJSON/0.1"); hreply.headers().set("Content-Length", json.length()); return hreply; }
From source file:com.intuit.karate.netty.WebSocketClient.java
License:Open Source License
public void ping() { WebSocketFrame frame = new PingWebSocketFrame(Unpooled.wrappedBuffer(new byte[] { 8, 1, 8, 1 })); channel.writeAndFlush(frame);/*from w w w . j a va 2 s . c o m*/ }
From source file:com.king.platform.net.http.netty.sse.ServerEventDecoderTest.java
License:Apache License
private ByteBuf buffer(String s) throws UnsupportedEncodingException { return Unpooled.wrappedBuffer(s.getBytes("UTF-8")); }
From source file:com.lambdaworks.redis.codec.StringCodec.java
License:Apache License
@Override public String decodeKey(ByteBuffer bytes) { return Unpooled.wrappedBuffer(bytes).toString(charset); }
From source file:com.lambdaworks.redis.codec.StringCodec.java
License:Apache License
@Override public String decodeValue(ByteBuffer bytes) { return Unpooled.wrappedBuffer(bytes).toString(charset); }
From source file:com.lambdaworks.redis.codec.StringCodec.java
License:Apache License
/** * Compatibility implementation.//from w ww. j a va 2s. co m * * @param key * @return */ private ByteBuffer encodeAndAllocateBuffer(String key) { if (key == null) { return ByteBuffer.wrap(EMPTY); } CharsetEncoder encoder = CharsetUtil.encoder(charset); ByteBuffer buffer = ByteBuffer.allocate((int) (encoder.maxBytesPerChar() * key.length())); ByteBuf byteBuf = Unpooled.wrappedBuffer(buffer); byteBuf.clear(); encode(key, byteBuf); buffer.limit(byteBuf.writerIndex()); return buffer; }
From source file:com.lambdaworks.redis.pubsub.PubSubCommandHandlerTest.java
License:Apache License
@Test public void shouldCompleteCommandExceptionallyOnOutputFailure() throws Exception { sut.channelRegistered(context);/*w w w. j a v a 2s.co m*/ sut.channelActive(context); sut.write(command); sut.channelRead(context, Unpooled.wrappedBuffer(":1000\r\n".getBytes())); assertThat(ReflectionTestUtils.getField(command, "exception")).isInstanceOf(IllegalStateException.class); }
From source file:com.linecorp.armeria.client.endpoint.dns.DnsAddressEndpointGroupTest.java
License:Apache License
private static DnsRecord newAddressRecord(String name, String ipAddr) { return new DefaultDnsRawRecord(name, NetUtil.isValidIpV4Address(ipAddr) ? A : AAAA, 60, Unpooled.wrappedBuffer(NetUtil.createByteArrayFromIpAddressString(ipAddr))); }
From source file:com.linecorp.armeria.client.endpoint.dns.DnsServiceEndpointGroupTest.java
License:Apache License
private static DnsRecord newTooShortSrvRecord(String hostname) { return new DefaultDnsRawRecord(hostname, SRV, 60, Unpooled.wrappedBuffer(new byte[4])); }
From source file:com.linecorp.armeria.client.endpoint.dns.DnsServiceEndpointGroupTest.java
License:Apache License
private static DnsRecord newBadNameSrvRecord(String hostname) { return new DefaultDnsRawRecord(hostname, SRV, 60, Unpooled.wrappedBuffer(new byte[] { 0, 0, 0, 0, 0, 0, 127, 127, 127 })); }