List of usage examples for java.lang Integer toHexString
public static String toHexString(int i)
From source file:Main.java
/** * Encode a string so that it can be safely used as text in an element * for XML output./*w ww.jav a 2 s . c o m*/ * @param text the element text body. * @return a string so that it can be safely used as text in an element * for XML output. */ public static String escape(String text) { final StringBuffer sb = new StringBuffer(); if (text != null) { char c; final int l = text.length(); for (int i = 0; i < l; i++) { c = text.charAt(i); switch (c) { case '<': sb.append("<"); break; case '>': // only needed to avoid ]]> sb.append(">"); break; case '&': sb.append("&"); break; default: if (c > Byte.MAX_VALUE) { sb.append("&#x"); sb.append(Integer.toHexString(c)); sb.append(';'); } else { sb.append(c); } } } } return sb.toString(); }
From source file:Main.java
static Object[] createThreadInfo(Thread thread, Object lock, Thread lockOwner) { String lockName = null;/*from w w w. j a v a2 s.com*/ String lockOwnerName = null; if (lock != null) { lockName = lock.getClass().getName() + "@" + Integer.toHexString(System.identityHashCode(lock)); if (lockOwner != null) lockOwnerName = lockOwner.getName(); } return new Object[] { thread.getName(), thread.getState(), lockName, lockOwnerName }; }
From source file:Main.java
public static String hexEncode(byte[] data) { if (null == data) { return null; }//from w ww . ja v a 2 s .co m StringBuffer buffer = new StringBuffer(); for (int i = 0; i < data.length; i++) { String tmp = Integer.toHexString(data[i] & 0xff); if (tmp.length() < 2) { buffer.append('0'); } buffer.append(tmp); } String retStr = buffer.toString().toUpperCase(); return retStr; }
From source file:Main.java
private static String encodeHex(byte[] digest) { StringBuilder hexString = new StringBuilder(); String hex = null;//from w ww . jav a 2 s . c o m for (int i = 0; i < digest.length; i++) { hex = Integer.toHexString((digest[i] & 0xff)); if (hex.length() == 1) { hex = '0' + hex; } hexString.append(hex); } return hexString.toString(); }
From source file:Main.java
public static BitSet int2BitSet(int value, int offset) { BitSet bs = new BitSet(); String hex = Integer.toHexString(value); hex2BitSet(bs, hex.getBytes(), offset); return bs;/*from ww w . j ava 2 s.c o m*/ }
From source file:Main.java
public static String toHexs(byte[] bytes, int offset, int count, String separator) { StringBuilder s = new StringBuilder(); int end = offset + count; for (int i = offset; i < end; i++) { if (i > offset) s.append(separator);// ww w. j av a 2 s . c o m s.append(Integer.toHexString(bytes[i])); } return s.toString(); }
From source file:Main.java
public static String md5L(String input) { try {/*from ww w .j a va 2s. c o m*/ MessageDigest mdInst = MessageDigest.getInstance("MD5"); mdInst.update(input.getBytes()); byte[] md = mdInst.digest(); StringBuilder hexString = new StringBuilder(); for (byte aMd : md) { String shaHex = Integer.toHexString(aMd & 0xFF); if (shaHex.length() < 2) { hexString.append(0); } hexString.append(shaHex); } return hexString.toString(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return ""; }
From source file:Main.java
public static String asHex(byte bytes[]) { if ((bytes == null) || (bytes.length == 0)) { return ""; }//from ww w. j a v a2 s . c om StringBuffer sb = new StringBuffer(bytes.length * 2); for (int index = 0; index < bytes.length; index++) { int bt = bytes[index] & 0xff; if (bt < 0x10) { sb.append("0"); } sb.append(Integer.toHexString(bt).toUpperCase()); } return sb.toString(); }
From source file:StringUtil.java
/** * Convert an integer to an HTML RGB value. The result is of the form * #hhhhhh. The input rgb integer value will be clipped into the range 0 ~ * 0xFFFFFF//from w w w.j a va2 s.c o m * * @param rgb * the integer RGB value * @return the value as an HTML RGB string */ public static String toRgbText(int rgb) { // clip input value. if (rgb > 0xFFFFFF) rgb = 0xFFFFFF; if (rgb < 0) rgb = 0; String str = "000000" + Integer.toHexString(rgb); //$NON-NLS-1$ return "#" + str.substring(str.length() - 6); //$NON-NLS-1$ }
From source file:Util.java
/** * Creates HEX String representation of supplied byte array.<br/> * Each byte is represented by a double character element from 00 to ff * // ww w. j av a 2 s.com * @param fieldData * to be tringed * @return */ public static String toHexString(byte[] fieldData) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < fieldData.length; i++) { int v = (fieldData[i] & 0xFF); if (v <= 0xF) { sb.append("0"); } sb.append(Integer.toHexString(v)); } return sb.toString(); }