List of usage examples for java.lang Integer toString
public static String toString(int i, int radix)
From source file:Main.java
private static String hexOffset(int i) { i = (i >> 4) << 4;/* w w w.j a v a2 s . com*/ int w = i > 0xFFFF ? 8 : 4; try { return zeropad(Integer.toString(i, 16), w); } catch (Exception e) { // should not happen return e.getMessage(); } }
From source file:Main.java
/** * Format character for debugging output, which it is prefixed with "0x", padded left with '0' * and either 4 or 6 hex characters in width according to whether it is in the BMP or not. * * @param c/* ww w. j a v a 2 s .com*/ * character code * @return formatted character string */ public static String format(int c) { if (c < 1114112) { return "0x" + padLeft(Integer.toString(c, 16), (c < 65536) ? 4 : 6, '0'); } else { return "!NOT A CHARACTER!"; } }
From source file:Main.java
public static String toHexString(byte[] bytes) { if (bytes == null) { return null; }//from ww w . j a v a 2 s.c o m StringBuffer result = new StringBuffer(); for (byte b : bytes) { result.append(Integer.toString((b & 0xF0) >> 4, 16)); result.append(Integer.toString(b & 0x0F, 16)); } return result.toString(); }
From source file:Main.java
public static String checksum(String path, String algorithm) { MessageDigest md = null;/*from www.j a va2s . co m*/ try { md = MessageDigest.getInstance(algorithm); } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e); } FileInputStream i = null; try { i = new FileInputStream(path); } catch (FileNotFoundException e) { throw new RuntimeException(e); } byte[] buf = new byte[1024]; int len = 0; try { while ((len = i.read(buf)) != -1) { md.update(buf, 0, len); } } catch (IOException e) { } byte[] digest = md.digest(); // HEX StringBuilder sb = new StringBuilder(); for (byte b : digest) { sb.append(Integer.toString((b & 0xff) + 0x100, 16).substring(1)); } return sb.toString(); }
From source file:Main.java
/** * Returns a unique ID which can be used for example as the value of an * attribute of type ID./*from w ww . ja v a2 s . c o m*/ */ public static final String getUniqueId() { StringBuffer buffer = new StringBuffer(); buffer.append("___"); buffer.append(Long.toString(System.currentTimeMillis(), Character.MAX_RADIX)); buffer.append("."); buffer.append(Integer.toString(uniqueId++, Character.MAX_RADIX)); return buffer.toString(); }