mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-27 00:32:07 +01:00
New encodeHex.
git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@2720 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
parent
29159b831c
commit
0c848916b7
1 changed files with 12 additions and 17 deletions
|
@ -134,7 +134,7 @@ public class StringUtils {
|
||||||
* @param string the string to escape.
|
* @param string the string to escape.
|
||||||
* @return the string with appropriate characters escaped.
|
* @return the string with appropriate characters escaped.
|
||||||
*/
|
*/
|
||||||
public static final String escapeForXML(String string) {
|
public static String escapeForXML(String string) {
|
||||||
if (string == null) {
|
if (string == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -217,7 +217,7 @@ public class StringUtils {
|
||||||
* @param data the String to compute the hash of.
|
* @param data the String to compute the hash of.
|
||||||
* @return a hashed version of the passed-in String
|
* @return a hashed version of the passed-in String
|
||||||
*/
|
*/
|
||||||
public synchronized static final String hash(String data) {
|
public synchronized static String hash(String data) {
|
||||||
if (digest == null) {
|
if (digest == null) {
|
||||||
try {
|
try {
|
||||||
digest = MessageDigest.getInstance("SHA-1");
|
digest = MessageDigest.getInstance("SHA-1");
|
||||||
|
@ -238,27 +238,22 @@ public class StringUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Turns an array of bytes into a String representing each byte as an
|
* Encodes an array of bytes as String representation of hexadecimal.
|
||||||
* unsigned hex number.
|
|
||||||
* <p>
|
|
||||||
* Method by Santeri Paavolainen, Helsinki Finland 1996<br>
|
|
||||||
* (c) Santeri Paavolainen, Helsinki Finland 1996<br>
|
|
||||||
* Distributed under LGPL.
|
|
||||||
*
|
*
|
||||||
* @param bytes an array of bytes to convert to a hex-string
|
* @param bytes an array of bytes to convert to a hex string.
|
||||||
* @return generated hex string
|
* @return generated hex string.
|
||||||
*/
|
*/
|
||||||
public static final String encodeHex(byte[] bytes) {
|
public static String encodeHex(byte[] bytes) {
|
||||||
StringBuffer buf = new StringBuffer(bytes.length * 2);
|
StringBuffer hex = new StringBuffer(bytes.length * 2);
|
||||||
int i;
|
|
||||||
|
|
||||||
for (i = 0; i < bytes.length; i++) {
|
for (int i=0; i<bytes.length; i++) {
|
||||||
if (((int) bytes[i] & 0xff) < 0x10) {
|
if (((int) bytes[i] & 0xff) < 0x10) {
|
||||||
buf.append("0");
|
hex.append("0");
|
||||||
}
|
}
|
||||||
buf.append(Long.toString((int) bytes[i] & 0xff, 16));
|
hex.append(Integer.toString((int) bytes[i] & 0xff, 16));
|
||||||
}
|
}
|
||||||
return buf.toString();
|
|
||||||
|
return hex.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
//*********************************************************************
|
//*********************************************************************
|
||||||
|
|
Loading…
Reference in a new issue