List of usage examples for io.netty.buffer Unpooled wrappedBuffer
public static ByteBuf wrappedBuffer(ByteBuffer... buffers)
From source file:com.butor.netty.handler.codec.ftp.FtpServerHandler.java
License:Apache License
private static void send(String response, ChannelHandlerContext ctx) { if (logger.isDebugEnabled()) { logger.debug("<- " + response); }/* w w w .j a v a 2s . c om*/ String line = response + "\r\n"; byte[] data = line.getBytes(ASCII); ctx.channel().writeAndFlush(Unpooled.wrappedBuffer(data)); }
From source file:com.caricah.iotracah.server.mqttserver.transform.IOTMqttTransformerImpl.java
License:Apache License
@Override public MqttMessage toServerMessage(IOTMessage internalMessage) { switch (internalMessage.getMessageType()) { case PublishMessage.MESSAGE_TYPE: PublishMessage pubMsg = (PublishMessage) internalMessage; //We generate a publish message. MqttPublishVariableHeader respVariableHeader = new MqttPublishVariableHeader(pubMsg.getTopic(), pubMsg.getMessageId());/* w ww.j ava2 s . c om*/ MqttFixedHeader respFixedHeader = new MqttFixedHeader(MqttMessageType.PUBLISH, pubMsg.getIsDuplicate(), MqttQoS.valueOf(pubMsg.getQos()), pubMsg.getIsRetain(), 0); ByteBuf content = Unpooled.wrappedBuffer((byte[]) pubMsg.getPayload()); return MqttMessageFactory.newMessage(respFixedHeader, respVariableHeader, content); case AcknowledgeMessage.MESSAGE_TYPE: //Generate a PUBACK for qos 1 messages. AcknowledgeMessage ackMsg = (AcknowledgeMessage) internalMessage; MqttFixedHeader ackFixedHeader = new MqttFixedHeader(MqttMessageType.PUBACK, ackMsg.isDup(), MqttQoS.valueOf(ackMsg.getQos()), ackMsg.isRetain(), 0); MqttMessageIdVariableHeader msgIdVariableHeader = MqttMessageIdVariableHeader .from(ackMsg.getMessageId()); return MqttMessageFactory.newMessage(ackFixedHeader, msgIdVariableHeader, null); case PublishReceivedMessage.MESSAGE_TYPE: //We need to generate a PUBREC message to acknowledge reception of message. PublishReceivedMessage pubrec = (PublishReceivedMessage) internalMessage; MqttFixedHeader recFixedHeader = new MqttFixedHeader(MqttMessageType.PUBREC, false, MqttQoS.valueOf(pubrec.getQos()), false, 0); msgIdVariableHeader = MqttMessageIdVariableHeader.from(pubrec.getMessageId()); return MqttMessageFactory.newMessage(recFixedHeader, msgIdVariableHeader, null); case ReleaseMessage.MESSAGE_TYPE: //We need to generate a PUBREL message to release cached message. ReleaseMessage pubrel = (ReleaseMessage) internalMessage; MqttFixedHeader relFixedHeader = new MqttFixedHeader(MqttMessageType.PUBREL, pubrel.isDup(), MqttQoS.valueOf(pubrel.getQos()), false, 0); msgIdVariableHeader = MqttMessageIdVariableHeader.from(pubrel.getMessageId()); return MqttMessageFactory.newMessage(relFixedHeader, msgIdVariableHeader, null); case CompleteMessage.MESSAGE_TYPE: //We need to generate a PUBCOMP message to acknowledge finalization of transmission of qos 2 message. CompleteMessage destroyMessage = (CompleteMessage) internalMessage; MqttFixedHeader compFixedHeader = new MqttFixedHeader(MqttMessageType.PUBCOMP, false, MqttQoS.valueOf(destroyMessage.getQos()), false, 0); msgIdVariableHeader = MqttMessageIdVariableHeader.from(destroyMessage.getMessageId()); return MqttMessageFactory.newMessage(compFixedHeader, msgIdVariableHeader, null); case Ping.MESSAGE_TYPE: Ping ping = (Ping) internalMessage; //We need to generate a PINGRESP message to respond to a PINGREQ. recFixedHeader = new MqttFixedHeader(MqttMessageType.PINGRESP, ping.isDup(), MqttQoS.valueOf(ping.getQos()), ping.isRetain(), 0); return MqttMessageFactory.newMessage(recFixedHeader, null, null); case ConnectAcknowledgeMessage.MESSAGE_TYPE: ConnectAcknowledgeMessage connAck = (ConnectAcknowledgeMessage) internalMessage; MqttFixedHeader connAckFixedHeader = new MqttFixedHeader(MqttMessageType.CONNACK, connAck.isDup(), MqttQoS.valueOf(connAck.getQos()), connAck.isRetain(), 0); MqttConnAckVariableHeader conAckVariableHeader = new MqttConnAckVariableHeader(connAck.getReturnCode()); //Todo: Raise netty codec issue for lack of codec 3.2.2.2 Session Present flag. return MqttMessageFactory.newMessage(connAckFixedHeader, conAckVariableHeader, null); case SubscribeAcknowledgeMessage.MESSAGE_TYPE: SubscribeAcknowledgeMessage subAckMsg = (SubscribeAcknowledgeMessage) internalMessage; MqttSubAckPayload payload = new MqttSubAckPayload(subAckMsg.getGrantedQos()); MqttFixedHeader subAckFixedHeader = new MqttFixedHeader(MqttMessageType.SUBACK, subAckMsg.isDup(), MqttQoS.valueOf(subAckMsg.getQos()), subAckMsg.isRetain(), 0); MqttMessageIdVariableHeader subAckVariableHeader = MqttMessageIdVariableHeader .from(subAckMsg.getMessageId()); return MqttMessageFactory.newMessage(subAckFixedHeader, subAckVariableHeader, payload); case UnSubscribeAcknowledgeMessage.MESSAGE_TYPE: UnSubscribeAcknowledgeMessage unSubAckMsg = (UnSubscribeAcknowledgeMessage) internalMessage; respFixedHeader = new MqttFixedHeader(MqttMessageType.UNSUBACK, unSubAckMsg.isDup(), MqttQoS.valueOf(unSubAckMsg.getQos()), unSubAckMsg.isRetain(), 0); MqttMessageIdVariableHeader variableHeader = MqttMessageIdVariableHeader .from(unSubAckMsg.getMessageId()); return MqttMessageFactory.newMessage(respFixedHeader, variableHeader, null); default: /** * * Internally these are not expected to get here. * In such cases we just return a null * and log this anomaly as a gross error. * * * if(internalMessage instanceof ConnectMessage || * internalMessage instanceof SubscribeMessage || * internalMessage instanceof UnSubscribeMessage || * internalMessage instanceof DisconnectMessage || * internalMessage instanceof WillMessage ){ * } **/ return null; } }
From source file:com.chiorichan.factory.FileInterpreter.java
License:Mozilla Public License
public final void interpretParamsFromFile(File file) throws IOException { if (file == null) throw new FileNotFoundException("File path was null"); FileInputStream is = null;//from w w w. j av a 2 s. c om try { cachedFile = file; annotations.put("file", file.getAbsolutePath()); if (file.isDirectory()) annotations.put("shell", "embedded"); else { if (!annotations.containsKey("shell") || annotations.get("shell") == null) { String shell = determineShellFromName(file.getName()); if (shell != null && !shell.isEmpty()) annotations.put("shell", shell); } is = new FileInputStream(file); ByteBuf buf = Unpooled.wrappedBuffer(IOUtils.toByteArray(is)); boolean beginContent = false; int lastInx; int lineCnt = 0; data = Unpooled.buffer(); do { lastInx = buf.readerIndex(); String l = readLine(buf); if (l == null) break; if (l.trim().startsWith("@")) try { lineCnt++; /* Only solution I could think of for CSS files since they use @annotations too, so we share them. */ if (ContentTypes.getContentType(file).equalsIgnoreCase("text/css")) data.writeBytes((l + "\n").getBytes()); /* Only solution I could think of for CSS files since they use @annotations too, so we share them. */ String key; String val = ""; if (l.contains(" ")) { key = l.trim().substring(1, l.trim().indexOf(" ")); val = l.trim().substring(l.trim().indexOf(" ") + 1); } else key = l; if (val.endsWith(";")) val = val.substring(0, val.length() - 1); if (val.startsWith("'") && val.endsWith("'")) val = val.substring(1, val.length() - 1); annotations.put(key.toLowerCase(), val); Log.get().finer("Setting param '" + key + "' to '" + val + "'"); if (key.equals("encoding")) if (Charset.isSupported(val)) setEncoding(Charsets.toCharset(val)); else Log.get() .severe("The file '" + file.getAbsolutePath() + "' requested encoding '" + val + "' but it's not supported by the JVM!"); } catch (NullPointerException | ArrayIndexOutOfBoundsException e) { } else if (l.trim().isEmpty()) lineCnt++; // Continue reading, this line is empty. else { // We encountered the beginning of the file content. beginContent = true; buf.readerIndex(lastInx); // This rewinds the buffer to the last reader index } } while (!beginContent); data.writeBytes(Strings.repeat('\n', lineCnt).getBytes()); data.writeBytes(buf); } } finally { if (is != null) is.close(); } }
From source file:com.chiorichan.http.HttpHandler.java
License:Mozilla Public License
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { try {/* www. ja v a 2 s . c o m*/ if (request == null || response == null) { NetworkManager.getLogger().severe(EnumColor.NEGATIVE + "" + EnumColor.RED + "We got an unexpected exception before the connection was processed:", cause); StringBuilder sb = new StringBuilder(); sb.append("<h1>500 - Internal Server Error</h1>\n"); sb.append( "<p>The server had encountered an unexpected exception before it could fully process your request, so no extended debug information is or will be available.</p>\n"); sb.append( "<p>The exception has been logged to the console, so we can only hope the exception is noticed and resolved. We apoligize for any inconvenience.</p>\n"); sb.append("<p><i>You have a good day now and we will see you again soon. :)</i></p>\n"); sb.append("<hr>\n"); sb.append(Versioning.getHTMLFooter()); FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.valueOf(500), Unpooled.wrappedBuffer(sb.toString().getBytes())); ctx.write(response); return; } String ip = request.getIpAddr(); if (requestFinished && cause instanceof HttpError) { int code = ((HttpError) cause).getHttpCode(); if (code >= 400 && code <= 499) NetworkSecurity.addStrikeToIp(ip, IpStrikeType.HTTP_ERROR_400); if (code >= 500 && code <= 599) NetworkSecurity.addStrikeToIp(ip, IpStrikeType.HTTP_ERROR_500); if (response.getStage() != HttpResponseStage.CLOSED) response.sendError((HttpError) cause); else NetworkManager.getLogger().severe(EnumColor.NEGATIVE + "" + EnumColor.RED + " [" + ip + "] For reasons unknown, we caught the HttpError but the connection was already closed.", cause); return; } if (requestFinished && "Connection reset by peer".equals(cause.getMessage())) { NetworkManager.getLogger().warning(EnumColor.NEGATIVE + "" + EnumColor.RED + " [" + ip + "] The connection was closed before we could finish the request, if the IP continues to abuse the system it WILL BE BANNED!"); NetworkSecurity.addStrikeToIp(ip, IpStrikeType.CLOSED_EARLY); return; } ScriptingException evalOrig = null; /* * Unpackage the EvalFactoryException. * Not sure if exceptions from the EvalFactory should be handled differently or not. * XXX Maybe skip generating exception pages for errors that were caused internally and report them to Chiori-chan unless the server is in development mode? */ if (cause instanceof ScriptingException && cause.getCause() != null) { evalOrig = (ScriptingException) cause; cause = cause.getCause(); } /* * Presently we can only send one exception to the client * So for now we only send the most severe one * * TODO Enhancement: Make it so each exception is printed out. */ if (cause instanceof MultipleException) { IException most = null; // The lower the intValue() to more important it became for (IException e : ((MultipleException) cause).getExceptions()) if (e instanceof Throwable && (most == null || most.reportingLevel().intValue() > e.reportingLevel().intValue())) most = e; if (most instanceof ScriptingException) { evalOrig = (ScriptingException) most; cause = most.getCause(); } else cause = (Throwable) most; } /* * TODO Proper Exception Handling. Consider the ability to have these exceptions cached, then delivered by e-mail to chiori-chan and/or server administrator. */ if (cause instanceof HttpError) response.sendError((HttpError) cause); else if (cause instanceof PermissionDeniedException) { PermissionDeniedException pde = (PermissionDeniedException) cause; if (pde.getReason() == PermissionDeniedReason.LOGIN_PAGE) response.sendLoginPage(pde.getReason().getMessage()); else /* * TODO generate a special permission denied page */ response.sendError(((PermissionDeniedException) cause).getHttpCode(), cause.getMessage()); } else if (cause instanceof OutOfMemoryError) { log.log(Level.SEVERE, EnumColor.NEGATIVE + "" + EnumColor.RED + "OutOfMemoryError! This is serious!!!"); response.sendError(500, "We have encountered an internal server error"); if (Versioning.isDevelopment()) cause.printStackTrace(); } else if (evalOrig == null) { // Was not caught by EvalFactory log.log(Level.SEVERE, "%s%sException %s thrown in file '%s' at line %s, message '%s'", EnumColor.NEGATIVE, EnumColor.RED, cause.getClass().getName(), cause.getStackTrace()[0].getFileName(), cause.getStackTrace()[0].getLineNumber(), cause.getMessage()); response.sendException(cause); if (Versioning.isDevelopment()) cause.printStackTrace(); } else { if (evalOrig.isScriptingException() && !evalOrig.hasScriptTrace()) { log.log(Level.WARNING, "We caught an EvalException which was determined to be related to a scripting issue but the exception has no script trace, this might be a combined internal and external problem.", EnumColor.NEGATIVE, EnumColor.RED); log.log(Level.SEVERE, "%s%sException %s thrown in file '%s' at line %s, message '%s'", EnumColor.NEGATIVE, EnumColor.RED, cause.getClass().getName(), cause.getStackTrace()[0].getFileName(), cause.getStackTrace()[0].getLineNumber(), cause.getMessage()); } else if (evalOrig.isScriptingException()) { ScriptTraceElement element = evalOrig.getScriptTrace()[0]; log.log(Level.SEVERE, "%s%sException %s thrown in file '%s' at line %s:%s, message '%s'", EnumColor.NEGATIVE, EnumColor.RED, cause.getClass().getName(), element.context().filename(), element.getLineNumber(), element.getColumnNumber() > 0 ? element.getColumnNumber() : 0, cause.getMessage()); } else log.log(Level.SEVERE, "%s%sException %s thrown with message '%s'", EnumColor.NEGATIVE, EnumColor.RED, cause.getClass().getName(), cause.getMessage()); // log.log( Level.SEVERE, "%s%sException %s thrown in file '%s' at line %s, message '%s'", LogColor.NEGATIVE, LogColor.RED, cause.getClass().getName(), cause.getStackTrace()[0].getFileName(), // cause.getStackTrace()[0].getLineNumber(), cause.getMessage() ); response.sendException(evalOrig); if (Versioning.isDevelopment()) cause.printStackTrace(); } finish(); } catch (Throwable t) { NetworkManager.getLogger().severe(EnumColor.NEGATIVE + "" + EnumColor.RED + "This is an uncaught exception from the exceptionCaught() method:", t); // ctx.fireExceptionCaught( t ); } }
From source file:com.chiorichan.http.HttpHandler.java
License:Mozilla Public License
@Override protected void messageReceived(ChannelHandlerContext ctx, Object msg) throws Exception { Timings.start(this); if (msg instanceof FullHttpRequest) { if (AppLoader.instances().get(0).runLevel() != RunLevel.RUNNING) { // Outputs a very crude raw message if we are running in a low level mode a.k.a. Startup or Reload. // While in the mode, much of the server API is potentially unavailable, that is why we do this. StringBuilder sb = new StringBuilder(); sb.append("<h1>503 - Service Unavailable</h1>\n"); sb.append(/*from w w w .j a va2 s . co m*/ "<p>I'm sorry to have to be the one to tell you this but the server is currently unavailable.</p>\n"); sb.append( "<p>This is most likely due to many possibilities, most commonly being it's currently booting up. Which would be great news because it means your request should succeed if you try again.</p>\n"); sb.append( "<p>But it is also possible that the server is actually running in a low level mode or could be offline for some other reason. If you feel this is a mistake, might I suggest you talk with the server admin.</p>\n"); sb.append("<p><i>You have a good day now and we will see you again soon. :)</i></p>\n"); sb.append("<hr>\n"); sb.append("<small>Running <a href=\"https://github.com/ChioriGreene/ChioriWebServer\">" + Versioning.getProduct() + "</a> Version " + Versioning.getVersion() + " (Build #" + Versioning.getBuildNumber() + ")<br />" + Versioning.getCopyright() + "</small>"); FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.valueOf(503), Unpooled.wrappedBuffer(sb.toString().getBytes())); ctx.write(response); return; } requestFinished = false; requestOrig = (FullHttpRequest) msg; request = new HttpRequestWrapper(ctx.channel(), requestOrig, this, ssl, log); response = request.getResponse(); String threadName = Thread.currentThread().getName(); if (threadName.length() > 10) threadName = threadName.substring(0, 2) + ".." + threadName.substring(threadName.length() - 6); else if (threadName.length() < 10) threadName = threadName + Strings.repeat(" ", 10 - threadName.length()); log.header("&7[&d%s&7] %s %s [&9%s:%s&7] -> [&a%s:%s&7]", threadName, dateFormat.format(Timings.millis()), timeFormat.format(Timings.millis()), request.getIpAddr(), request.getRemotePort(), request.getLocalIpAddr(), request.getLocalPort()); if (HttpHeaderUtil.is100ContinueExpected((HttpRequest) msg)) send100Continue(ctx); if (NetworkSecurity.isIpBanned(request.getIpAddr())) { response.sendError(403); return; } Site currentSite = request.getLocation(); File tmpFileDirectory = currentSite != null ? currentSite.directoryTemp() : AppConfig.get().getDirectoryCache(); setTempDirectory(tmpFileDirectory); if (request.isWebsocketRequest()) { try { WebSocketServerHandshakerFactory wsFactory = new WebSocketServerHandshakerFactory( request.getWebSocketLocation(requestOrig), null, true); handshaker = wsFactory.newHandshaker(requestOrig); if (handshaker == null) WebSocketServerHandshakerFactory.sendUnsupportedVersionResponse(ctx.channel()); else handshaker.handshake(ctx.channel(), requestOrig); } catch (WebSocketHandshakeException e) { NetworkManager.getLogger().severe( "A request was made on the websocket uri '/fw/websocket' but it failed to handshake for reason '" + e.getMessage() + "'."); response.sendError(500, null, "This URI is for websocket requests only<br />" + e.getMessage()); } return; } if (request.method() != HttpMethod.GET) try { decoder = new HttpPostRequestDecoder(factory, requestOrig); } catch (ErrorDataDecoderException e) { e.printStackTrace(); response.sendException(e); return; } request.contentSize += requestOrig.content().readableBytes(); if (decoder != null) { try { decoder.offer(requestOrig); } catch (ErrorDataDecoderException e) { e.printStackTrace(); response.sendError(e); // ctx.channel().close(); return; } catch (IllegalArgumentException e) { // TODO Handle this further? maybe? // java.lang.IllegalArgumentException: empty name } readHttpDataChunkByChunk(); } handleHttp(); finish(); } else if (msg instanceof WebSocketFrame) { WebSocketFrame frame = (WebSocketFrame) msg; // Check for closing frame if (frame instanceof CloseWebSocketFrame) { handshaker.close(ctx.channel(), (CloseWebSocketFrame) frame.retain()); return; } if (frame instanceof PingWebSocketFrame) { ctx.channel().write(new PongWebSocketFrame(frame.content().retain())); return; } if (!(frame instanceof TextWebSocketFrame)) throw new UnsupportedOperationException( String.format("%s frame types are not supported", frame.getClass().getName())); String request = ((TextWebSocketFrame) frame).text(); NetworkManager.getLogger() .fine("Received '" + request + "' over WebSocket connection '" + ctx.channel() + "'"); ctx.channel().write(new TextWebSocketFrame(request.toUpperCase())); } else if (msg instanceof DefaultHttpRequest) { // Do Nothing! } else NetworkManager.getLogger().warning( "Received Object '" + msg.getClass() + "' and had nothing to do with it, is this a bug?"); }
From source file:com.cloudhopper.smpp.pdu.BufferHelper.java
License:Apache License
static public ByteBuf createBuffer(byte[] bytes) throws Exception { return Unpooled.wrappedBuffer(bytes).order(ByteOrder.BIG_ENDIAN); }
From source file:com.cmz.http.websocketx.client.WebSocketClient.java
License:Apache License
public static void main(String[] args) throws Exception { URI uri = new URI(URL); String scheme = uri.getScheme() == null ? "ws" : uri.getScheme(); final String host = uri.getHost() == null ? "127.0.0.1" : uri.getHost(); final int port; if (uri.getPort() == -1) { if ("ws".equalsIgnoreCase(scheme)) { port = 80;/*from w w w .ja v a 2s .c o m*/ } else if ("wss".equalsIgnoreCase(scheme)) { port = 443; } else { port = -1; } } else { port = uri.getPort(); } if (!"ws".equalsIgnoreCase(scheme) && !"wss".equalsIgnoreCase(scheme)) { System.err.println("Only WS(S) is supported."); return; } final boolean ssl = "wss".equalsIgnoreCase(scheme); final SslContext sslCtx; if (ssl) { sslCtx = SslContextBuilder.forClient().trustManager(InsecureTrustManagerFactory.INSTANCE).build(); } else { sslCtx = null; } EventLoopGroup group = new NioEventLoopGroup(); try { // Connect with V13 (RFC 6455 aka HyBi-17). You can change it to V08 or V00. // If you change it to V00, ping is not supported and remember to change // HttpResponseDecoder to WebSocketHttpResponseDecoder in the pipeline. final WebSocketClientHandler handler = new WebSocketClientHandler(WebSocketClientHandshakerFactory .newHandshaker(uri, WebSocketVersion.V13, null, true, new DefaultHttpHeaders())); Bootstrap b = new Bootstrap(); b.group(group).channel(NioSocketChannel.class).handler(new ChannelInitializer<SocketChannel>() { @Override protected void initChannel(SocketChannel ch) { ChannelPipeline p = ch.pipeline(); if (sslCtx != null) { p.addLast(sslCtx.newHandler(ch.alloc(), host, port)); } p.addLast(new HttpClientCodec(), new HttpObjectAggregator(8192), WebSocketClientCompressionHandler.INSTANCE, handler); } }); Channel ch = b.connect(uri.getHost(), port).sync().channel(); handler.handshakeFuture().sync(); BufferedReader console = new BufferedReader(new InputStreamReader(System.in)); while (true) { String msg = console.readLine(); if (msg == null) { break; } else if ("bye".equals(msg.toLowerCase())) { ch.writeAndFlush(new CloseWebSocketFrame()); ch.closeFuture().sync(); break; } else if ("ping".equals(msg.toLowerCase())) { WebSocketFrame frame = new PingWebSocketFrame( Unpooled.wrappedBuffer(new byte[] { 8, 1, 8, 1 })); ch.writeAndFlush(frame); } else { WebSocketFrame frame = new TextWebSocketFrame(msg); ch.writeAndFlush(frame); } } } finally { group.shutdownGracefully(); } }
From source file:com.comphenix.protocol.compat.netty.independent.IndependentNetty.java
License:Open Source License
@Override public String toEncodedText(CompressedImage image) { final ByteBuf buffer = Unpooled.wrappedBuffer(image.getDataCopy()); String computed = "data:" + image.getMime() + ";base64," + Base64.encode(buffer).toString(Charsets.UTF_8); return computed; }
From source file:com.comphenix.protocol.compat.netty.independent.IndependentNetty.java
License:Open Source License
@Override public WrappedByteBuf decode(byte[] encoded) { return new NettyByteBuf(Base64.decode(Unpooled.wrappedBuffer(encoded))); }
From source file:com.corundumstudio.socketio.handler.PacketHandlerTest.java
License:Apache License
public void testDecodePerf() throws Exception { PacketListener listener = new PacketListener(null, null, null) { @Override/*from w w w .jav a 2 s . com*/ public void onPacket(Packet packet, NamespaceClient client) { } }; PacketHandler handler = new PacketHandler(listener, decoder, namespacesHub); long start = System.currentTimeMillis(); ByteBuf buffer = Unpooled.wrappedBuffer( "\ufffd10\ufffd3:::\ufffd7\ufffd3:::53d\ufffd3\ufffd0::\ufffd5\ufffd3:::5\ufffd7\ufffd3:::53d\ufffd3\ufffd0::\ufffd5\ufffd3:::5\ufffd7\ufffd3:::53d\ufffd3\ufffd0::\ufffd5\ufffd3:::5\ufffd7\ufffd3:::53d\ufffd3\ufffd0::\ufffd5\ufffd3:::5\ufffd7\ufffd3:::53d\ufffd3\ufffd0::" .getBytes()); for (int i = 0; i < 50000; i++) { handler.channelRead0(null, new PacketsMessage(client, buffer)); buffer.readerIndex(0); } long end = System.currentTimeMillis() - start; System.out.println(end + "ms"); // 670ms }