List of usage examples for io.netty.buffer ByteBufUtil hexDump
public static String hexDump(byte[] array)
From source file:org.apache.zookeeper.server.NettyServerCnxn.java
License:Apache License
/** * Receive a message, which can come from the queued buffer or from a new * buffer coming in over the channel. This should only be called from the * event loop thread./*from w w w . j av a2 s . co m*/ * @param message the message bytes to process. */ private void receiveMessage(ByteBuf message) { assert channel.eventLoop().inEventLoop(); try { while (message.isReadable() && !throttled.get()) { if (bb != null) { if (LOG.isTraceEnabled()) { LOG.trace("message readable {} bb len {} {}", message.readableBytes(), bb.remaining(), bb); ByteBuffer dat = bb.duplicate(); dat.flip(); LOG.trace("0x{} bb {}", Long.toHexString(sessionId), ByteBufUtil.hexDump(Unpooled.wrappedBuffer(dat))); } if (bb.remaining() > message.readableBytes()) { int newLimit = bb.position() + message.readableBytes(); bb.limit(newLimit); } message.readBytes(bb); bb.limit(bb.capacity()); if (LOG.isTraceEnabled()) { LOG.trace("after readBytes message readable {} bb len {} {}", message.readableBytes(), bb.remaining(), bb); ByteBuffer dat = bb.duplicate(); dat.flip(); LOG.trace("after readbytes 0x{} bb {}", Long.toHexString(sessionId), ByteBufUtil.hexDump(Unpooled.wrappedBuffer(dat))); } if (bb.remaining() == 0) { bb.flip(); packetReceived(4 + bb.remaining()); ZooKeeperServer zks = this.zkServer; if (zks == null || !zks.isRunning()) { throw new IOException("ZK down"); } if (initialized) { // TODO: if zks.processPacket() is changed to take a ByteBuffer[], // we could implement zero-copy queueing. zks.processPacket(this, bb); } else { if (LOG.isDebugEnabled()) { LOG.debug("got conn req request from {}", getRemoteSocketAddress()); } zks.processConnectRequest(this, bb); initialized = true; } bb = null; } } else { if (LOG.isTraceEnabled()) { LOG.trace("message readable {} bblenrem {}", message.readableBytes(), bbLen.remaining()); ByteBuffer dat = bbLen.duplicate(); dat.flip(); LOG.trace("0x{} bbLen {}", Long.toHexString(sessionId), ByteBufUtil.hexDump(Unpooled.wrappedBuffer(dat))); } if (message.readableBytes() < bbLen.remaining()) { bbLen.limit(bbLen.position() + message.readableBytes()); } message.readBytes(bbLen); bbLen.limit(bbLen.capacity()); if (bbLen.remaining() == 0) { bbLen.flip(); if (LOG.isTraceEnabled()) { LOG.trace("0x{} bbLen {}", Long.toHexString(sessionId), ByteBufUtil.hexDump(Unpooled.wrappedBuffer(bbLen))); } int len = bbLen.getInt(); if (LOG.isTraceEnabled()) { LOG.trace("0x{} bbLen len is {}", Long.toHexString(sessionId), len); } bbLen.clear(); if (!initialized) { if (checkFourLetterWord(channel, message, len)) { return; } } if (len < 0 || len > BinaryInputArchive.maxBuffer) { throw new IOException("Len error " + len); } bb = ByteBuffer.allocate(len); } } } } catch (IOException e) { LOG.warn("Closing connection to " + getRemoteSocketAddress(), e); close(); } }
From source file:org.eclipse.milo.opcua.binaryschema.BsdParserTest.java
License:Open Source License
protected void assertRoundTrip(String type, Object originalValue, OpcUaBinaryDataTypeCodec<Object> codec) { System.out.printf("--- assertRoundTrip Type: %s ---\n", type); System.out.println("originalValue:\t" + originalValue); ByteBuf buffer = Unpooled.buffer();// w w w . j av a 2 s. c om codec.encode(context, originalValue, new OpcUaBinaryStreamEncoder(buffer)); ByteBuf encodedValue = buffer.copy(); System.out.println("encodedValue:\t" + ByteBufUtil.hexDump(encodedValue)); Object decodedValue = codec.decode(context, new OpcUaBinaryStreamDecoder(buffer)); assertEquals(decodedValue, originalValue); System.out.println("decodedValue:\t" + decodedValue); }
From source file:org.eclipse.milo.opcua.binaryschema.BsdParserTest.java
License:Open Source License
/** * A weaker version of {@link #assertRoundTrip(String, Object, OpcUaBinaryDataTypeCodec)} for values that don't * implement equals and hashcode or values that contain members not implementing equals and hashcode. * <p>// w w w . jav a 2 s . c o m * Relies on toString() values to be implemented at all levels instead... not great, but since the built-in structs * don't implement equals/hashcode it's what we have. */ protected void assertRoundTripUsingToString(String type, Object originalValue, OpcUaBinaryDataTypeCodec<Object> codec) { System.out.printf("--- assertRoundTrip Type: %s ---\n", type); System.out.println("originalValue:\t" + originalValue); ByteBuf buffer = Unpooled.buffer(); codec.encode(context, originalValue, new OpcUaBinaryStreamEncoder(buffer)); ByteBuf encodedValue = buffer.copy(); System.out.println("encodedValue:\t" + ByteBufUtil.hexDump(encodedValue)); Object decodedValue = codec.decode(context, new OpcUaBinaryStreamDecoder(buffer)); assertEquals(decodedValue.toString(), originalValue.toString()); System.out.println("decodedValue:\t" + decodedValue); }
From source file:org.eclipse.milo.opcua.sdk.server.events.conversions.ByteStringConversions.java
License:Open Source License
@Nonnull static String byteStringToString(@Nonnull ByteString bs) { return ByteBufUtil.hexDump(bs.bytesOrEmpty()); }
From source file:org.eclipse.milo.opcua.sdk.server.events.conversions.ByteStringConversionsTest.java
License:Open Source License
@Test public void testByteStringToString() { ByteString bs = ByteString.of(new byte[] { 0x01, 0x02, 0x03 }); assertEquals(ByteBufUtil.hexDump(bs.bytesOrEmpty()), ByteStringConversions.byteStringToString(bs)); }
From source file:org.eclipse.milo.opcua.stack.core.application.DirectoryCertificateValidator.java
License:Open Source License
private static String getFilename(X509Certificate certificate) throws Exception { String[] ss = certificate.getSubjectX500Principal().getName().split(","); String name = ss.length > 0 ? ss[0] : certificate.getSubjectX500Principal().getName(); String thumbprint = ByteBufUtil.hexDump(Unpooled.wrappedBuffer(DigestUtil.sha1(certificate.getEncoded()))); return String.format("%s [%s].der", thumbprint, URLEncoder.encode(name, "UTF-8")); }
From source file:org.eclipse.milo.opcua.stack.core.security.DefaultTrustListManager.java
License:Open Source License
private static String getFilename(X509CRL crl) throws Exception { String thumbprint = ByteBufUtil.hexDump(sha1(crl.getEncoded())); return String.format("%s.crl", thumbprint); }
From source file:org.eclipse.milo.opcua.stack.core.security.DefaultTrustListManager.java
License:Open Source License
private static String getFilename(X509Certificate certificate) throws Exception { String[] ss = certificate.getSubjectX500Principal().getName().split(","); String name = ss.length > 0 ? ss[0] : certificate.getSubjectX500Principal().getName(); String thumbprint = ByteBufUtil.hexDump(sha1(certificate.getSignature())); return String.format("%s [%s].der", thumbprint, URLEncoder.encode(name, "UTF-8")); }
From source file:org.eclipse.neoscada.protocol.iec60870.apci.APDUDecoder.java
License:Open Source License
@Override protected void decode(final ChannelHandlerContext ctx, final ByteBuf in, final List<Object> out) throws Exception { if (logger.isTraceEnabled()) { logger.trace("decode - bytes: {}", ByteBufUtil.hexDump(in)); }//from w w w . j ava 2 s .c om if (in.readableBytes() < Constants.APCI_MIN_LENGTH) { return; } final byte start = in.getByte(in.readerIndex() + 0); if (start != Constants.START_BYTE) { throw new DecoderException( String.format("ACPI must start with 0x%02x but did with 0x%02x", Constants.START_BYTE, start)); } final short len = in.getUnsignedByte(in.readerIndex() + 1); if (len > Constants.APCI_MAX_DATA_LENGTH) { throw new DecoderException(String.format("APCI has a maximum length of %s bytes, but we received %s", Constants.APCI_MAX_DATA_LENGTH, len)); } if (in.readableBytes() < len + 2) { return; } // we have the full InformationTransfer // skip start & len in.skipBytes(2); // read control fields final ByteBuf controlFields = in.readSlice(4); final ByteBuf data; if (len > 4) { data = Unpooled.copiedBuffer(in.readSlice(len - 4)).order(ByteOrder.LITTLE_ENDIAN); } else { data = null; } // now add the PDU out.add(decode(controlFields, data)); }
From source file:org.eclipse.neoscada.protocol.iec60870.apci.APDUDecoder.java
License:Open Source License
private APCIBase decode(ByteBuf controlFields, final ByteBuf data) { logger.trace("Control Fields: {}", ByteBufUtil.hexDump(controlFields)); controlFields = controlFields.order(ByteOrder.LITTLE_ENDIAN); final byte first = controlFields.getByte(0); if ((first & 0x01) == 0) { // I format final int sendSequenceNumber = controlFields.readUnsignedShort() >> 1; final int receiveSequenceNumber = controlFields.readUnsignedShort() >> 1; logger.debug("S: {}, R: {}", sendSequenceNumber, receiveSequenceNumber); return new InformationTransfer(sendSequenceNumber, receiveSequenceNumber, data); } else if ((first & 0x03) == 1) { // S format controlFields.skipBytes(2);/*from ww w. j a v a2 s . c o m*/ final int receiveSequenceNumber = controlFields.readUnsignedShort() >> 1; return new Supervisory(receiveSequenceNumber); } else if ((first & 0x03) == 3) { // U format final Function function = convertFunction(controlFields.readUnsignedByte()); return new UnnumberedControl(function); } // this should actually never happen throw new DecoderException("Invalid control fields"); }