Here you can find the source of printData(ByteBuffer buffer, int len)
public static String printData(ByteBuffer buffer, int len)
//package com.java2s; /*//from w w w. ja v a2 s . co m * This file is part of l2jserver2 <l2jserver2.com>. * * l2jserver2 is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * l2jserver2 is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with l2jserver2. If not, see <http://www.gnu.org/licenses/>. */ import java.nio.ByteBuffer; public class Main { public static String printData(ByteBuffer buffer, int len) { StringBuilder result = new StringBuilder(); int counter = 0; int length = buffer.remaining(); for (int i = 0; i < len; i++) { // if (counter % 16 == 0) { // result.append(fillHex(i, 4) + ": "); // } //result.append(fillHex(buffer.get(i) & 0xff, 2) + " "); counter++; if (counter == 16) { //result.append(" "); int charpoint = i - 15; for (int a = 0; a < 16; a++) { int t1 = buffer.get(charpoint++); if (t1 > 0x1f && t1 < 0x80) { result.append((char) t1); } else { result.append('.'); } } result.append('\n'); counter = 0; } } int rest = length % 16; if (rest > 0) { for (int i = 0; i < 17 - rest; i++) { //result.append(" "); } int charpoint = length - rest; for (int a = 0; a < rest; a++) { int t1 = buffer.get(charpoint++); if (t1 > 0x1f && t1 < 0x80) { result.append((char) t1); } else { result.append('.'); } } result.append('\n'); } return result.toString(); } }