Java Code Examples for io.netty.buffer.ByteBufUtil#hexDump()

The following examples show how to use io.netty.buffer.ByteBufUtil#hexDump() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FingerprintTrustManagerFactory.java    From netty4.0.27Learn with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new instance.
 *
 * @param fingerprints a list of SHA1 fingerprints
 */
public FingerprintTrustManagerFactory(byte[]... fingerprints) {
    if (fingerprints == null) {
        throw new NullPointerException("fingerprints");
    }

    List<byte[]> list = new ArrayList<byte[]>();
    for (byte[] f: fingerprints) {
        if (f == null) {
            break;
        }
        if (f.length != SHA1_BYTE_LEN) {
            throw new IllegalArgumentException("malformed fingerprint: " +
                    ByteBufUtil.hexDump(Unpooled.wrappedBuffer(f)) + " (expected: SHA1)");
        }
        list.add(f.clone());
    }

    this.fingerprints = list.toArray(new byte[list.size()][]);
}
 
Example 2
Source File: FingerprintTrustManagerFactory.java    From netty-4.1.22 with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new instance.
 *
 * @param fingerprints a list of SHA1 fingerprints
 */
public FingerprintTrustManagerFactory(byte[]... fingerprints) {
    if (fingerprints == null) {
        throw new NullPointerException("fingerprints");
    }

    List<byte[]> list = new ArrayList<byte[]>(fingerprints.length);
    for (byte[] f: fingerprints) {
        if (f == null) {
            break;
        }
        if (f.length != SHA1_BYTE_LEN) {
            throw new IllegalArgumentException("malformed fingerprint: " +
                    ByteBufUtil.hexDump(Unpooled.wrappedBuffer(f)) + " (expected: SHA1)");
        }
        list.add(f.clone());
    }

    this.fingerprints = list.toArray(new byte[list.size()][]);
}
 
Example 3
Source File: HttpClientTracingHandlerIntegrationTest.java    From xio with Apache License 2.0 6 votes vote down vote up
@Test
public void testOutBoundAndInboundSpan() throws Exception {
  TracingConfig tracingConfig =
      new TracingConfig(
          "tracingHandlerClientIntegrationTest", config().getConfig("settings.tracing"));
  val client = newClient(new FakeTracer(tracingConfig));

  val request =
      DefaultSegmentedRequest.builder()
          .method(GET)
          .path("/v1/authinit")
          .host("127.0.0.1" + ":" + server.getPort())
          .build();

  client.write(request);
  // We wait on the local future because this signals the full roundtrip between outbound and
  // return trip from the Application Handler out and then back in.
  local.get();
  assertEquals(reportedSpans.size(), 1);

  val responseHex = ByteBufUtil.hexDump(((SegmentedData) response).content());
  byte[] bytes = Hex.decodeHex(responseHex.toCharArray());
  assertEquals(expectedResponse, new String(bytes, "UTF-8"));
}
 
Example 4
Source File: WriteBufferingAndExceptionHandler.java    From grpc-java with Apache License 2.0 6 votes vote down vote up
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) {
  try {
    if (logger.isLoggable(Level.FINE)) {
      Object loggedMsg = msg instanceof ByteBuf ? ByteBufUtil.hexDump((ByteBuf) msg) : msg;
      logger.log(
          Level.FINE,
          "Unexpected channelRead()->{0} reached end of pipeline {1}",
          new Object[] {loggedMsg, ctx.pipeline().names()});
    }
    exceptionCaught(
        ctx,
        Status.INTERNAL.withDescription(
            "channelRead() missed by ProtocolNegotiator handler: " + msg)
            .asRuntimeException());
  } finally {
    ReferenceCountUtil.safeRelease(msg);
  }
}
 
Example 5
Source File: DarkRepulsor.java    From jt808-server with Apache License 2.0 5 votes vote down vote up
@Override
public void write(ByteBuf buf, Property prop, Object value) {
    int before = buf.writerIndex();
    super.write(buf, prop, value);
    int after = buf.writerIndex();

    String hex = ByteBufUtil.hexDump(buf, before, after - before);
    System.out.println(prop.index() + "\t" + hex + "\t" + prop.desc() + "\t" + String.valueOf(value));
}
 
Example 6
Source File: CommandAsyncService.java    From redisson with Apache License 2.0 5 votes vote down vote up
private String calcSHA(String script) {
    String digest = SHA_CACHE.get(script);
    if (digest == null) {
        try {
            MessageDigest mdigest = MessageDigest.getInstance("SHA-1");
            byte[] s = mdigest.digest(script.getBytes());
            digest = ByteBufUtil.hexDump(s);
            SHA_CACHE.put(script, digest);
        } catch (Exception e) {
            throw new IllegalStateException(e);
        }
    }
    return digest;
}
 
Example 7
Source File: SctpMessage.java    From netty4.0.27Learn with Apache License 2.0 5 votes vote down vote up
@Override
public String toString() {
    if (refCnt() == 0) {
        return "SctpFrame{" +
                "streamIdentifier=" + streamIdentifier + ", protocolIdentifier=" + protocolIdentifier +
                ", data=(FREED)}";
    }
    return "SctpFrame{" +
            "streamIdentifier=" + streamIdentifier + ", protocolIdentifier=" + protocolIdentifier +
            ", data=" + ByteBufUtil.hexDump(content()) + '}';
}
 
Example 8
Source File: CompressorCodecTest.java    From pulsar with Apache License 2.0 5 votes vote down vote up
@DataProvider(name = "codec")
public Object[][] codecProvider() {
    return new Object[][] {
            { CompressionType.NONE, ByteBufUtil.hexDump(text.getBytes()) },
            { CompressionType.LZ4, lz4CompressedText },
            { CompressionType.ZLIB, zipCompressedText },
            { CompressionType.ZSTD, zstdCompressedText },
            { CompressionType.SNAPPY, snappyCompressedText }
    };
}
 
Example 9
Source File: DynamicHttp2FrameLogger.java    From zuul with Apache License 2.0 5 votes vote down vote up
private String toString(ByteBuf buf) {
    if (level == InternalLogLevel.TRACE || buf.readableBytes() <= BUFFER_LENGTH_THRESHOLD) {
        // Log the entire buffer.
        return ByteBufUtil.hexDump(buf);
    }

    // Otherwise just log the first 64 bytes.
    int length = Math.min(buf.readableBytes(), BUFFER_LENGTH_THRESHOLD);
    return ByteBufUtil.hexDump(buf, buf.readerIndex(), length) + "...";
}
 
Example 10
Source File: DefaultChannelId.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
@Override
public String asShortText() {
    String shortValue = this.shortValue;
    if (shortValue == null) {
        this.shortValue = shortValue = ByteBufUtil.hexDump(data, data.length - RANDOM_LEN, RANDOM_LEN);
    }
    return shortValue;
}
 
Example 11
Source File: Http2FrameLogger.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
private String toString(ByteBuf buf) {
    if (!logger.isEnabled(level)) {
        return StringUtil.EMPTY_STRING;
    }

    if (level == InternalLogLevel.TRACE || buf.readableBytes() <= BUFFER_LENGTH_THRESHOLD) {
        // Log the entire buffer.
        return ByteBufUtil.hexDump(buf);
    }

    // Otherwise just log the first 64 bytes.
    int length = Math.min(buf.readableBytes(), BUFFER_LENGTH_THRESHOLD);
    return ByteBufUtil.hexDump(buf, buf.readerIndex(), length) + "...";
}
 
Example 12
Source File: Elucidator.java    From jt808-server with Apache License 2.0 5 votes vote down vote up
@Override
public Object read(ByteBuf buf, Property prop, int length, PropertyDescriptor pd) {
    buf.markReaderIndex();
    String hex = ByteBufUtil.hexDump(buf.readSlice(length));
    buf.resetReaderIndex();

    Object value = super.read(buf, prop, length, pd);
    System.out.println(prop.index() + "\t" + hex + "\t" + prop.desc() + "\t" + String.valueOf(value));
    return value;
}
 
Example 13
Source File: RedissonExecutorService.java    From redisson with Apache License 2.0 4 votes vote down vote up
protected String generateRequestId() {
    byte[] id = new byte[16];
    ThreadLocalRandom.current().nextBytes(id);
    return ByteBufUtil.hexDump(id);
}
 
Example 14
Source File: HexBenchmark.java    From turbo-rpc with Apache License 2.0 4 votes vote down vote up
@Benchmark
@BenchmarkMode({ Mode.Throughput })
@OutputTimeUnit(TimeUnit.MICROSECONDS)
public String toHexByNetty() {
	return ByteBufUtil.hexDump(bytes);
}
 
Example 15
Source File: MySQLBinlogEventPacketDecoder.java    From shardingsphere with Apache License 2.0 4 votes vote down vote up
private String readRemainPacket(final MySQLPacketPayload payload) {
    return ByteBufUtil.hexDump(payload.readStringFixByBytes(payload.getByteBuf().readableBytes()));
}
 
Example 16
Source File: RedissonTransaction.java    From redisson with Apache License 2.0 4 votes vote down vote up
protected static String generateId() {
    byte[] id = new byte[16];
    ThreadLocalRandom.current().nextBytes(id);
    return ByteBufUtil.hexDump(id);
}
 
Example 17
Source File: LocalCacheListener.java    From redisson with Apache License 2.0 4 votes vote down vote up
private RSemaphore getClearSemaphore(byte[] requestId) {
    String id = ByteBufUtil.hexDump(requestId);
    RSemaphore semaphore = new RedissonSemaphore(commandExecutor, name + ":clear:" + id);
    return semaphore;
}
 
Example 18
Source File: CoderTest.java    From jt808-server with Apache License 2.0 4 votes vote down vote up
public static String transform(PackageData<Header> packageData) {
    ByteBuf buf = encoder.encode(packageData);
    String hex = ByteBufUtil.hexDump(buf);
    return hex;
}
 
Example 19
Source File: RequestId.java    From redisson with Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
    return ByteBufUtil.hexDump(id);
}
 
Example 20
Source File: RedissonNode.java    From redisson with Apache License 2.0 4 votes vote down vote up
private String generateId() {
    byte[] id = new byte[8];
    ThreadLocalRandom.current().nextBytes(id);
    return ByteBufUtil.hexDump(id);
}