You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2009/07/14 03:05:31 UTC
svn commit: r793772 - in
/commons/proper/codec/trunk/src/java/org/apache/commons/codec:
binary/Hex.java digest/DigestUtils.java language/Caverphone.java
language/RefinedSoundex.java language/Soundex.java
Author: ggregory
Date: Tue Jul 14 01:05:30 2009
New Revision: 793772
URL: http://svn.apache.org/viewvc?rev=793772&view=rev
Log:
Added @since 1.4 tags.
Modified:
commons/proper/codec/trunk/src/java/org/apache/commons/codec/binary/Hex.java
commons/proper/codec/trunk/src/java/org/apache/commons/codec/digest/DigestUtils.java
commons/proper/codec/trunk/src/java/org/apache/commons/codec/language/Caverphone.java
commons/proper/codec/trunk/src/java/org/apache/commons/codec/language/RefinedSoundex.java
commons/proper/codec/trunk/src/java/org/apache/commons/codec/language/Soundex.java
Modified: commons/proper/codec/trunk/src/java/org/apache/commons/codec/binary/Hex.java
URL: http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/java/org/apache/commons/codec/binary/Hex.java?rev=793772&r1=793771&r2=793772&view=diff
==============================================================================
--- commons/proper/codec/trunk/src/java/org/apache/commons/codec/binary/Hex.java (original)
+++ commons/proper/codec/trunk/src/java/org/apache/commons/codec/binary/Hex.java Tue Jul 14 01:05:30 2009
@@ -121,6 +121,7 @@
* @param toLowerCase
* <code>true</code> converts to lowercase, <code>false</code> to uppercase
* @return A char[] containing hexadecimal characters
+ * @since 1.4
*/
public static char[] encodeHex(byte[] data, boolean toLowerCase) {
return encodeHex(data, toLowerCase ? DIGITS_LOWER : DIGITS_UPPER);
@@ -136,19 +137,16 @@
* @param toDigits
* the output alphabet
* @return A char[] containing hexadecimal characters
+ * @since 1.4
*/
protected static char[] encodeHex(byte[] data, char[] toDigits) {
-
int l = data.length;
-
char[] out = new char[l << 1];
-
// two characters form the hex value.
for (int i = 0, j = 0; i < l; i++) {
out[j++] = toDigits[(0xF0 & data[i]) >>> 4];
out[j++] = toDigits[0x0F & data[i]];
}
-
return out;
}
Modified: commons/proper/codec/trunk/src/java/org/apache/commons/codec/digest/DigestUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/java/org/apache/commons/codec/digest/DigestUtils.java?rev=793772&r1=793771&r2=793772&view=diff
==============================================================================
--- commons/proper/codec/trunk/src/java/org/apache/commons/codec/digest/DigestUtils.java (original)
+++ commons/proper/codec/trunk/src/java/org/apache/commons/codec/digest/DigestUtils.java Tue Jul 14 01:05:30 2009
@@ -35,6 +35,26 @@
private static final int STREAM_BUFFER_LENGTH = 1024;
/**
+ * Read through an InputStream and returns the digest for the data
+ *
+ * @param digest The MessageDigest to use (e.g. MD5)
+ * @param data Data to digest
+ * @return MD5 digest
+ * @throws IOException On error reading from the stream
+ */
+ private static byte[] digest(MessageDigest digest, InputStream data) throws IOException {
+ byte[] buffer = new byte[STREAM_BUFFER_LENGTH];
+ int read = data.read(buffer, 0, STREAM_BUFFER_LENGTH);
+
+ while(read > -1) {
+ digest.update(buffer, 0, read);
+ read = data.read(buffer, 0, STREAM_BUFFER_LENGTH);
+ }
+
+ return digest.digest();
+ }
+
+ /**
* Returns a <code>MessageDigest</code> for the given <code>algorithm</code>.
*
* @param algorithm
@@ -118,26 +138,6 @@
private static MessageDigest getShaDigest() {
return getDigest("SHA");
}
-
- /**
- * Read through an InputStream and returns the digest for the data
- *
- * @param digest The MessageDigest to use (e.g. MD5)
- * @param data Data to digest
- * @return MD5 digest
- * @throws IOException On error reading from the stream
- */
- private static byte[] digest(MessageDigest digest, InputStream data) throws IOException {
- byte[] buffer = new byte[STREAM_BUFFER_LENGTH];
- int read = data.read(buffer, 0, STREAM_BUFFER_LENGTH);
-
- while(read > -1) {
- digest.update(buffer, 0, read);
- read = data.read(buffer, 0, STREAM_BUFFER_LENGTH);
- }
-
- return digest.digest();
- }
/**
* Calculates the MD5 digest and returns the value as a 16 element <code>byte[]</code>.
@@ -157,6 +157,7 @@
* Data to digest
* @return MD5 digest
* @throws IOException On error reading from the stream
+ * @since 1.4
*/
public static byte[] md5(InputStream data) throws IOException {
return digest(getMd5Digest(), data);
@@ -190,8 +191,10 @@
* @param data
* Data to digest
* @return MD5 digest as a hex string
+ * @throws IOException On error reading from the stream
+ * @since 1.4
*/
- public static String md5Hex(String data) {
+ public static String md5Hex(InputStream data) throws IOException {
return new String(Hex.encodeHex(md5(data)));
}
@@ -201,9 +204,8 @@
* @param data
* Data to digest
* @return MD5 digest as a hex string
- * @throws IOException On error reading from the stream
*/
- public static String md5Hex(InputStream data) throws IOException {
+ public static String md5Hex(String data) {
return new String(Hex.encodeHex(md5(data)));
}
@@ -224,9 +226,10 @@
* @param data
* Data to digest
* @return SHA-1 digest
+ * @throws IOException On error reading from the stream
*/
- public static byte[] sha(String data) {
- return sha(data.getBytes());
+ public static byte[] sha(InputStream data) throws IOException {
+ return digest(getShaDigest(), data);
}
/**
@@ -235,10 +238,9 @@
* @param data
* Data to digest
* @return SHA-1 digest
- * @throws IOException On error reading from the stream
*/
- public static byte[] sha(InputStream data) throws IOException {
- return digest(getShaDigest(), data);
+ public static byte[] sha(String data) {
+ return sha(data.getBytes());
}
/**
@@ -250,6 +252,7 @@
* @param data
* Data to digest
* @return SHA-256 digest
+ * @since 1.4
*/
public static byte[] sha256(byte[] data) {
return getSha256Digest().digest(data);
@@ -264,9 +267,11 @@
* @param data
* Data to digest
* @return SHA-256 digest
+ * @throws IOException On error reading from the stream
+ * @since 1.4
*/
- public static byte[] sha256(String data) {
- return sha256(data.getBytes());
+ public static byte[] sha256(InputStream data) throws IOException {
+ return digest(getSha256Digest(), data);
}
/**
@@ -278,10 +283,10 @@
* @param data
* Data to digest
* @return SHA-256 digest
- * @throws IOException On error reading from the stream
+ * @since 1.4
*/
- public static byte[] sha256(InputStream data) throws IOException {
- return digest(getSha256Digest(), data);
+ public static byte[] sha256(String data) {
+ return sha256(data.getBytes());
}
/**
@@ -293,6 +298,7 @@
* @param data
* Data to digest
* @return SHA-256 digest as a hex string
+ * @since 1.4
*/
public static String sha256Hex(byte[] data) {
return new String(Hex.encodeHex(sha256(data)));
@@ -307,8 +313,10 @@
* @param data
* Data to digest
* @return SHA-256 digest as a hex string
+ * @throws IOException On error reading from the stream
+ * @since 1.4
*/
- public static String sha256Hex(String data) {
+ public static String sha256Hex(InputStream data) throws IOException {
return new String(Hex.encodeHex(sha256(data)));
}
@@ -321,9 +329,9 @@
* @param data
* Data to digest
* @return SHA-256 digest as a hex string
- * @throws IOException On error reading from the stream
+ * @since 1.4
*/
- public static String sha256Hex(InputStream data) throws IOException {
+ public static String sha256Hex(String data) {
return new String(Hex.encodeHex(sha256(data)));
}
@@ -336,9 +344,9 @@
* @param data
* Data to digest
* @return SHA-384 digest
+ * @since 1.4
*/
public static byte[] sha384(byte[] data) {
- // FIXME: check Sun docs for how to get a sha 384 digest
return getSha384Digest().digest(data);
}
@@ -351,9 +359,11 @@
* @param data
* Data to digest
* @return SHA-384 digest
+ * @throws IOException On error reading from the stream
+ * @since 1.4
*/
- public static byte[] sha384(String data) {
- return sha384(data.getBytes());
+ public static byte[] sha384(InputStream data) throws IOException {
+ return digest(getSha384Digest(), data);
}
/**
@@ -365,10 +375,10 @@
* @param data
* Data to digest
* @return SHA-384 digest
- * @throws IOException On error reading from the stream
+ * @since 1.4
*/
- public static byte[] sha384(InputStream data) throws IOException {
- return digest(getSha384Digest(), data);
+ public static byte[] sha384(String data) {
+ return sha384(data.getBytes());
}
/**
@@ -380,6 +390,7 @@
* @param data
* Data to digest
* @return SHA-384 digest as a hex string
+ * @since 1.4
*/
public static String sha384Hex(byte[] data) {
return new String(Hex.encodeHex(sha384(data)));
@@ -394,8 +405,10 @@
* @param data
* Data to digest
* @return SHA-384 digest as a hex string
+ * @throws IOException On error reading from the stream
+ * @since 1.4
*/
- public static String sha384Hex(String data) {
+ public static String sha384Hex(InputStream data) throws IOException {
return new String(Hex.encodeHex(sha384(data)));
}
@@ -408,9 +421,9 @@
* @param data
* Data to digest
* @return SHA-384 digest as a hex string
- * @throws IOException On error reading from the stream
+ * @since 1.4
*/
- public static String sha384Hex(InputStream data) throws IOException {
+ public static String sha384Hex(String data) {
return new String(Hex.encodeHex(sha384(data)));
}
@@ -423,6 +436,7 @@
* @param data
* Data to digest
* @return SHA-512 digest
+ * @since 1.4
*/
public static byte[] sha512(byte[] data) {
return getSha512Digest().digest(data);
@@ -437,9 +451,11 @@
* @param data
* Data to digest
* @return SHA-512 digest
+ * @throws IOException On error reading from the stream
+ * @since 1.4
*/
- public static byte[] sha512(String data) {
- return sha512(data.getBytes());
+ public static byte[] sha512(InputStream data) throws IOException {
+ return digest(getSha512Digest(), data);
}
/**
@@ -451,10 +467,10 @@
* @param data
* Data to digest
* @return SHA-512 digest
- * @throws IOException On error reading from the stream
+ * @since 1.4
*/
- public static byte[] sha512(InputStream data) throws IOException {
- return digest(getSha512Digest(), data);
+ public static byte[] sha512(String data) {
+ return sha512(data.getBytes());
}
/**
@@ -466,6 +482,7 @@
* @param data
* Data to digest
* @return SHA-512 digest as a hex string
+ * @since 1.4
*/
public static String sha512Hex(byte[] data) {
return new String(Hex.encodeHex(sha512(data)));
@@ -480,8 +497,10 @@
* @param data
* Data to digest
* @return SHA-512 digest as a hex string
+ * @throws IOException On error reading from the stream
+ * @since 1.4
*/
- public static String sha512Hex(String data) {
+ public static String sha512Hex(InputStream data) throws IOException {
return new String(Hex.encodeHex(sha512(data)));
}
@@ -494,9 +513,9 @@
* @param data
* Data to digest
* @return SHA-512 digest as a hex string
- * @throws IOException On error reading from the stream
+ * @since 1.4
*/
- public static String sha512Hex(InputStream data) throws IOException {
+ public static String sha512Hex(String data) {
return new String(Hex.encodeHex(sha512(data)));
}
@@ -517,8 +536,9 @@
* @param data
* Data to digest
* @return SHA-1 digest as a hex string
+ * @throws IOException On error reading from the stream
*/
- public static String shaHex(String data) {
+ public static String shaHex(InputStream data) throws IOException {
return new String(Hex.encodeHex(sha(data)));
}
@@ -528,9 +548,8 @@
* @param data
* Data to digest
* @return SHA-1 digest as a hex string
- * @throws IOException On error reading from the stream
*/
- public static String shaHex(InputStream data) throws IOException {
+ public static String shaHex(String data) {
return new String(Hex.encodeHex(sha(data)));
}
}
Modified: commons/proper/codec/trunk/src/java/org/apache/commons/codec/language/Caverphone.java
URL: http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/java/org/apache/commons/codec/language/Caverphone.java?rev=793772&r1=793771&r2=793772&view=diff
==============================================================================
--- commons/proper/codec/trunk/src/java/org/apache/commons/codec/language/Caverphone.java (original)
+++ commons/proper/codec/trunk/src/java/org/apache/commons/codec/language/Caverphone.java Tue Jul 14 01:05:30 2009
@@ -21,16 +21,16 @@
import org.apache.commons.codec.StringEncoder;
/**
- * Encodes a string into a caverphone value.
- *
- * This is an algorithm created the Caversham Project at the University of Otago.
- * It implements the Caverphone 2.0 algorithm:
- *
- *
+ * Encodes a string into a Caverphone value.
+ *
+ * This is an algorithm created the Caversham Project at the University of Otago. It implements the Caverphone 2.0
+ * algorithm:
+ *
* @author Apache Software Foundation
* @version $Id$
* @see <a href="http://en.wikipedia.org/wiki/Caverphone">Wikipedia - Caverphone</a>
* @see <a href="http://caversham.otago.ac.nz/files/working/ctp150804.pdf">Caverphone 2.0 specification</a>
+ * @since 1.4
*/
public class Caverphone implements StringEncoder {
Modified: commons/proper/codec/trunk/src/java/org/apache/commons/codec/language/RefinedSoundex.java
URL: http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/java/org/apache/commons/codec/language/RefinedSoundex.java?rev=793772&r1=793771&r2=793772&view=diff
==============================================================================
--- commons/proper/codec/trunk/src/java/org/apache/commons/codec/language/RefinedSoundex.java (original)
+++ commons/proper/codec/trunk/src/java/org/apache/commons/codec/language/RefinedSoundex.java Tue Jul 14 01:05:30 2009
@@ -30,6 +30,9 @@
*/
public class RefinedSoundex implements StringEncoder {
+ /**
+ * @since 1.4
+ */
public static final String US_ENGLISH_MAPPING_STRING = "01360240043788015936020505";
/**
@@ -75,13 +78,12 @@
}
/**
- * Creates a refined soundex instance using a custom mapping. This
- * constructor can be used to customize the mapping, and/or possibly
- * provide an internationalized mapping for a non-Western character set.
+ * Creates a refined Soundex instance using a custom mapping. This constructor can be used to customize the mapping,
+ * and/or possibly provide an internationalized mapping for a non-Western character set.
*
* @param mapping
- * Mapping string to use when finding the corresponding code for
- * a given character
+ * Mapping string to use when finding the corresponding code for a given character
+ * @since 1.4
*/
public RefinedSoundex(String mapping) {
this.soundexMapping = mapping.toCharArray();
Modified: commons/proper/codec/trunk/src/java/org/apache/commons/codec/language/Soundex.java
URL: http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/java/org/apache/commons/codec/language/Soundex.java?rev=793772&r1=793771&r2=793772&view=diff
==============================================================================
--- commons/proper/codec/trunk/src/java/org/apache/commons/codec/language/Soundex.java (original)
+++ commons/proper/codec/trunk/src/java/org/apache/commons/codec/language/Soundex.java Tue Jul 14 01:05:30 2009
@@ -119,13 +119,12 @@
}
/**
- * Creates a refined soundex instance using a custom mapping. This
- * constructor can be used to customize the mapping, and/or possibly
- * provide an internationalized mapping for a non-Western character set.
+ * Creates a refined soundex instance using a custom mapping. This constructor can be used to customize the mapping,
+ * and/or possibly provide an internationalized mapping for a non-Western character set.
*
* @param mapping
- * Mapping string to use when finding the corresponding code for
- * a given character
+ * Mapping string to use when finding the corresponding code for a given character
+ * @since 1.4
*/
public Soundex(String mapping) {
this.soundexMapping = mapping.toCharArray();