src/share/classes/sun/security/pkcs11/wrapper/Functions.java
Print this page
@@ -52,11 +52,11 @@
import java.util.*;
import static sun.security.pkcs11.wrapper.PKCS11Constants.*;
/**
- * This class contains onyl static methods. It is the place for all functions
+ * This class contains only static methods. It is the place for all functions
* that are used by several classes in this package.
*
* @author Karl Scheibelhofer <Karl.Scheibelhofer@iaik.at>
* @author Martin Schlaeffer <schlaeff@sbox.tugraz.at>
*/
@@ -94,50 +94,31 @@
private static final Map<String,Integer> objectClassIds =
new HashMap<String,Integer>();
/**
- * For converting numbers to their hex presentation.
- */
- private static final char[] HEX_DIGITS = "0123456789ABCDEF".toCharArray();
-
- /**
* Converts a long value to a hexadecimal String of length 16. Includes
* leading zeros if necessary.
*
* @param value The long value to be converted.
* @return The hexadecimal string representation of the long value.
*/
public static String toFullHexString(long value) {
- long currentValue = value;
- StringBuffer stringBuffer = new StringBuffer(16);
- for(int j = 0; j < 16; j++) {
- int currentDigit = (int) currentValue & 0xf;
- stringBuffer.append(HEX_DIGITS[currentDigit]);
- currentValue >>>= 4;
- }
-
- return stringBuffer.reverse().toString();
+ return Long.toHexString(value, 16)
+ .toUpperCase();
}
/**
* Converts a int value to a hexadecimal String of length 8. Includes
* leading zeros if necessary.
*
* @param value The int value to be converted.
* @return The hexadecimal string representation of the int value.
*/
public static String toFullHexString(int value) {
- int currentValue = value;
- StringBuffer stringBuffer = new StringBuffer(8);
- for(int i = 0; i < 8; i++) {
- int currentDigit = currentValue & 0xf;
- stringBuffer.append(HEX_DIGITS[currentDigit]);
- currentValue >>>= 4;
- }
-
- return stringBuffer.reverse().toString();
+ return Integer.toHexString(value, 8)
+ .toUpperCase();
}
/**
* converts a long value to a hexadecimal String
*
@@ -159,24 +140,15 @@
public static String toHexString(byte[] value) {
if (value == null) {
return null;
}
- StringBuffer buffer = new StringBuffer(2 * value.length);
- int single;
-
- for (int i = 0; i < value.length; i++) {
- single = value[i] & 0xFF;
-
- if (single < 0x10) {
- buffer.append('0');
- }
-
- buffer.append(Integer.toString(single, 16));
+ StringBuilder sb = new StringBuilder(2 * value.length);
+ for (byte b : value) {
+ sb.append(Integer.toHexString((int)b & 0xFF, 2));
}
-
- return buffer.toString();
+ return sb.toString();
}
/**
* converts a long value to a binary String
*