List of utility methods to do ByteBuffer to Hex
String | asHexString(ByteBuffer buffer) Represent as a String all the bytes (in hex format) in a ByteBuffer. final int charsPerLine = 16; StringBuilder asString = new StringBuilder(); StringBuilder currentLine = new StringBuilder(); StringBuilder all = new StringBuilder(); boolean processedFirst = false; int currentChar = 0; int length = buffer.limit(); int eobyte = 0; ... |
StringBuilder | asHexString(StringBuilder temp, ByteBuffer buffer) as Hex String int limit = buffer.limit(); for (int i = buffer.position(); i < limit; i++) temp.append( i + 1 == limit ? String.format("%02x", buffer.get(i)) : String.format("%02x ", buffer.get(i))); return temp; |
String | byteBufferToHex(ByteBuffer buffer) Returns a hexadecimal representation of the bytes written to ByteBuffer (i.e. ByteBuffer tmp = buffer.duplicate(); tmp.flip(); byte[] bytes = new byte[tmp.remaining()]; tmp.get(bytes); return bytesToHex(bytes); |
String | bytesToHex(ByteBuffer bytes) bytes To Hex char[] hexChars = new char[bytes.limit() * 2]; for (int j = 0; j < bytes.limit(); j++) { int v = bytes.get() & 0xFF; hexChars[j * 2] = hexArray[v >>> 4]; hexChars[j * 2 + 1] = hexArray[v & 0x0F]; return new String(hexChars); |
String | bytesToHex(ByteBuffer bytes) bytes To Hex StringBuilder sb = new StringBuilder(); for (int i = bytes.position() + bytes.arrayOffset(); i < bytes.limit() + bytes.arrayOffset(); i++) { int bint = bytes.array()[i] & 0xff; if (bint <= 0xF) sb.append("0"); sb.append(Integer.toHexString(bint)); return sb.toString(); ... |
String | bytesToHexString(ByteBuffer b) bytes To Hex String StringBuilder result = new StringBuilder(); for (int i = 0; i < b.remaining(); ++i) { final int v = b.array()[b.arrayOffset() + b.position() + i] & 0xff; if (i > 0) { result.append(" "); if (v < 16) { result.append("0"); ... |
StringBuffer | toHex(ByteBuffer bb) to Hex StringBuffer sb = new StringBuffer(); for (int i = 0; i < bb.limit(); i++) { sb.append(Integer.toString((bb.get(i) & 0xff) + 0x100, 16).substring(1)); return sb; |
String | toHex(ByteBuffer bb) to Hex StringBuilder sb = new StringBuilder("[ "); while (bb.hasRemaining()) { sb.append(String.format("%02X ", bb.get())); sb.append("]"); return sb.toString(); |
String | toHex(ByteBuffer buf) Interprets the bytes inside the given buffer as a hexadecimal string. int orig = buf.position(); StringBuilder sb = new StringBuilder(); while (buf.remaining() > 0) { byte b = buf.get(); sb.append(HEX_CHARS[(b & 0xF0) >>> 4]); sb.append(HEX_CHARS[b & 0x0F]); buf.position(orig); ... |
String | toHex(ByteBuffer buffer) to Hex StringBuilder result = new StringBuilder(); int pos = buffer.position(); buffer.position(0); for (int i = buffer.limit(); --i >= 0;) { byte b = buffer.get(); result.append(HEX.charAt((b >> 4) & 0xF)); result.append(HEX.charAt(b & 0xF)); result.append(' '); ... |