Author: sebb Date: Wed May 18 13:54:59 2016 New Revision: 1744410 URL: http://svn.apache.org/viewvc?rev=1744410&view=rev Log: CODEC-206 Add java.io.File APIs to DigestUtils Drop algo-specific methods in favour of generic ones
Modified: commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/digest/DigestUtils.java Modified: commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/digest/DigestUtils.java URL: http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/digest/DigestUtils.java?rev=1744410&r1=1744409&r2=1744410&view=diff ============================================================================== --- commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/digest/DigestUtils.java (original) +++ commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/digest/DigestUtils.java Wed May 18 13:54:59 2016 @@ -46,6 +46,7 @@ import org.apache.commons.codec.binary.S * import static org.apache.commons.codec.digest.MessageDigestAlgorithms.SHA_224; * ... * byte [] digest = DigestUtils.digest(SHA_224, dataToDigest); + * byte [] pommed = DigestUtils.digest(SHA_224, new File("pom.xml")); * </pre> * </code> * @see MessageDigestAlgorithms @@ -366,20 +367,6 @@ public class DigestUtils { * @return MD2 digest * @throws IOException * On error reading from the stream - * @since 1.11 - */ - public static byte[] md2(final File data) throws IOException { - return digest(getMd2Digest(), data); - } - - /** - * Calculates the MD2 digest and returns the value as a 16 element <code>byte[]</code>. - * - * @param data - * Data to digest - * @return MD2 digest - * @throws IOException - * On error reading from the stream * @since 1.7 */ public static byte[] md2(final InputStream data) throws IOException { @@ -430,20 +417,6 @@ public class DigestUtils { * @return MD2 digest as a hex string * @throws IOException * On error reading from the stream - * @since 1.11 - */ - public static String md2Hex(final File data) throws IOException { - return Hex.encodeHexString(md2(data)); - } - - /** - * Calculates the MD2 digest and returns the value as a 32 character hex string. - * - * @param data - * Data to digest - * @return MD2 digest as a hex string - * @throws IOException - * On error reading from the stream * @since 1.7 */ public static String md2Hex(final InputStream data) throws IOException { @@ -493,20 +466,6 @@ public class DigestUtils { * @return MD5 digest * @throws IOException * On error reading from the stream - * @since 1.11 - */ - public static byte[] md5(final File data) throws IOException { - return digest(getMd5Digest(), data); - } - - /** - * Calculates the MD5 digest and returns the value as a 16 element <code>byte[]</code>. - * - * @param data - * Data to digest - * @return MD5 digest - * @throws IOException - * On error reading from the stream * @since 1.4 */ public static byte[] md5(final InputStream data) throws IOException { @@ -555,20 +514,6 @@ public class DigestUtils { * @return MD5 digest as a hex string * @throws IOException * On error reading from the stream - * @since 1.11 - */ - public static String md5Hex(final File data) throws IOException { - return Hex.encodeHexString(md5(data)); - } - - /** - * Calculates the MD5 digest and returns the value as a 32 character hex string. - * - * @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(final InputStream data) throws IOException { @@ -660,20 +605,6 @@ public static byte[] sha(final byte[] da * @return SHA-1 digest * @throws IOException * On error reading from the stream - * @since 1.11 - */ - public static byte[] sha1(final File data) throws IOException { - return digest(getSha1Digest(), data); - } - - /** - * Calculates the SHA-1 digest and returns the value as a <code>byte[]</code>. - * - * @param data - * Data to digest - * @return SHA-1 digest - * @throws IOException - * On error reading from the stream * @since 1.7 */ public static byte[] sha1(final InputStream data) throws IOException { @@ -723,20 +654,6 @@ public static byte[] sha(final byte[] da * @return SHA-1 digest as a hex string * @throws IOException * On error reading from the stream - * @since 1.11 - */ - public static String sha1Hex(final File data) throws IOException { - return Hex.encodeHexString(sha1(data)); - } - - /** - * Calculates the SHA-1 digest and returns the value as a hex string. - * - * @param data - * Data to digest - * @return SHA-1 digest as a hex string - * @throws IOException - * On error reading from the stream * @since 1.7 */ public static String sha1Hex(final InputStream data) throws IOException { @@ -789,23 +706,6 @@ public static byte[] sha(final byte[] da * </p> * * @param data - * File to digest - * @return SHA-256 digest - * @throws IOException - * On error reading from the stream - * @since 1.11 - */ - public static byte[] sha256(final File data) throws IOException { - return digest(getSha256Digest(), data); - } - - /** - * Calculates the SHA-256 digest and returns the value as a <code>byte[]</code>. - * <p> - * Throws a <code>RuntimeException</code> on JRE versions prior to 1.4.0. - * </p> - * - * @param data * Data to digest * @return SHA-256 digest * @throws IOException @@ -869,23 +769,6 @@ public static byte[] sha(final byte[] da * @return SHA-256 digest as a hex string * @throws IOException * On error reading from the stream - * @since 1.11 - */ - public static String sha256Hex(final File data) throws IOException { - return Hex.encodeHexString(sha256(data)); - } - - /** - * Calculates the SHA-256 digest and returns the value as a hex string. - * <p> - * Throws a <code>RuntimeException</code> on JRE versions prior to 1.4.0. - * </p> - * - * @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(final InputStream data) throws IOException { @@ -941,23 +824,6 @@ public static byte[] sha(final byte[] da * </p> * * @param data - * File to digest - * @return SHA-384 digest - * @throws IOException - * On error reading from the stream - * @since 1.11 - */ - public static byte[] sha384(final File data) throws IOException { - return digest(getSha384Digest(), data); - } - - /** - * Calculates the SHA-384 digest and returns the value as a <code>byte[]</code>. - * <p> - * Throws a <code>RuntimeException</code> on JRE versions prior to 1.4.0. - * </p> - * - * @param data * Data to digest * @return SHA-384 digest * @throws IOException @@ -1021,23 +887,6 @@ public static byte[] sha(final byte[] da * @return SHA-384 digest as a hex string * @throws IOException * On error reading from the stream - * @since 1.11 - */ - public static String sha384Hex(final File data) throws IOException { - return Hex.encodeHexString(sha384(data)); - } - - /** - * Calculates the SHA-384 digest and returns the value as a hex string. - * <p> - * Throws a <code>RuntimeException</code> on JRE versions prior to 1.4.0. - * </p> - * - * @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(final InputStream data) throws IOException { @@ -1093,23 +942,6 @@ public static byte[] sha(final byte[] da * </p> * * @param data - * File to digest - * @return SHA-512 digest - * @throws IOException - * On error reading from the stream - * @since 1.11 - */ - public static byte[] sha512(final File data) throws IOException { - return digest(getSha512Digest(), data); - } - - /** - * Calculates the SHA-512 digest and returns the value as a <code>byte[]</code>. - * <p> - * Throws a <code>RuntimeException</code> on JRE versions prior to 1.4.0. - * </p> - * - * @param data * Data to digest * @return SHA-512 digest * @throws IOException @@ -1162,23 +994,6 @@ public static byte[] sha(final byte[] da return Hex.encodeHexString(sha512(data)); } - /** - * Calculates the SHA-512 digest and returns the value as a hex string. - * <p> - * Throws a <code>RuntimeException</code> on JRE versions prior to 1.4.0. - * </p> - * - * @param data - * File to digest - * @return SHA-512 digest as a hex string - * @throws IOException - * On error reading from the stream - * @since 1.11 - */ - public static String sha512Hex(File data) throws IOException { - return Hex.encodeHexString(sha512(data)); - } - /** * Calculates the SHA-512 digest and returns the value as a hex string. * <p>