public static String bytesToHex(byte... bytes) { char[] c = new char[bytes.length * 2]; for (int i = 0; i < bytes.length; i++) { int byteAsInteger = bytes[i]; c[i * 2] = byteToChar[(byteAsInteger & 0xf0) >> 4]; c[1 + i * 2] = byteToChar[byteAsInteger & 0x0f]; } return wrapCharArray(c); }
@Override public String toString() { int ihc = System.identityHashCode(this); String ihcString = String.format("0x%s", Hex.bytesToHex( (byte)(ihc >>> 24 & 0x000000FF), (byte)(ihc >>> 16 & 0x000000FF), (byte)(ihc >>> 8 & 0x000000FF), (byte)(ihc & 0x000000FF))); return StringFactory.graphString(this, ihcString); }
for (String qString : queryStrings) { String queryTokens[] = qString.split("/"); StaticBuffer start = StaticArrayBuffer.of(Hex.hexToBytes(queryTokens[0])); StaticBuffer end = StaticArrayBuffer.of(Hex.hexToBytes(queryTokens[1])); SliceQuery query = new SliceQuery(start, end); int limit = Integer.valueOf(queryTokens[2]);
private static String encodeQueries(List<SliceQuery> queries) { List<String> queryStrings = new ArrayList<>(queries.size()); for (SliceQuery query : queries) { String start = Hex.bytesToHex(query.getSliceStart().as(StaticBuffer.ARRAY_FACTORY)); String end = Hex.bytesToHex(query.getSliceEnd().as(StaticBuffer.ARRAY_FACTORY)); final int limit; if (query.hasLimit()) { limit = query.getLimit(); } else { limit = -1; } queryStrings.add(String.format("%s/%s/%d", start, end, limit)); } return Joiner.on(":").join(queryStrings); }
public static String bytesToHex(ByteBuffer bytes) { final int offset = bytes.position(); final int size = bytes.remaining(); final char[] c = new char[size * 2]; for (int i = 0; i < size; i++) { final int byteAsInteger = bytes.get(i + offset); c[i * 2] = Hex.byteToChar[(byteAsInteger & 0xf0) >> 4]; c[1 + i * 2] = Hex.byteToChar[byteAsInteger & 0x0f]; } return Hex.wrapCharArray(c); }