下面列出了io.netty.buffer.ByteBufUtil#hexDump ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* 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()][]);
}
@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);
}
}
@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"));
}
/**
* 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()][]);
}
@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));
}
@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;
}
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) + "...";
}
@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;
}
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) + "...";
}
@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 }
};
}
@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()) + '}';
}
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;
}
public static String transform(PackageData<Header> packageData) {
ByteBuf buf = encoder.encode(packageData);
String hex = ByteBufUtil.hexDump(buf);
return hex;
}
protected static String generateId() {
byte[] id = new byte[16];
ThreadLocalRandom.current().nextBytes(id);
return ByteBufUtil.hexDump(id);
}
@Benchmark
@BenchmarkMode({ Mode.Throughput })
@OutputTimeUnit(TimeUnit.MICROSECONDS)
public String toHexByNetty() {
return ByteBufUtil.hexDump(bytes);
}
protected String generateRequestId() {
byte[] id = new byte[16];
ThreadLocalRandom.current().nextBytes(id);
return ByteBufUtil.hexDump(id);
}
private String readRemainPacket(final MySQLPacketPayload payload) {
return ByteBufUtil.hexDump(payload.readStringFixByBytes(payload.getByteBuf().readableBytes()));
}
private RSemaphore getClearSemaphore(byte[] requestId) {
String id = ByteBufUtil.hexDump(requestId);
RSemaphore semaphore = new RedissonSemaphore(commandExecutor, name + ":clear:" + id);
return semaphore;
}
@Override
public String toString() {
return ByteBufUtil.hexDump(id);
}
private String generateId() {
byte[] id = new byte[8];
ThreadLocalRandom.current().nextBytes(id);
return ByteBufUtil.hexDump(id);
}