List of usage examples for java.lang Integer toHexString
public static String toHexString(int i)
From source file:de.wbuecke.codec.HexInput.java
@Override public String encode(String plaintext) { byte[] bytes = encodeBinary(plaintext); if (bytes == null) return null; StringBuilder hex = new StringBuilder(); for (int pos = 0; pos < bytes.length; pos++) hex.append(StringUtils.leftPad(Integer.toHexString(0x000000FF & bytes[pos]).toUpperCase(), 2, "0")); return hex.toString(); }
From source file:Main.java
public static String bytes2String(byte digest[]) { String str = ""; String tempStr = ""; for (int i = 0; i < digest.length; i++) { tempStr = (Integer.toHexString(digest[i] & 0xff)); if (tempStr.length() == 1) { str = str + "0" + tempStr; } else {/*www. j a v a 2 s. com*/ str += tempStr; } } return str; }
From source file:Main.java
/** * Loads an {@link Animation} object from a resource * * @param context Application context used to access resources * @param id The resource id of the animation to load * @return The animation object reference by the specified id * @throws NotFoundException when the animation cannot be loaded *//*from ww w.j a va 2 s. c o m*/ @SuppressWarnings("TryWithIdenticalCatches") public static Animation loadAnimation(Context context, int id) throws NotFoundException { XmlResourceParser parser = null; try { parser = context.getResources().getAnimation(id); return createAnimationFromXml(context, parser); } catch (XmlPullParserException ex) { NotFoundException rnf = new NotFoundException( "Can't load animation resource ID #0x" + Integer.toHexString(id)); rnf.initCause(ex); throw rnf; } catch (IOException ex) { NotFoundException rnf = new NotFoundException( "Can't load animation resource ID #0x" + Integer.toHexString(id)); rnf.initCause(ex); throw rnf; } finally { if (parser != null) parser.close(); } }
From source file:Main.java
/** * @param colorNode//from w ww . j a v a2 s .co m * @return the hex color */ public static String toHexColor(Node colorNode) { String value = "#000000"; if (colorNode == null) return value; try {// FIXME no good to grab 1st child and then node val if (colorNode.getFirstChild() == null) return value; String nodeVal = colorNode.getFirstChild().getNodeValue(); String[] components = nodeVal.split(", "); StringBuffer sb = new StringBuffer(100); sb.append("#"); for (int i = 0; i < components.length - 1; i++) { String uglyHack = Integer.toHexString(Integer.parseInt(components[i])); uglyHack = uglyHack.length() == 1 ? "0" + uglyHack : uglyHack; sb.append(uglyHack); } value = sb.toString(); } catch (Exception e) { e.printStackTrace(); } return value; }
From source file:Main.java
public static String byte2hex(byte[] b) { StringBuffer hs = new StringBuffer(b.length); String stmp = ""; int len = b.length; for (int n = 0; n < len; n++) { stmp = Integer.toHexString(b[n] & 0xFF); if (stmp.length() == 1) hs = hs.append("0").append(stmp); else {//from w w w . j a v a 2s .co m hs = hs.append(stmp); } } return String.valueOf(hs); }
From source file:Main.java
public static String getSignatureString(Signature sig, String type) { byte[] hexBytes = sig.toByteArray(); String fingerprint = "error!"; try {/*from w ww . jav a 2 s. c o m*/ MessageDigest digest = MessageDigest.getInstance(type); if (digest != null) { byte[] digestBytes = digest.digest(hexBytes); StringBuilder sb = new StringBuilder(); for (byte digestByte : digestBytes) { sb.append((Integer.toHexString((digestByte & 0xFF) | 0x100)).substring(1, 3)); } fingerprint = sb.toString(); } } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return fingerprint; }
From source file:iddb.core.util.Functions.java
public static final String maskIpAddress(String ip) { if (ip == null || ip.length() == 0) return ""; String[] parts = ip.split("\\."); Integer n = IP_SEED;/* w ww. java 2s. co m*/ n += Integer.parseInt(parts[0]); n -= Integer.parseInt(parts[1]); n += Integer.parseInt(parts[2]); n -= Integer.parseInt(parts[3]); n = Math.abs(n); return parts[0] + "." + parts[1] + "." + parts[2] + "." + Integer.toHexString(n).toUpperCase(); }
From source file:org.sglover.alfrescoextensions.common.HasherImpl.java
private String getHash(ByteBuffer bytes, int start, int end, MessageDigest digest) throws NoSuchAlgorithmException { int saveLimit = bytes.limit(); bytes.limit(end + 1);// w w w.j a v a 2s . co m bytes.mark(); bytes.position(start); digest.reset(); digest.update(bytes); byte[] array = digest.digest(); StringBuffer sb = new StringBuffer(); for (int i = 0; i < array.length; ++i) { sb.append(Integer.toHexString((array[i] & 0xFF) | 0x100).substring(1, 3)); } bytes.limit(saveLimit); bytes.reset(); return sb.toString(); }
From source file:Main.java
public static long prefixCodedToLong(final String prefixCoded) { final int shift = prefixCoded.charAt(0) - SHIFT_START_LONG; if (shift > 63 || shift < 0) throw new NumberFormatException( "Invalid shift value in prefixCoded string (is encoded value really a LONG?)"); long sortableBits = 0L; for (int i = 1, len = prefixCoded.length(); i < len; i++) { sortableBits <<= 7;//from w w w . j av a2 s . c o m final char ch = prefixCoded.charAt(i); if (ch > 0x7f) { throw new NumberFormatException("Invalid prefixCoded numerical value representation (char " + Integer.toHexString(ch) + " at position " + i + " is invalid)"); } sortableBits |= ch; } return (sortableBits << shift) ^ 0x8000000000000000L; }
From source file:Encrypt.java
private static String toHexString(byte b[]) { StringBuffer hexString = new StringBuffer(); for (int i = 0; i < b.length; i++) { String plainText = Integer.toHexString(0xff & b[i]); if (plainText.length() < 2) plainText = "0" + plainText; hexString.append(plainText);/*from ww w . j a v a 2s . c om*/ } return hexString.toString(); }