OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Rev

Rev 94 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 94 Rev 174
Line 11... Line 11...
11
 * When distributing the software, include this License Header Notice in each file.
11
 * When distributing the software, include this License Header Notice in each file.
12
 */
12
 */
13
 
13
 
14
 package org.openconcerto.utils.sync;
14
 package org.openconcerto.utils.sync;
15
 
15
 
-
 
16
import org.openconcerto.utils.MessageDigestUtils;
-
 
17
 
16
import java.io.BufferedInputStream;
18
import java.io.BufferedInputStream;
17
import java.io.BufferedOutputStream;
19
import java.io.BufferedOutputStream;
18
import java.io.DataOutputStream;
20
import java.io.DataOutputStream;
19
import java.io.File;
21
import java.io.File;
20
import java.io.FileInputStream;
22
import java.io.FileInputStream;
Line 36... Line 38...
36
            if (!outputFile.exists()) {
38
            if (!outputFile.exists()) {
37
                new File(outputFile.getParent()).mkdirs();
39
                new File(outputFile.getParent()).mkdirs();
38
            }
40
            }
39
            final DataOutputStream bOut = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(outputFile)));
41
            final DataOutputStream bOut = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(outputFile)));
40
            bOut.writeInt((int) this.in.length());
42
            bOut.writeInt((int) this.in.length());
41
            final MessageDigest hashSum = MessageDigest.getInstance("SHA-256");
43
            final MessageDigest hashSum = MessageDigestUtils.getSHA256();
42
            final MessageDigest md5 = MessageDigest.getInstance("MD5");
44
            final MessageDigest md5 = MessageDigestUtils.getMD5();
43
            fb = new BufferedInputStream(new FileInputStream(in));
45
            fb = new BufferedInputStream(new FileInputStream(in));
44
            final RollingChecksum32 r32 = new RollingChecksum32();
46
            final RollingChecksum32 r32 = new RollingChecksum32();
45
            final byte[] buffer = new byte[BLOCK_SIZE];
47
            final byte[] buffer = new byte[BLOCK_SIZE];
46
            int readSize = fb.read(buffer);
48
            int readSize = fb.read(buffer);
47
            while (readSize > 0) {
49
            while (readSize > 0) {
Line 72... Line 74...
72
                }
74
                }
73
            }
75
            }
74
        }
76
        }
75
    }
77
    }
76
 
78
 
77
    public static byte[] getHash(File f) throws Exception {
79
    public static byte[] getHash(File f) throws IOException {
78
        final MessageDigest hashSum = MessageDigest.getInstance("SHA-256");
80
        final MessageDigest hashSum = MessageDigestUtils.getSHA256();
79
        FileInputStream fIn = null;
81
        FileInputStream fIn = null;
80
        try {
82
        try {
81
            fIn = new FileInputStream(f);
83
            fIn = new FileInputStream(f);
82
            BufferedInputStream fb = null;
84
            BufferedInputStream fb = null;
83
            try {
85
            try {
Line 121... Line 123...
121
            }
123
            }
122
        }
124
        }
123
        return true;
125
        return true;
124
    }
126
    }
125
 
127
 
-
 
128
    private static final char[] hexArray = "0123456789ABCDEF".toCharArray();
-
 
129
 
-
 
130
    public static String bytesToHex(byte[] bytes) {
-
 
131
        char[] hexChars = new char[bytes.length * 2];
-
 
132
        for (int j = 0; j < bytes.length; j++) {
-
 
133
            int v = bytes[j] & 0xFF;
-
 
134
            hexChars[j * 2] = hexArray[v >>> 4];
-
 
135
            hexChars[j * 2 + 1] = hexArray[v & 0x0F];
-
 
136
        }
-
 
137
        return new String(hexChars);
-
 
138
    }
126
}
139
}