Here you can find the source of dumpNextNBytes(ByteBuffer buffer, int n)
public static void dumpNextNBytes(ByteBuffer buffer, int n)
//package com.java2s; //License from project: Open Source License import java.io.PrintWriter; import java.nio.ByteBuffer; public class Main { public static PrintWriter debugLog = null; public static void dumpNextNBytes(ByteBuffer buffer, int n) { if (!debugging()) return; int oldPosition = buffer.position(); byte[] bytesToRead = new byte[Math.min(buffer.remaining(), n)]; buffer.get(bytesToRead);/*www .jav a2s. c o m*/ log(Integer.toHexString(oldPosition) + " " + getHexString(bytesToRead)); buffer.position(oldPosition); } public static boolean debugging() { return debugLog != null; } public static void log(String line) { if (debugLog != null) debugLog.println(line); } public static String getHexString(byte[] data) { StringBuilder result = new StringBuilder(); for (byte b : data) { result.append(String.format("%02X", b)); } return result.toString(); } }