Java Code Examples for com.mysql.cj.util.StringUtils#dumpAsHex()

The following examples show how to use com.mysql.cj.util.StringUtils#dumpAsHex() . These examples are extracted from open source projects. 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
/**
 * Add a packet to the debug buffer.
 */
private void pushPacketToDebugBuffer(byte[] packet, int packetLen) {
    int bytesToDump = Math.min(this.maxPacketDumpLength, packetLen);

    String packetPayload = StringUtils.dumpAsHex(packet, bytesToDump);

    StringBuilder packetDump = new StringBuilder(DEBUG_MSG_LEN + NativeConstants.HEADER_LENGTH + packetPayload.length());

    packetDump.append("Client ");
    packetDump.append(packet.toString());
    packetDump.append("--------------------> Server\n");
    packetDump.append("\nPacket payload:\n\n");
    packetDump.append(packetPayload);

    if (packetLen > this.maxPacketDumpLength) {
        packetDump.append("\nNote: Packet of " + packetLen + " bytes truncated to " + this.maxPacketDumpLength + " bytes.\n");
    }

    if ((this.packetDebugBuffer.size() + 1) > this.packetDebugBufferSize.getValue()) {
        this.packetDebugBuffer.removeFirst();
    }

    this.packetDebugBuffer.addLast(packetDump);
}
 
Example 2
/**
 * Add a packet to the debug buffer.
 * 
 * @param packet
 *            packet as bytes
 * @param packetLen
 *            packet length
 */
private void pushPacketToDebugBuffer(byte[] packet, int packetLen) {
    int bytesToDump = Math.min(this.maxPacketDumpLength, packetLen);

    String packetPayload = StringUtils.dumpAsHex(packet, bytesToDump);

    StringBuilder packetDump = new StringBuilder(DEBUG_MSG_LEN + NativeConstants.HEADER_LENGTH + packetPayload.length());

    packetDump.append("Client ");
    packetDump.append(packet.toString());
    packetDump.append("--------------------> Server\n");
    packetDump.append("\nPacket payload:\n\n");
    packetDump.append(packetPayload);

    if (packetLen > this.maxPacketDumpLength) {
        packetDump.append("\nNote: Packet of " + packetLen + " bytes truncated to " + this.maxPacketDumpLength + " bytes.\n");
    }

    if ((this.packetDebugBuffer.size() + 1) > this.packetDebugBufferSize.getValue()) {
        this.packetDebugBuffer.removeFirst();
    }

    this.packetDebugBuffer.addLast(packetDump);
}
 
Example 3
@Override
public NativePacketHeader readHeader() throws IOException {

    byte prevPacketSeq = this.packetReader.getMessageSequence();

    NativePacketHeader hdr = this.packetReader.readHeader();

    // Normally we shouldn't get into situation of getting packets out of order from server,
    // so we do this check only in debug mode.
    byte currPacketSeq = hdr.getMessageSequence();
    if (!this.packetSequenceReset) {

        if ((currPacketSeq == -128) && (prevPacketSeq != 127)) {
            throw new IOException(Messages.getString("PacketReader.9", new Object[] { "-128", currPacketSeq }));
        }

        if ((prevPacketSeq == -1) && (currPacketSeq != 0)) {
            throw new IOException(Messages.getString("PacketReader.9", new Object[] { "-1", currPacketSeq }));
        }

        if ((currPacketSeq != -128) && (prevPacketSeq != -1) && (currPacketSeq != (prevPacketSeq + 1))) {
            throw new IOException(Messages.getString("PacketReader.9", new Object[] { (prevPacketSeq + 1), currPacketSeq }));
        }

    } else {
        this.packetSequenceReset = false;
    }

    this.lastHeaderPayload = StringUtils.dumpAsHex(hdr.getBuffer().array(), NativeConstants.HEADER_LENGTH);

    return hdr;
}
 
Example 4
@Override
public NativePacketPayload readMessage(Optional<NativePacketPayload> reuse, NativePacketHeader header) throws IOException {
    int packetLength = header.getMessageSize();
    NativePacketPayload buf = this.packetReader.readMessage(reuse, header);

    int bytesToDump = Math.min(MAX_PACKET_DUMP_LENGTH, packetLength);
    String PacketPayloadImpl = StringUtils.dumpAsHex(buf.getByteBuffer(), bytesToDump);

    StringBuilder packetDump = new StringBuilder(DEBUG_MSG_LEN + NativeConstants.HEADER_LENGTH + PacketPayloadImpl.length());
    packetDump.append("Server ");
    packetDump.append(reuse.isPresent() ? "(re-used) " : "(new) ");
    packetDump.append(buf.toString());
    packetDump.append(" --------------------> Client\n");
    packetDump.append("\nPacket payload:\n\n");
    packetDump.append(this.lastHeaderPayload);
    packetDump.append(PacketPayloadImpl);

    if (bytesToDump == MAX_PACKET_DUMP_LENGTH) {
        packetDump.append("\nNote: Packet of " + packetLength + " bytes truncated to " + MAX_PACKET_DUMP_LENGTH + " bytes.\n");
    }

    if ((this.packetDebugBuffer.size() + 1) > this.packetDebugBufferSize.getValue()) {
        this.packetDebugBuffer.removeFirst();
    }

    this.packetDebugBuffer.addLast(packetDump);

    return buf;
}
 
Example 5
@Override
public String toString() {
    int numBytes = this.position <= this.payloadLength ? this.position : this.payloadLength;
    int numBytesToDump = numBytes < MAX_BYTES_TO_DUMP ? numBytes : MAX_BYTES_TO_DUMP;

    this.position = 0;
    String dumped = StringUtils.dumpAsHex(readBytes(StringLengthDataType.STRING_FIXED, numBytesToDump), numBytesToDump);

    if (numBytesToDump < numBytes) {
        return dumped + " ....(packet exceeds max. dump length)";
    }

    return dumped;
}
 
Example 6
@Override
public NativePacketHeader readHeader() throws IOException {

    byte prevPacketSeq = this.packetReader.getMessageSequence();

    NativePacketHeader hdr = this.packetReader.readHeader();

    // Normally we shouldn't get into situation of getting packets out of order from server,
    // so we do this check only in debug mode.
    byte currPacketSeq = hdr.getMessageSequence();
    if (!this.packetSequenceReset) {

        if ((currPacketSeq == -128) && (prevPacketSeq != 127)) {
            throw new IOException(Messages.getString("PacketReader.9", new Object[] { "-128", currPacketSeq }));
        }

        if ((prevPacketSeq == -1) && (currPacketSeq != 0)) {
            throw new IOException(Messages.getString("PacketReader.9", new Object[] { "-1", currPacketSeq }));
        }

        if ((currPacketSeq != -128) && (prevPacketSeq != -1) && (currPacketSeq != (prevPacketSeq + 1))) {
            throw new IOException(Messages.getString("PacketReader.9", new Object[] { (prevPacketSeq + 1), currPacketSeq }));
        }

    } else {
        this.packetSequenceReset = false;
    }

    this.lastHeaderPayload = StringUtils.dumpAsHex(hdr.getBuffer().array(), NativeConstants.HEADER_LENGTH);

    return hdr;
}
 
Example 7
@Override
public NativePacketPayload readMessage(Optional<NativePacketPayload> reuse, NativePacketHeader header) throws IOException {
    int packetLength = header.getMessageSize();
    NativePacketPayload buf = this.packetReader.readMessage(reuse, header);

    int bytesToDump = Math.min(MAX_PACKET_DUMP_LENGTH, packetLength);
    String PacketPayloadImpl = StringUtils.dumpAsHex(buf.getByteBuffer(), bytesToDump);

    StringBuilder packetDump = new StringBuilder(DEBUG_MSG_LEN + NativeConstants.HEADER_LENGTH + PacketPayloadImpl.length());
    packetDump.append("Server ");
    packetDump.append(reuse.isPresent() ? "(re-used) " : "(new) ");
    packetDump.append(buf.toString());
    packetDump.append(" --------------------> Client\n");
    packetDump.append("\nPacket payload:\n\n");
    packetDump.append(this.lastHeaderPayload);
    packetDump.append(PacketPayloadImpl);

    if (bytesToDump == MAX_PACKET_DUMP_LENGTH) {
        packetDump.append("\nNote: Packet of " + packetLength + " bytes truncated to " + MAX_PACKET_DUMP_LENGTH + " bytes.\n");
    }

    if ((this.packetDebugBuffer.size() + 1) > this.packetDebugBufferSize.getValue()) {
        this.packetDebugBuffer.removeFirst();
    }

    this.packetDebugBuffer.addLast(packetDump);

    return buf;
}
 
Example 8
@Override
public String toString() {
    int numBytes = this.position <= this.payloadLength ? this.position : this.payloadLength;
    int numBytesToDump = numBytes < MAX_BYTES_TO_DUMP ? numBytes : MAX_BYTES_TO_DUMP;

    this.position = 0;
    String dumped = StringUtils.dumpAsHex(readBytes(StringLengthDataType.STRING_FIXED, numBytesToDump), numBytesToDump);

    if (numBytesToDump < numBytes) {
        return dumped + " ....(packet exceeds max. dump length)";
    }

    return dumped;
}