List of usage examples for java.lang Integer toHexString
public static String toHexString(int i)
From source file:Main.java
private static String getTwoDigitHexString(int integer) { StringBuilder sb = new StringBuilder(); sb.append(Integer.toHexString(integer)); if (sb.length() < 2) { sb.insert(0, '0'); // pad with leading zero if needed }/*from w w w . ja v a 2 s . c om*/ return sb.toString(); }
From source file:Main.java
/** * VLC only acccepts "-._~" in Mrl format, android Uri accepts "_-!.~'()*". * Therefore, encode the characters authorized by Android Uri when creating a mrl from an Uri. *//*from w ww . ja va 2 s.c o m*/ public static String encodeVLCString(@NonNull String mrl) { final char[] array = mrl.toCharArray(); final StringBuilder sb = new StringBuilder(array.length * 2); for (final char c : array) { if (URI_AUTHORIZED_CHARS.indexOf(c) != -1) sb.append("%").append(Integer.toHexString(c)); else sb.append(c); } return sb.toString(); }
From source file:Util.java
/** * Returns a hexadecimal representation of the given byte array. * /*from w ww . java2 s. com*/ * @param bytes the array to output to an hex string * @param separator the separator to use between each byte in the output * string. If null no char is inserted between each byte value. * @return the hex representation as a string */ public static String asHex(byte[] bytes, String separator) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < bytes.length; i++) { String code = Integer.toHexString(bytes[i] & 0xFF); if ((bytes[i] & 0xFF) < 16) { sb.append('0'); } sb.append(code); if (separator != null && i < bytes.length - 1) { sb.append(separator); } } return sb.toString(); }
From source file:it.gualtierotesta.gdocx.GFactory.java
/** * Convert java.awt.Color in hex string code (RRGGBB) * * @param color the color to be converted * @return a string with color hex code// w w w . j a v a 2s . c om */ public static String color2hex(@Nonnull final Color color) { Validate.notNull(color, "Color not valid"); final String rgb = Integer.toHexString(color.getRGB()); return rgb.substring(2, rgb.length()); }
From source file:Main.java
/** Calculates the MD5 hash of a given string * @author Tom V. http://m2tec.be/blog/2010/02/03/java-md5-hex-0093 * @param stringToBeHashed the string to be hashed * @return the MD5 hash as a string /*from w ww.j a v a 2 s . c o m*/ * @throws NoSuchAlgorithmException */ public static String stringToMD5(String stringToBeHashed) throws NoSuchAlgorithmException { MessageDigest messageDigest = MessageDigest.getInstance("MD5"); StringBuffer md5Hash = new StringBuffer(); byte[] array = messageDigest.digest(stringToBeHashed.getBytes()); for (int i = 0; i < array.length; i++) { md5Hash.append(Integer.toHexString((array[i] & 0xFF) | 0x100).substring(1, 3)); } return md5Hash.toString(); }
From source file:com.pfarrell.crypto.HmacUtil.java
/** * toHexes the given bytes array, and returns it. * @param buf input byte buffer// w ww .j ava2s . c o m * @return hexified result */ public static String hexify(byte[] buf) { Preconditions.checkNotNull(buf); StringBuilder sb = new StringBuilder(); for (int i = 0; i < buf.length; i++) { Byte b = new Byte(buf[i]); String s = Integer.toHexString(b.intValue()); if (s.length() == 1) s = "0" + s; if (s.length() > 2) s = s.substring(s.length() - 2); sb.append(s); } return sb.toString(); }
From source file:StringUtils.java
/** * Given an array of bytes it will convert the bytes to a hex string * representation of the bytes/*from w w w.j av a 2 s . c om*/ * @param bytes * @return hex string representation of the byte array */ public static String byteToHexString(byte bytes[]) { StringBuffer retString = new StringBuffer(); for (int i = 0; i < bytes.length; ++i) { retString.append(Integer.toHexString(0x0100 + (bytes[i] & 0x00FF)).substring(1)); } return retString.toString(); }
From source file:it.cilea.osd.jdyna.utils.HashUtil.java
public static String hashMD5(String passw) { String passwHash = ""; try {//from w w w . ja v a 2 s.c o m MessageDigest md = MessageDigest.getInstance("MD5"); md.update(passw.getBytes()); byte[] result = md.digest(); StringBuffer sb = new StringBuffer(); for (int i = 0; i < result.length; i++) { String tmpStr = "0" + Integer.toHexString((0xff & result[i])); sb.append(tmpStr.substring(tmpStr.length() - 2)); } passwHash = sb.toString(); } catch (NoSuchAlgorithmException ecc) { log.error("Errore algoritmo " + ecc); } return passwHash; }
From source file:com.eschava.forevernote.EvernoteUtil.java
public static String getHash(Resource resource) { Data data = resource.getData(); byte[] hash = data.getBodyHash(); StringBuilder builder = new StringBuilder(); for (byte b : hash) { String hex = Integer.toHexString(b < 0 ? 256 + b : b); if (hex.length() < 2) builder.append('0'); builder.append(hex);//from w w w .j a v a 2 s .c o m } return builder.toString(); }
From source file:Util.java
/** * Convert a number to a zero padded hex string * /* w w w .ja v a 2 s .com*/ * @param int number * @return zero padded hex string * @throws IllegalArgumentException * if number takes up more characters than <code>size</code> */ public static String numberToPaddedHexString(int number, int size) { String s = Integer.toHexString(number); if (s.length() > size) { throw new IllegalArgumentException("Number too big for padded hex string"); } StringBuffer buf = new StringBuffer(); for (int i = 0; i < (size - s.length()); i++) { buf.append('0'); } buf.append(s); return buf.toString(); }