Example usage for java.lang Integer toHexString

List of usage examples for java.lang Integer toHexString

Introduction

In this page you can find the example usage for java.lang Integer toHexString.

Prototype

public static String toHexString(int i) 

Source Link

Document

Returns a string representation of the integer argument as an unsigned integer in base 16.

Usage

From source file:com.mnt.base.util.HashUtil.java

public static String toHexString(byte[] data) {
    StringBuilder sb = new StringBuilder(data.length * 2);

    for (int i = 0; i < data.length; i++) {
        sb.append(DIGITS[(data[i] & 0xf0) >>> 4]);
        sb.append(DIGITS[data[i] & 0x0f]);
    }/*  w  w w  .  j  a va2 s .c  o m*/

    Integer.toHexString(1);

    return sb.toString();
}

From source file:jef.testbase.JefTester.java

static String hexByte(byte b) {
    String s = "000000" + Integer.toHexString(b);
    return s.substring(s.length() - 2);
}

From source file:Main.java

/**
 * Format a string buffer containing the Class, Interfaces, CodeSource, and
 * ClassLoader information for the given object clazz.
 * /*from  w w w .j  a v a  2 s.c om*/
 * @param clazz
 *          the Class
 * @param results -
 *          the buffer to write the info to
 */
public static void displayClassInfo(Class clazz, StringBuffer results) {
    // Print out some codebase info for the clazz
    ClassLoader cl = clazz.getClassLoader();
    results.append("\n");
    results.append(clazz.getName());
    results.append("(");
    results.append(Integer.toHexString(clazz.hashCode()));
    results.append(").ClassLoader=");
    results.append(cl);
    ClassLoader parent = cl;
    while (parent != null) {
        results.append("\n..");
        results.append(parent);
        URL[] urls = getClassLoaderURLs(parent);
        int length = urls != null ? urls.length : 0;
        for (int u = 0; u < length; u++) {
            results.append("\n....");
            results.append(urls[u]);
        }
        if (parent != null)
            parent = parent.getParent();
    }
    CodeSource clazzCS = clazz.getProtectionDomain().getCodeSource();
    if (clazzCS != null) {
        results.append("\n++++CodeSource: ");
        results.append(clazzCS);
    } else
        results.append("\n++++Null CodeSource");

    results.append("\nImplemented Interfaces:");
    Class[] ifaces = clazz.getInterfaces();
    for (int i = 0; i < ifaces.length; i++) {
        Class iface = ifaces[i];
        results.append("\n++");
        results.append(iface);
        results.append("(");
        results.append(Integer.toHexString(iface.hashCode()));
        results.append(")");
        ClassLoader loader = ifaces[i].getClassLoader();
        results.append("\n++++ClassLoader: ");
        results.append(loader);
        ProtectionDomain pd = ifaces[i].getProtectionDomain();
        CodeSource cs = pd.getCodeSource();
        if (cs != null) {
            results.append("\n++++CodeSource: ");
            results.append(cs);
        } else
            results.append("\n++++Null CodeSource");
    }
}

From source file:Main.java

/**
 *  This method encodes a String so that it is a valid XML name, according
 *  to ISO/IEC 9075-14:2003.  Whether a character is considered an XML name
 *  character, please see {@link XMLUtils#isXMLNameChar(int)}.
 *  /*w  w  w  .  ja  v a 2  s .  co m*/
 *  @param src The source string to encode.
 *  @return An encoded string.
 */
public static String encode(String src) {
    StringBuilder sb = new StringBuilder();

    for (int i = 0; i < src.length(); i++) {
        int ch = src.charAt(i);

        if (!isXMLNameChar(ch) || (ch == '_' && i < src.length() - 5 && src.charAt(i + 1) == 'x'
                && (VALID_HEX_CHARS.indexOf(src.charAt(i + 2)) != -1)
                && (VALID_HEX_CHARS.indexOf(src.charAt(i + 3)) != -1)
                && (VALID_HEX_CHARS.indexOf(src.charAt(i + 4)) != -1)
                && (VALID_HEX_CHARS.indexOf(src.charAt(i + 5)) != -1))) {
            sb.append("_x");
            String s = Integer.toHexString(ch);
            for (int j = 0; j < 4 - s.length(); j++)
                sb.append('0');
            sb.append(s);
            sb.append('_');
        } else {
            sb.append((char) ch);
        }
    }

    return sb.toString();
}

From source file:com.apabi.r2k.common.security.util.NonceUtils.java

/**
 * SecureRandom?Integer,?8Hex?.
 */
public static String randomHexInt() {
    return Integer.toHexString(randomInt());
}

From source file:ch.rasc.s4ws.snake.SnakeWebSocketHandler.java

public static String getRandomHexColor() {
    float hue = random.nextFloat();
    // sat between 0.1 and 0.3
    float saturation = (random.nextInt(2000) + 1000) / 10000f;
    float luminance = 0.9f;
    Color color = Color.getHSBColor(hue, saturation, luminance);
    return '#' + Integer.toHexString(color.getRGB() & 0xffffff | 0x1000000).substring(1);
}

From source file:com.gmind7.bakery.websocket.SnakeWebSocketHandler.java

public static String getRandomHexColor() {
    float hue = random.nextFloat();
    // sat between 0.1 and 0.3
    float saturation = (random.nextInt(2000) + 1000) / 10000f;
    float luminance = 0.9f;
    Color color = Color.getHSBColor(hue, saturation, luminance);
    return '#' + Integer.toHexString((color.getRGB() & 0xffffff) | 0x1000000).substring(1);
}

From source file:io.wcm.devops.conga.plugins.aem.crypto.CryptoString.java

/**
 * Converts byte array to hex string enclosed in curly braces.
 * @param data Binary data/*from   ww  w .  j  ava 2s.  com*/
 * @return Binary data string
 */
public static String toString(byte[] data) {
    if (data == null || data.length == 0) {
        throw new IllegalArgumentException("Data is null or empty.");
    }
    StringBuilder text = new StringBuilder(data.length * 2 + 2);
    text.append("{");
    for (int i = 0; i < data.length; i++) {
        String hex = Integer.toHexString(data[i] & 0xff);
        if (hex.length() < 2) {
            text.append("0");
        }
        text.append(hex);
    }
    text.append("}");
    return text.toString();
}

From source file:com.agiletec.plugins.jpnewsletter.aps.system.services.newsletter.util.ShaEncoder.java

public static String encodeWord(String word) throws NoSuchAlgorithmException {
    if (word != null) {
        MessageDigest digest = MessageDigest.getInstance("SHA");
        digest.update(word.getBytes());/*from   ww w. j av  a  2s  . c  o m*/
        byte bytes[] = digest.digest();
        StringBuilder buffer = new StringBuilder();
        for (int i = 0; i < bytes.length; i++) {
            int b = bytes[i] & 0xff;
            if (b < 16) {
                buffer.append("0");
            }
            buffer.append(Integer.toHexString(b));
        }
        word = buffer.toString();
    }
    return word;
}

From source file:fi.jumi.core.ipc.encoding.StringEncodingTest.java

@Test
public void test_serialization_of_String_with_non_printable_characters() {
    for (char c = 0; c < ' '; c++) {
        String original = "" + c;
        assertThat("0x" + Integer.toHexString(c), roundTripString(original), is(original));
    }//  w w w  .j  av a 2s.  c om
}