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

kit-data-manager / ro-crate-java / #359

16 Apr 2025 04:37PM UTC coverage: 85.989%. First build
#359

Pull #233

github

Pfeil
fix: add null and existence checks for JSON-LD file in JsonLdExpander
Pull Request #233: Version 2.1.0

532 of 694 new or added lines in 19 files covered. (76.66%)

1878 of 2184 relevant lines covered (85.99%)

0.86 hits per line

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

82.61
/src/main/java/edu/kit/datamanager/ro_crate/util/ZipUtil.java
1
package edu.kit.datamanager.ro_crate.util;
2

3
import java.io.File;
4
import java.io.FileInputStream;
5
import java.io.IOException;
6
import java.io.InputStream;
7
import net.lingala.zip4j.io.outputstream.ZipOutputStream;
8
import net.lingala.zip4j.model.ZipParameters;
9

10
/**
11
 *
12
 * @author jejkal
13
 */
NEW
14
public class ZipUtil {
×
15

16
    public static void addFolderToZipStream(ZipOutputStream zipOutputStream, File folder, String parentPath) throws IOException {
17
        if (!folder.exists() || !folder.isDirectory()) {
1✔
NEW
18
            throw new IllegalArgumentException("The provided folder path is not a valid directory: " + folder.getAbsolutePath());
×
19
        }
20

21
        File[] files = folder.listFiles();
1✔
22
        if (files == null) {
1✔
NEW
23
            return;
×
24
        }
25

26
        for (File file : files) {
1✔
27
            String zipEntryPath = parentPath.isEmpty() ? file.getName() : parentPath + "/" + file.getName();
1✔
28
            if (file.isDirectory()) {
1✔
NEW
29
                addFolderToZipStream(zipOutputStream, file.getAbsolutePath(), zipEntryPath);
×
30
            } else {
31
                addFileToZipStream(zipOutputStream, file, zipEntryPath);
1✔
32
            }
33
        }
34
    }
1✔
35

36
    public static void addFolderToZipStream(ZipOutputStream zipOutputStream, String folderPath, String parentPath) throws IOException {
37
        addFolderToZipStream(zipOutputStream, new File(folderPath), parentPath);
1✔
38
    }
1✔
39

40
    public static void addFileToZipStream(ZipOutputStream zipOutputStream, File file, String zipEntryPath) throws IOException {
41
        ZipParameters zipParameters = new ZipParameters();
1✔
42
        zipParameters.setFileNameInZip(zipEntryPath);
1✔
43
        zipOutputStream.putNextEntry(zipParameters);
1✔
44

45
        try (InputStream inputStream = new FileInputStream(file)) {
1✔
46
            byte[] buffer = new byte[4096];
1✔
47
            int len;
48
            while ((len = inputStream.read(buffer)) != -1) {
1✔
49
                zipOutputStream.write(buffer, 0, len);
1✔
50
            }
51
        }
52

53
        zipOutputStream.closeEntry();
1✔
54
    }
1✔
55
}
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