Java ByteBuffer Print printTraceHexData(PrintWriter trc, ByteBuffer buf, int startPos, int endPos)

Here you can find the source of printTraceHexData(PrintWriter trc, ByteBuffer buf, int startPos, int endPos)

Description

print Trace Hex Data

License

Open Source License

Declaration

static void printTraceHexData(PrintWriter trc, ByteBuffer buf, int startPos, int endPos) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * The MIT License (MIT)// w ww  .  j a  v  a  2  s  .c o m
 * Copyright (c) 2015 Frank Benoit, Stuttgart, Germany <keinfarbton@gmail.com>
 * 
 * See the LICENSE.md or the online documentation:
 * https://docs.google.com/document/d/1Wqa8rDi0QYcqcf0oecD8GW53nMVXj3ZFSmcF81zAa8g/edit#heading=h.2kvlhpr5zi2u
 * 
 * Contributors:
 *     Frank Benoit - initial API and implementation
 *******************************************************************************/

import java.io.PrintWriter;
import java.nio.ByteBuffer;

public class Main {
    static void printTraceHexData(PrintWriter trc, ByteBuffer buf, int startPos, int endPos) {
        int len = endPos - startPos;
        for (int i = 0; i < len; i += 16) {
            trc.printf("    ");
            for (int k = 0; k + i < len && k < 16; k++) {
                if (k > 0) {
                    trc.print(" ");
                    if (k % 4 == 0) {
                        trc.print(" ");
                    }
                }
                trc.printf("%02X", 0xFF & buf.get(i + k));
            }
            trc.printf("%n");
        }
        trc.printf("    <<%n%n");
    }
}

Related

  1. printByteBuffer(ByteBuffer buf)
  2. printData(ByteBuffer buf, int offset, int len)
  3. printData(ByteBuffer buffer, int len)
  4. printImageContentsSubset(ByteBuffer buf, int w, int h)
  5. println(String string, ByteBuffer buffer)