Skip to content
Browse files

格式化

  • Loading branch information...
1 parent 82dbd00 commit d08ee3af83437093f33bf06c9044d63ce9f0e067 @zhaodj committed
View
2 java/demo/.classpath
@@ -4,7 +4,7 @@
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>
<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"/>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
View
11 java/demo/.settings/org.eclipse.jdt.core.prefs
@@ -1,6 +1,9 @@
-#Tue Apr 24 16:30:38 CST 2012
+#Thu Mar 14 12:42:54 CST 2013
eclipse.preferences.version=1
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
-org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
-org.eclipse.jdt.core.compiler.source=1.5
+org.eclipse.jdt.core.compiler.source=1.6
View
83 java/demo/src/main/java/org/zhaodj/util/FileHasher.java
@@ -7,56 +7,59 @@
import java.security.NoSuchAlgorithmException;
public class FileHasher {
-
- private static final char[] DIGITS = {
- '0', '1', '2', '3', '4', '5', '6', '7',
- '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
- };
-
- public static String hash(String algorithm,String filepath) throws NoSuchAlgorithmException, IOException{
- MessageDigest md=MessageDigest.getInstance(algorithm);
- InputStream is=new FileInputStream(filepath);
- int numRead=0;
- byte[] buffer=new byte[1024];
- while((numRead=is.read(buffer))>0){
- md.update(buffer, 0, numRead);
+
+ private static final char[] DIGITS = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a',
+ 'b', 'c', 'd', 'e', 'f' };
+
+ public static String hash(String algorithm, String filepath) throws NoSuchAlgorithmException,
+ IOException {
+ MessageDigest md = MessageDigest.getInstance(algorithm);
+ InputStream is = new FileInputStream(filepath);
+ try {
+ int numRead = 0;
+ byte[] buffer = new byte[1024];
+ while ((numRead = is.read(buffer)) > 0) {
+ md.update(buffer, 0, numRead);
+ }
+ } finally {
+ is.close();
}
- is.close();
return new String(encodeHex(md.digest()));
}
-
+
public static char[] encodeHex(byte[] data) {
- int l = data.length;
+ int l = data.length;
- char[] out = new char[l << 1];
+ char[] out = new char[l << 1];
- // two characters form the hex value.
- for (int i = 0, j = 0; i < l; i++) {
- out[j++] = DIGITS[(0xF0 & data[i]) >>> 4 ];
- out[j++] = DIGITS[ 0x0F & data[i] ];
- }
+ // two characters form the hex value.
+ for (int i = 0, j = 0; i < l; i++) {
+ out[j++] = DIGITS[(0xF0 & data[i]) >>> 4];
+ out[j++] = DIGITS[0x0F & data[i]];
+ }
- return out;
- }
-
- public static void test(String algorithm,String filepath,int times) throws NoSuchAlgorithmException, IOException{
- long begin=System.nanoTime();
- for(int i=0;i<times;i++){
- hash(algorithm,filepath);
+ return out;
+ }
+
+ public static void test(String algorithm, String filepath, int times)
+ throws NoSuchAlgorithmException, IOException {
+ long begin = System.nanoTime();
+ for (int i = 0; i < times; i++) {
+ hash(algorithm, filepath);
}
- System.out.println(algorithm+":"+(System.nanoTime()-begin));
+ System.out.println(algorithm + ":" + (System.nanoTime() - begin));
}
-
- public static void main(String[] args) throws NoSuchAlgorithmException, IOException{
- String file="/home/zhaodj/图片/照片/IMG_3643.JPG";
- System.out.println("file:"+file);
- test("MD5",file,1000);
- test("SHA1",file,1000);
- file="/home/zhaodj/图片/照片/ada.jpg";
- System.out.println("file:"+file);
- test("MD5",file,1000);
- test("SHA1",file,1000);
+
+ public static void main(String[] args) throws NoSuchAlgorithmException, IOException {
+ String file = "/home/zhaodj/图片/照片/IMG_3643.JPG";
+ System.out.println("file:" + file);
+ test("MD5", file, 1000);
+ test("SHA1", file, 1000);
+ file = "/home/zhaodj/图片/照片/ada.jpg";
+ System.out.println("file:" + file);
+ test("MD5", file, 1000);
+ test("SHA1", file, 1000);
}
}
View
2 java/demo/src/main/java/org/zhaodj/util/FileUtil.java
@@ -3,10 +3,8 @@
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
-import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
-import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;

0 comments on commit d08ee3a

Please sign in to comment.
Something went wrong with that request. Please try again.