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

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

29 Apr 2025 01:00PM UTC coverage: 86.311%. First build
#378

Pull #233

github

web-flow
Merge pull request #253 from kit-data-manager/fix-renaming-of-data-set-entities

Fix renaming of data set entities
Pull Request #233: Version 2.1.0

598 of 763 new or added lines in 29 files covered. (78.37%)

1879 of 2177 relevant lines covered (86.31%)

0.86 hits per line

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

83.33
/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
    /**
17
     * Adds a folder and its contents to a ZipOutputStream.
18
     *
19
     * @param zipOutputStream The ZipOutputStream to which the folder will be added.
20
     * @param folder The folder to be added.
21
     * @param parentPath The path in the zip file where the folder will be added.
22
     * @throws IOException If an I/O error occurs.
23
     */
24
    public static void addFolderToZipStream(
25
            ZipOutputStream zipOutputStream,
26
            File folder,
27
            String parentPath
28
    ) throws IOException {
29
        if (!folder.exists() || !folder.isDirectory()) {
1✔
NEW
30
            throw new IllegalArgumentException(
×
31
                    "The provided folder path is not a valid directory: %s"
NEW
32
                            .formatted(folder.getAbsolutePath())
×
33
            );
34
        }
35

36
        File[] files = folder.listFiles();
1✔
37
        if (files == null) {
1✔
NEW
38
            return;
×
39
        }
40

41
        for (File file : files) {
1✔
42
            String zipEntryPath = parentPath.isEmpty() ? file.getName() : parentPath + "/" + file.getName();
1✔
43
            if (file.isDirectory()) {
1✔
44
                addFolderToZipStream(zipOutputStream, file.getAbsolutePath(), zipEntryPath);
1✔
45
            } else {
46
                addFileToZipStream(zipOutputStream, file, zipEntryPath);
1✔
47
            }
48
        }
49
    }
1✔
50

51
    /**
52
     * Adds a folder and its contents to a ZipOutputStream.
53
     * @param zipOutputStream The ZipOutputStream to which the folder will be added.
54
     * @param folderPath The path of the folder to be added.
55
     * @param parentPath The path in the zip file where the folder will be added.
56
     * @throws IOException If an I/O error occurs.
57
     */
58
    public static void addFolderToZipStream(
59
            ZipOutputStream zipOutputStream,
60
            String folderPath,
61
            String parentPath
62
    ) throws IOException {
63
        addFolderToZipStream(zipOutputStream, new File(folderPath), parentPath);
1✔
64
    }
1✔
65

66
    /**
67
     * Adds a file to a ZipOutputStream.
68
     *
69
     * @param zipOutputStream The ZipOutputStream to which the file will be added.
70
     * @param file The file to be added.
71
     * @param zipEntryPath The path in the zip file where the file will be added.
72
     * @throws IOException If an I/O error occurs.
73
     */
74
    public static void addFileToZipStream(
75
            ZipOutputStream zipOutputStream,
76
            File file,
77
            String zipEntryPath
78
    ) throws IOException {
79
        ZipParameters zipParameters = new ZipParameters();
1✔
80
        zipParameters.setFileNameInZip(zipEntryPath);
1✔
81
        zipOutputStream.putNextEntry(zipParameters);
1✔
82

83
        try (InputStream inputStream = new FileInputStream(file)) {
1✔
84
            byte[] buffer = new byte[4096];
1✔
85
            int len;
86
            while ((len = inputStream.read(buffer)) != -1) {
1✔
87
                zipOutputStream.write(buffer, 0, len);
1✔
88
            }
89
        }
90

91
        zipOutputStream.closeEntry();
1✔
92
    }
1✔
93
}
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