• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

wurstscript / WurstScript / 238

04 Jan 2024 02:22PM UTC coverage: 62.412% (+0.02%) from 62.393%
238

Pull #1086

circleci

Frotty
Also allow real and boolean comparisons with null in Jass code
Pull Request #1086: Also allow real and boolean comparisons with null in Jass code

17278 of 27684 relevant lines covered (62.41%)

0.62 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
de.peeeq.wurstscript/src/main/java/de/peeeq/wurstio/Checksums.java
1
package de.peeeq.wurstio;
2

3
import de.peeeq.wurstio.utils.FileUtils;
4

5
import java.io.File;
6
import java.io.IOException;
7
import java.io.InputStream;
8
import java.security.DigestInputStream;
9
import java.security.MessageDigest;
10
import java.security.NoSuchAlgorithmException;
11
import java.util.ArrayList;
12
import java.util.List;
13

14

15
public class Checksums {
×
16

17
    public static void main(String[] args) {
18
        if (args.length != 2) {
×
19
            throw new RuntimeException("usage: 1. folder, 2. output file");
×
20
        }
21
        File dir = new File(args[0]);
×
22
        File outFile = new File(args[1]);
×
23
        List<Data> data = getData(dir);
×
24
        String out = printData(data);
×
25
        try {
26
            FileUtils.write(out, outFile);
×
27
        } catch (IOException e) {
×
28
            throw new RuntimeException(e);
×
29
        }
×
30
    }
×
31

32
    private static String printData(List<Data> data) {
33
        StringBuilder sb = new StringBuilder();
×
34
        for (Data d : data) {
×
35
            sb.append(d.filePath);
×
36
            sb.append("\n");
×
37
            sb.append(d.md5);
×
38
            sb.append("\n");
×
39
        }
×
40
        return sb.toString();
×
41
    }
42

43
    private static List<Data> getData(File f) {
44
        List<Data> result = new ArrayList<>();
×
45
        for (File p : f.listFiles()) {
×
46
            getDataRec(result, "", p);
×
47
        }
48
        return result;
×
49
    }
50

51
    private static void getDataRec(List<Data> result, String path, File f) {
52
        if (f.isDirectory()) {
×
53
            for (File p : f.listFiles()) {
×
54
                getDataRec(result, path + "/" + f.getName(), p);
×
55
            }
56
        } else {
57
            result.add(new Data(path + "/" + f.getName(), md5(f)));
×
58
        }
59
    }
×
60

61
    // stolen from http://stackoverflow.com/a/304350/303637
62
    private static String md5(File f) {
63
        try {
64
            byte[] buf = new byte[1024];
×
65
            MessageDigest md = MessageDigest.getInstance("MD5");
×
66
            try (InputStream is = java.nio.file.Files.newInputStream(f.toPath());
×
67
                 DigestInputStream dis = new DigestInputStream(is, md)) {
×
68
                while (dis.read(buf) >= 0) ;
×
69
            }
70
            byte[] digest = md.digest();
×
71
            return bytesToHex(digest);
×
72
        } catch (NoSuchAlgorithmException | IOException e) {
×
73
            throw new RuntimeException(e);
×
74
        }
75
    }
76

77
    // stolen from http://stackoverflow.com/a/9855338/303637
78
    final protected static char[] hexArray = "0123456789abcdef".toCharArray();
×
79

80
    public static String bytesToHex(byte[] bytes) {
81
        char[] hexChars = new char[bytes.length * 2];
×
82
        int v;
83
        for (int j = 0; j < bytes.length; j++) {
×
84
            v = bytes[j] & 0xFF;
×
85
            hexChars[j * 2] = hexArray[v >>> 4];
×
86
            hexChars[j * 2 + 1] = hexArray[v & 0x0F];
×
87
        }
88
        return new String(hexChars);
×
89
    }
90

91
}
92

93
class Data {
94
    final String filePath;
95
    final String md5;
96

97
    public Data(String filePath, String md5) {
×
98
        this.filePath = filePath;
×
99
        this.md5 = md5;
×
100
    }
×
101
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc