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

wurstscript / WurstScript / 271

29 Sep 2025 12:12PM UTC coverage: 64.649% (+2.4%) from 62.222%
271

Pull #1096

circleci

Frotty
Merge branch 'perf-improvements' of https://github.com/wurstscript/WurstScript into perf-improvements
Pull Request #1096: Perf improvements

18202 of 28155 relevant lines covered (64.65%)

0.65 hits per line

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

73.33
de.peeeq.wurstscript/src/main/java/de/peeeq/wurstio/utils/FileReading.java
1
package de.peeeq.wurstio.utils;
2

3
import com.google.common.base.Charsets;
4
import de.peeeq.wurstscript.WLogger;
5
import org.mozilla.universalchardet.UniversalDetector;
6

7
import java.io.File;
8
import java.io.IOException;
9
import java.io.InputStream;
10
import java.io.Reader;
11
import java.nio.charset.Charset;
12
import java.nio.file.Files;
13

14
public class FileReading {
×
15

16
    private static final UniversalDetector detector = new UniversalDetector();
1✔
17

18
    /**
19
     * get a reader for a file
20
     */
21
    private static Reader getFileReader(File file, Charset cs) throws IOException {
22
        return Files.newBufferedReader(file.toPath(), cs);
1✔
23
    }
24

25
    /**
26
     * get a reader for a file and guess the charset using jchardet
27
     */
28
    public static Reader getFileReader(File file) throws IOException {
29
        try (InputStream fis = Files.newInputStream(file.toPath())) {
1✔
30

31
            byte[] buf = new byte[4096];
1✔
32

33
            int nread;
34
            while ((nread = fis.read(buf)) > 0 && !detector.isDone()) {
1✔
35
                detector.handleData(buf, 0, nread);
1✔
36
            }
37
            detector.dataEnd();
1✔
38

39
            String encoding = detector.getDetectedCharset();
1✔
40

41
            detector.reset();
1✔
42

43
            if (encoding == null) {
1✔
44
                WLogger.severe("Could not get encoding for " + file.getAbsolutePath());
×
45
                return getFileReader(file, Charsets.UTF_8);
×
46
            } else {
47
                return getFileReader(file, Charset.forName(encoding));
1✔
48
            }
49
        }
×
50
    }
51

52
}
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