Search in sources :

Example 1 with HexPrinter

use of org.neo4j.kernel.impl.util.HexPrinter in project neo4j by neo4j.

the class Client method beginningOfBufferAsHexString.

protected static String beginningOfBufferAsHexString(ChannelBuffer buffer, int maxBytesToPrint) {
    // read buffer from pos 0 - writeIndex
    int prevIndex = buffer.readerIndex();
    buffer.readerIndex(0);
    try {
        ByteArrayOutputStream byteArrayStream = new ByteArrayOutputStream(buffer.readableBytes());
        PrintStream stream = new PrintStream(byteArrayStream);
        HexPrinter printer = new HexPrinter(stream).withLineNumberDigits(4);
        for (int i = 0; buffer.readable() && i < maxBytesToPrint; i++) {
            printer.append(buffer.readByte());
        }
        stream.flush();
        return byteArrayStream.toString();
    } finally {
        buffer.readerIndex(prevIndex);
    }
}
Also used : PrintStream(java.io.PrintStream) HexPrinter(org.neo4j.kernel.impl.util.HexPrinter) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Aggregations

ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 PrintStream (java.io.PrintStream)1 HexPrinter (org.neo4j.kernel.impl.util.HexPrinter)1