OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 144 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 144 Rev 177
Line 15... Line 15...
15
 
15
 
16
import java.io.File;
16
import java.io.File;
17
import java.io.FileInputStream;
17
import java.io.FileInputStream;
18
import java.io.IOException;
18
import java.io.IOException;
19
import java.io.InputStream;
19
import java.io.InputStream;
-
 
20
import java.io.OutputStream;
20
import java.security.DigestOutputStream;
21
import java.security.DigestOutputStream;
21
import java.security.MessageDigest;
22
import java.security.MessageDigest;
22
import java.security.NoSuchAlgorithmException;
23
import java.security.NoSuchAlgorithmException;
23
 
24
 
24
public class MessageDigestUtils {
25
public class MessageDigestUtils {
Line 94... Line 95...
94
        md.update(data);
95
        md.update(data);
95
        return getHashString(md);
96
        return getHashString(md);
96
    }
97
    }
97
 
98
 
98
    public static String getHashString(MessageDigest md, final InputStream ins) throws IOException {
99
    public static String getHashString(MessageDigest md, final InputStream ins) throws IOException {
99
        final DigestOutputStream out = new DigestOutputStream(StreamUtils.NULL_OS, md);
-
 
100
        StreamUtils.copy(ins, out);
-
 
101
        out.close();
-
 
102
        return getHashString(md);
100
        return asHex(getHash(md, ins));
103
    }
101
    }
104
 
102
 
-
 
103
    public static byte[] getHash(MessageDigest md, final InputStream ins) throws IOException {
-
 
104
        return getHash(md, ins, StreamUtils.NULL_OS);
-
 
105
    }
-
 
106
 
-
 
107
    public static byte[] getHash(MessageDigest md, final InputStream ins, final OutputStream out) throws IOException {
-
 
108
        try (final DigestOutputStream digestStream = new DigestOutputStream(out, md)) {
-
 
109
            StreamUtils.copy(ins, digestStream);
-
 
110
        }
-
 
111
        return md.digest();
-
 
112
    }
-
 
113
 
105
    public static String getMD5(File f) throws IOException {
114
    public static byte[] getHash(MessageDigest md, final File f) throws IOException {
106
        try (final InputStream ins = new FileInputStream(f)) {
115
        try (final InputStream ins = new FileInputStream(f)) {
107
            return getHashString(getMD5(), ins);
116
            return getHash(md, ins);
-
 
117
        }
108
        }
118
    }
-
 
119
 
-
 
120
    public static String getMD5(File f) throws IOException {
-
 
121
        return asHex(getHash(getMD5(), f));
109
    }
122
    }
110
 
123
 
111
    public static MessageDigest getMD5() {
124
    public static MessageDigest getMD5() {
112
        try {
125
        try {
113
            return MessageDigest.getInstance("MD5");
126
            return MessageDigest.getInstance("MD5");