Skip to content

Commit 3b6468a

Browse files
committed
CODEC-206 Add java.io.File APIs to DigestUtils
Drop algo-specific methods in favour of generic ones git-svn-id: https://svn.apache.org/repos/asf/commons/proper/codec/trunk@1744410 13f79535-47bb-0310-9956-ffa450edef68
1 parent 55e9d25 commit 3b6468a

1 file changed

Lines changed: 1 addition & 186 deletions

File tree

src/main/java/org/apache/commons/codec/digest/DigestUtils.java

Lines changed: 1 addition & 186 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
* import static org.apache.commons.codec.digest.MessageDigestAlgorithms.SHA_224;
4747
* ...
4848
* byte [] digest = DigestUtils.digest(SHA_224, dataToDigest);
49+
* byte [] pommed = DigestUtils.digest(SHA_224, new File("pom.xml"));
4950
* </pre>
5051
* </code>
5152
* @see MessageDigestAlgorithms
@@ -358,20 +359,6 @@ public static byte[] md2(final ByteBuffer data) {
358359
return digest(getMd2Digest(), data);
359360
}
360361

361-
/**
362-
* Calculates the MD2 digest and returns the value as a 16 element <code>byte[]</code>.
363-
*
364-
* @param data
365-
* Data to digest
366-
* @return MD2 digest
367-
* @throws IOException
368-
* On error reading from the stream
369-
* @since 1.11
370-
*/
371-
public static byte[] md2(final File data) throws IOException {
372-
return digest(getMd2Digest(), data);
373-
}
374-
375362
/**
376363
* Calculates the MD2 digest and returns the value as a 16 element <code>byte[]</code>.
377364
*
@@ -422,20 +409,6 @@ public static String md2Hex(final ByteBuffer data) {
422409
return Hex.encodeHexString(md2(data));
423410
}
424411

425-
/**
426-
* Calculates the MD2 digest and returns the value as a 32 character hex string.
427-
*
428-
* @param data
429-
* Data to digest
430-
* @return MD2 digest as a hex string
431-
* @throws IOException
432-
* On error reading from the stream
433-
* @since 1.11
434-
*/
435-
public static String md2Hex(final File data) throws IOException {
436-
return Hex.encodeHexString(md2(data));
437-
}
438-
439412
/**
440413
* Calculates the MD2 digest and returns the value as a 32 character hex string.
441414
*
@@ -485,20 +458,6 @@ public static byte[] md5(final ByteBuffer data) {
485458
return digest(getMd5Digest(), data);
486459
}
487460

488-
/**
489-
* Calculates the MD5 digest and returns the value as a 16 element <code>byte[]</code>.
490-
*
491-
* @param data
492-
* Data to digest
493-
* @return MD5 digest
494-
* @throws IOException
495-
* On error reading from the stream
496-
* @since 1.11
497-
*/
498-
public static byte[] md5(final File data) throws IOException {
499-
return digest(getMd5Digest(), data);
500-
}
501-
502461
/**
503462
* Calculates the MD5 digest and returns the value as a 16 element <code>byte[]</code>.
504463
*
@@ -547,20 +506,6 @@ public static String md5Hex(final ByteBuffer data) {
547506
return Hex.encodeHexString(md5(data));
548507
}
549508

550-
/**
551-
* Calculates the MD5 digest and returns the value as a 32 character hex string.
552-
*
553-
* @param data
554-
* Data to digest
555-
* @return MD5 digest as a hex string
556-
* @throws IOException
557-
* On error reading from the stream
558-
* @since 1.11
559-
*/
560-
public static String md5Hex(final File data) throws IOException {
561-
return Hex.encodeHexString(md5(data));
562-
}
563-
564509
/**
565510
* Calculates the MD5 digest and returns the value as a 32 character hex string.
566511
*
@@ -652,20 +597,6 @@ public static byte[] sha1(final ByteBuffer data) {
652597
return digest(getSha1Digest(), data);
653598
}
654599

655-
/**
656-
* Calculates the SHA-1 digest and returns the value as a <code>byte[]</code>.
657-
*
658-
* @param data
659-
* Data to digest
660-
* @return SHA-1 digest
661-
* @throws IOException
662-
* On error reading from the stream
663-
* @since 1.11
664-
*/
665-
public static byte[] sha1(final File data) throws IOException {
666-
return digest(getSha1Digest(), data);
667-
}
668-
669600
/**
670601
* Calculates the SHA-1 digest and returns the value as a <code>byte[]</code>.
671602
*
@@ -715,20 +646,6 @@ public static String sha1Hex(final ByteBuffer data) {
715646
return Hex.encodeHexString(sha1(data));
716647
}
717648

718-
/**
719-
* Calculates the SHA-1 digest and returns the value as a hex string.
720-
*
721-
* @param data
722-
* Data to digest
723-
* @return SHA-1 digest as a hex string
724-
* @throws IOException
725-
* On error reading from the stream
726-
* @since 1.11
727-
*/
728-
public static String sha1Hex(final File data) throws IOException {
729-
return Hex.encodeHexString(sha1(data));
730-
}
731-
732649
/**
733650
* Calculates the SHA-1 digest and returns the value as a hex string.
734651
*
@@ -782,23 +699,6 @@ public static byte[] sha256(final ByteBuffer data) {
782699
return digest(getSha256Digest(), data);
783700
}
784701

785-
/**
786-
* Calculates the SHA-256 digest and returns the value as a <code>byte[]</code>.
787-
* <p>
788-
* Throws a <code>RuntimeException</code> on JRE versions prior to 1.4.0.
789-
* </p>
790-
*
791-
* @param data
792-
* File to digest
793-
* @return SHA-256 digest
794-
* @throws IOException
795-
* On error reading from the stream
796-
* @since 1.11
797-
*/
798-
public static byte[] sha256(final File data) throws IOException {
799-
return digest(getSha256Digest(), data);
800-
}
801-
802702
/**
803703
* Calculates the SHA-256 digest and returns the value as a <code>byte[]</code>.
804704
* <p>
@@ -858,23 +758,6 @@ public static String sha256Hex(final ByteBuffer data) {
858758
return Hex.encodeHexString(sha256(data));
859759
}
860760

861-
/**
862-
* Calculates the SHA-256 digest and returns the value as a hex string.
863-
* <p>
864-
* Throws a <code>RuntimeException</code> on JRE versions prior to 1.4.0.
865-
* </p>
866-
*
867-
* @param data
868-
* Data to digest
869-
* @return SHA-256 digest as a hex string
870-
* @throws IOException
871-
* On error reading from the stream
872-
* @since 1.11
873-
*/
874-
public static String sha256Hex(final File data) throws IOException {
875-
return Hex.encodeHexString(sha256(data));
876-
}
877-
878761
/**
879762
* Calculates the SHA-256 digest and returns the value as a hex string.
880763
* <p>
@@ -934,23 +817,6 @@ public static byte[] sha384(final ByteBuffer data) {
934817
return digest(getSha384Digest(), data);
935818
}
936819

937-
/**
938-
* Calculates the SHA-384 digest and returns the value as a <code>byte[]</code>.
939-
* <p>
940-
* Throws a <code>RuntimeException</code> on JRE versions prior to 1.4.0.
941-
* </p>
942-
*
943-
* @param data
944-
* File to digest
945-
* @return SHA-384 digest
946-
* @throws IOException
947-
* On error reading from the stream
948-
* @since 1.11
949-
*/
950-
public static byte[] sha384(final File data) throws IOException {
951-
return digest(getSha384Digest(), data);
952-
}
953-
954820
/**
955821
* Calculates the SHA-384 digest and returns the value as a <code>byte[]</code>.
956822
* <p>
@@ -1010,23 +876,6 @@ public static String sha384Hex(final ByteBuffer data) {
1010876
return Hex.encodeHexString(sha384(data));
1011877
}
1012878

1013-
/**
1014-
* Calculates the SHA-384 digest and returns the value as a hex string.
1015-
* <p>
1016-
* Throws a <code>RuntimeException</code> on JRE versions prior to 1.4.0.
1017-
* </p>
1018-
*
1019-
* @param data
1020-
* Data to digest
1021-
* @return SHA-384 digest as a hex string
1022-
* @throws IOException
1023-
* On error reading from the stream
1024-
* @since 1.11
1025-
*/
1026-
public static String sha384Hex(final File data) throws IOException {
1027-
return Hex.encodeHexString(sha384(data));
1028-
}
1029-
1030879
/**
1031880
* Calculates the SHA-384 digest and returns the value as a hex string.
1032881
* <p>
@@ -1086,23 +935,6 @@ public static byte[] sha512(final ByteBuffer data) {
1086935
return digest(getSha512Digest(), data);
1087936
}
1088937

1089-
/**
1090-
* Calculates the SHA-512 digest and returns the value as a <code>byte[]</code>.
1091-
* <p>
1092-
* Throws a <code>RuntimeException</code> on JRE versions prior to 1.4.0.
1093-
* </p>
1094-
*
1095-
* @param data
1096-
* File to digest
1097-
* @return SHA-512 digest
1098-
* @throws IOException
1099-
* On error reading from the stream
1100-
* @since 1.11
1101-
*/
1102-
public static byte[] sha512(final File data) throws IOException {
1103-
return digest(getSha512Digest(), data);
1104-
}
1105-
1106938
/**
1107939
* Calculates the SHA-512 digest and returns the value as a <code>byte[]</code>.
1108940
* <p>
@@ -1162,23 +994,6 @@ public static String sha512Hex(final ByteBuffer data) {
1162994
return Hex.encodeHexString(sha512(data));
1163995
}
1164996

1165-
/**
1166-
* Calculates the SHA-512 digest and returns the value as a hex string.
1167-
* <p>
1168-
* Throws a <code>RuntimeException</code> on JRE versions prior to 1.4.0.
1169-
* </p>
1170-
*
1171-
* @param data
1172-
* File to digest
1173-
* @return SHA-512 digest as a hex string
1174-
* @throws IOException
1175-
* On error reading from the stream
1176-
* @since 1.11
1177-
*/
1178-
public static String sha512Hex(File data) throws IOException {
1179-
return Hex.encodeHexString(sha512(data));
1180-
}
1181-
1182997
/**
1183998
* Calculates the SHA-512 digest and returns the value as a hex string.
1184999
* <p>

0 commit comments

Comments
 (0)