List of usage examples for java.lang Integer toHexString
public static String toHexString(int i)
From source file:com.cloud.utils.NumbersUtil.java
/** * Converts a byte array to a hex readable string. **///w w w . j a v a 2 s . c om public static String bytesToString(byte[] data, int start, int end) { StringBuilder buf = new StringBuilder(); if (end > data.length) { end = data.length; } for (int i = start; i < end; i++) { buf.append(" "); buf.append(Integer.toHexString(data[i] & 0xff)); } return buf.toString(); }
From source file:Main.java
public static String printQuoted(String s) { /* this method quotes xml(!!) attribute values which may not contain any of the following literal chars & < " if they are enclosed in double-quotes ", if the quoting is ' then double-quotes are legal, but ' must be quoted. we assume double-quotes here though. /sr */ // pre-quote linefeeds s = quoteString(s);/*w w w .j av a2s. c o m*/ // Quote other harmful characters StringBuffer bf = new StringBuffer(); for (int i = 0, j = s.length(); i < j; ++i) { char c = s.charAt(i); switch (c) { case '&': case '<': case '"': bf.append("&#x"); //$NON-NLS-1$ bf.append(Integer.toHexString(c)); bf.append(';'); break; default: bf.append(c); } } return bf.toString(); }
From source file:com.amazonaws.mobileconnectors.pinpoint.internal.core.util.JSONBuilder.java
public JSONBuilder(Object component) { if (null != component) { this.withAttribute("class", component.getClass().getName()); this.withAttribute("hashCode", Integer.toHexString(component.hashCode())); }/*w w w . j a va 2 s .c o m*/ }
From source file:com.DPFaragir.DPFUtils.java
public static String bytesToHex(byte[] bytes) { StringBuilder sbuf = new StringBuilder(); for (int idx = 0; idx < bytes.length; idx++) { int intVal = bytes[idx] & 0xff; if (intVal < 0x10) sbuf.append("0"); sbuf.append(Integer.toHexString(intVal).toUpperCase()); }//from w ww . j a v a 2 s .c o m return sbuf.toString(); }
From source file:Uuid32Generator.java
public String generate() { StringBuilder strRetVal = new StringBuilder(); String strTemp;//from w w w . j a va2 s . co m try { // IPAddress segment InetAddress addr = InetAddress.getLocalHost(); byte[] ipaddr = addr.getAddress(); for (byte anIpaddr : ipaddr) { Byte b = new Byte(anIpaddr); strTemp = Integer.toHexString(b.intValue() & 0x000000ff); strRetVal.append(ZEROS.substring(0, 2 - strTemp.length())); strRetVal.append(strTemp); } strRetVal.append(':'); // CurrentTimeMillis() segment strTemp = Long.toHexString(System.currentTimeMillis()); strRetVal.append(ZEROS.substring(0, 12 - strTemp.length())); strRetVal.append(strTemp).append(':'); // random segment SecureRandom prng = SecureRandom.getInstance("SHA1PRNG"); strTemp = Integer.toHexString(prng.nextInt()); while (strTemp.length() < 8) { strTemp = '0' + strTemp; } strRetVal.append(strTemp.substring(4)).append(':'); // IdentityHash() segment strTemp = Long.toHexString(System.identityHashCode(this)); strRetVal.append(ZEROS.substring(0, 8 - strTemp.length())); strRetVal.append(strTemp); } catch (UnknownHostException uhex) { throw new RuntimeException("Unknown host.", uhex); } catch (NoSuchAlgorithmException nsaex) { throw new RuntimeException("Algorithm 'SHA1PRNG' is unavailiable.", nsaex); } return strRetVal.toString().toUpperCase(); }
From source file:management.limbr.test.util.FakeI18N.java
public FakeI18N add(String id) { strings.put(id, "string_" + Integer.toHexString(count++)); return this; }
From source file:Main.java
private static void ipv6toStr(StringBuilder sb, byte[] src, int fromHextet, int toHextet) { for (int i = fromHextet; i < toHextet; i++) { sb.append(Integer.toHexString(src[i << 1] << 8 & 0xff00 | src[(i << 1) + 1] & 0xff)); if (i < toHextet - 1) { sb.append(ipv6hextetSeparator); }/* www.j a v a 2 s . c o m*/ } }
From source file:com.codebutler.farebot.card.desfire.DesfireFileSettings.java
public static DesfireFileSettings Create(byte[] data) throws Exception { byte fileType = (byte) data[0]; ByteArrayInputStream stream = new ByteArrayInputStream(data); if (fileType == STANDARD_DATA_FILE || fileType == BACKUP_DATA_FILE) return new StandardDesfireFileSettings(stream); else if (fileType == LINEAR_RECORD_FILE || fileType == CYCLIC_RECORD_FILE) return new RecordDesfireFileSettings(stream); else if (fileType == VALUE_FILE) throw new UnsupportedOperationException("Value files not yet supported"); else/*from w w w. jav a 2 s .c om*/ throw new Exception("Unknown file type: " + Integer.toHexString(fileType)); }
From source file:ObjectUtils.java
/** * Return a hex String form of an object's identity hash code. * @param obj the object/* w ww.ja va 2 s. co m*/ * @return the object's identity code in hex notation */ public static String getIdentityHexString(Object obj) { return Integer.toHexString(System.identityHashCode(obj)); }
From source file:UUID.java
public String toString() { String temp1, temp2, temp3, temp4, temp; temp1 = Integer.toHexString(d1); while (temp1.length() < 8) temp1 = new String("0") + temp1; if (d2 < 0) temp2 = Integer.toHexString(d2 + 65536); else//from ww w . j av a 2 s.c o m temp2 = Integer.toHexString(d2); while (temp2.length() < 4) temp2 = new String("0") + temp2; if (d3 < 0) temp3 = Integer.toHexString(d3 + 65536); else temp3 = Integer.toHexString(d3); while (temp3.length() < 4) temp3 = new String("0") + temp3; temp = temp1 + "-" + temp2 + "-" + temp3 + "-"; for (int i = 0; i < d4.length; i++) { if (d4[i] < 0) temp4 = Integer.toHexString(d4[i] + 256); else temp4 = Integer.toHexString(d4[i]); while (temp4.length() < 2) temp4 = new String("0") + temp4; temp += temp4; } return temp; }