List of usage examples for io.netty.buffer ByteBuf toString
public abstract String toString(Charset charset);
From source file:com.lambdaworks.redis.protocol.CommandArgsTest.java
License:Apache License
@Test public void addByteUsingDirectByteCodec() throws Exception { CommandArgs<byte[], byte[]> args = new CommandArgs<>(CommandArgs.ExperimentalByteArrayCodec.INSTANCE) .add("one".getBytes()); ByteBuf buffer = Unpooled.buffer(); args.encode(buffer);/*w w w . jav a 2s.co m*/ ByteBuf expected = Unpooled.buffer(); expected.writeBytes(("$3\r\n" + "one\r\n").getBytes()); assertThat(buffer.toString(LettuceCharsets.ASCII)).isEqualTo(expected.toString(LettuceCharsets.ASCII)); }
From source file:com.lambdaworks.redis.protocol.CommandArgsTest.java
License:Apache License
@Test public void addValueUsingDirectByteCodec() throws Exception { CommandArgs<byte[], byte[]> args = new CommandArgs<>(CommandArgs.ExperimentalByteArrayCodec.INSTANCE) .addValue("one".getBytes()); ByteBuf buffer = Unpooled.buffer(); args.encode(buffer);/*from w ww .j av a 2s .c o m*/ ByteBuf expected = Unpooled.buffer(); expected.writeBytes(("$3\r\n" + "one\r\n").getBytes()); assertThat(buffer.toString(LettuceCharsets.ASCII)).isEqualTo(expected.toString(LettuceCharsets.ASCII)); }
From source file:com.lambdaworks.redis.protocol.CommandArgsTest.java
License:Apache License
@Test public void addKeyUsingDirectByteCodec() throws Exception { CommandArgs<byte[], byte[]> args = new CommandArgs<>(CommandArgs.ExperimentalByteArrayCodec.INSTANCE) .addValue("one".getBytes()); ByteBuf buffer = Unpooled.buffer(); args.encode(buffer);//w ww . j a v a 2 s .co m ByteBuf expected = Unpooled.buffer(); expected.writeBytes(("$3\r\n" + "one\r\n").getBytes()); assertThat(buffer.toString(LettuceCharsets.ASCII)).isEqualTo(expected.toString(LettuceCharsets.ASCII)); }
From source file:com.lambdaworks.redis.protocol.CommandArgsTest.java
License:Apache License
@Test public void addByteUsingByteCodec() throws Exception { CommandArgs<byte[], byte[]> args = new CommandArgs<>(ByteArrayCodec.INSTANCE).add("one".getBytes()); ByteBuf buffer = Unpooled.buffer(); args.encode(buffer);/*from w w w . ja va 2 s . c o m*/ ByteBuf expected = Unpooled.buffer(); expected.writeBytes(("$3\r\n" + "one\r\n").getBytes()); assertThat(buffer.toString(LettuceCharsets.ASCII)).isEqualTo(expected.toString(LettuceCharsets.ASCII)); }
From source file:com.lambdaworks.redis.protocol.CommandArgsTest.java
License:Apache License
@Test public void addValueUsingByteCodec() throws Exception { CommandArgs<byte[], byte[]> args = new CommandArgs<>(ByteArrayCodec.INSTANCE).addValue("one".getBytes()); ByteBuf buffer = Unpooled.buffer(); args.encode(buffer);/*from w w w. j a v a 2 s . c o m*/ ByteBuf expected = Unpooled.buffer(); expected.writeBytes(("$3\r\n" + "one\r\n").getBytes()); assertThat(buffer.toString(LettuceCharsets.ASCII)).isEqualTo(expected.toString(LettuceCharsets.ASCII)); }
From source file:com.lambdaworks.redis.protocol.CommandArgsTest.java
License:Apache License
@Test public void addKeyUsingByteCodec() throws Exception { CommandArgs<byte[], byte[]> args = new CommandArgs<>(ByteArrayCodec.INSTANCE).addValue("one".getBytes()); ByteBuf buffer = Unpooled.buffer(); args.encode(buffer);//from w w w . j ava 2 s. co m ByteBuf expected = Unpooled.buffer(); expected.writeBytes(("$3\r\n" + "one\r\n").getBytes()); assertThat(buffer.toString(LettuceCharsets.ASCII)).isEqualTo(expected.toString(LettuceCharsets.ASCII)); }
From source file:com.lambdaworks.redis.protocol.CommandEncoder.java
License:Apache License
private void encode(ChannelHandlerContext ctx, ByteBuf out, RedisCommand<?, ?, ?> command) { try {/*from w ww . j a v a 2 s. c om*/ out.markWriterIndex(); command.encode(out); } catch (RuntimeException e) { out.resetWriterIndex(); command.completeExceptionally(new EncoderException( "Cannot encode command. Please close the connection as the connection state may be out of sync.", e)); } if (debugEnabled) { logger.debug("{} writing command {}", logPrefix(ctx.channel()), command); if (traceEnabled) { logger.trace("{} Sent: {}", logPrefix(ctx.channel()), out.toString(Charset.defaultCharset()).trim()); } } }
From source file:com.liferay.sync.engine.lan.server.discovery.LanDiscoveryListenerHandler.java
License:Open Source License
@Override public void channelRead0(ChannelHandlerContext channelHandlerContext, DatagramPacket datagramPacket) throws Exception { ByteBuf byteBuf = datagramPacket.content(); SyncLanClient syncLanClient = JSONUtil.readValue(byteBuf.toString(CharsetUtil.UTF_8), SyncLanClient.class); String syncLanClientUuid = syncLanClient.getSyncLanClientUuid(); if (syncLanClientUuid.equals(LanClientUtil.getSyncLanClientUuid())) { return;//from w w w . j av a 2s . c o m } List<SyncLanEndpoint> syncLanEndpoints = SyncLanEndpointService.findSyncLanEndPoints(syncLanClientUuid); Map<String, Set<Long>> endpoints = syncLanClient.getEndpoints(); for (Map.Entry<String, Set<Long>> entry : endpoints.entrySet()) { for (Long groupId : entry.getValue()) { SyncLanEndpoint syncLanEndpoint = new SyncLanEndpoint(); syncLanEndpoint.setLanServerUuid(entry.getKey()); syncLanEndpoint.setRepositoryId(groupId); syncLanEndpoint.setSyncLanClientUuid(syncLanClientUuid); if (!syncLanEndpoints.remove(syncLanEndpoint)) { SyncLanEndpointService.update(syncLanEndpoint); } } } for (SyncLanEndpoint syncLanEndpoint : syncLanEndpoints) { SyncLanEndpointService.deleteSyncLanEndpoint(syncLanEndpoint); } InetSocketAddress inetSocketAddress = datagramPacket.sender(); syncLanClient.setHostname(inetSocketAddress.getHostName()); syncLanClient.setModifiedTime(System.currentTimeMillis()); SyncLanClientService.update(syncLanClient); }
From source file:com.linecorp.armeria.common.http.Http2GoAwayListener.java
License:Apache License
private void onGoAway(String sentOrReceived, int lastStreamId, long errorCode, ByteBuf debugData) { if (errorCode != Http2Error.NO_ERROR.code()) { if (logger.isWarnEnabled()) { logger.warn("{} {} a GOAWAY frame: lastStreamId={}, errorCode={}, debugData=\"{}\" (Hex: {})", ch, sentOrReceived, lastStreamId, errorStr(errorCode), debugData.toString(StandardCharsets.UTF_8), ByteBufUtil.hexDump(debugData)); }/* w ww . j a v a 2 s. c o m*/ } else { if (logger.isDebugEnabled()) { logger.debug("{} {} a GOAWAY frame: lastStreamId={}, errorCode=NO_ERROR", ch, sentOrReceived, lastStreamId); } } }
From source file:com.linecorp.armeria.internal.http.Http2GoAwayListener.java
License:Apache License
private void onGoAway(String sentOrReceived, int lastStreamId, long errorCode, ByteBuf debugData) { if (errorCode != Http2Error.NO_ERROR.code()) { if (logger.isWarnEnabled()) { logger.warn("{} {} a GOAWAY frame: lastStreamId={}, errorCode={}, debugData=\"{}\"", ch, sentOrReceived, lastStreamId, errorStr(errorCode), debugData.toString(StandardCharsets.UTF_8)); }/*from w w w. j av a 2 s . c o m*/ } else { if (logger.isDebugEnabled()) { logger.debug("{} {} a GOAWAY frame: lastStreamId={}, errorCode=NO_ERROR", ch, sentOrReceived, lastStreamId); } } }