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

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

01 Apr 2025 01:45PM UTC coverage: 88.589%. First build
#323

Pull #233

github

ThomasJejkal
Added zip stream writer, minor cleanup
Pull Request #233: CI trigger adjustments

34 of 82 new or added lines in 4 files covered. (41.46%)

1607 of 1814 relevant lines covered (88.59%)

0.89 hits per line

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

81.25
/src/main/java/edu/kit/datamanager/ro_crate/preview/CustomPreview.java
1
package edu.kit.datamanager.ro_crate.preview;
2

3
import java.io.File;
4
import java.io.IOException;
5
import net.lingala.zip4j.ZipFile;
6
import net.lingala.zip4j.exception.ZipException;
7
import net.lingala.zip4j.model.ZipParameters;
8
import org.apache.commons.io.FileUtils;
9

10
/**
11
 * This class represents the custom preview of a crate, which means html files
12
 * created from outside sources.
13
 *
14
 * @author Nikola Tzotchev on 12.2.2022 г.
15
 * @version 1
16
 */
17
public class CustomPreview implements CratePreview {
18

19
    private final File metadataHtml;
20
    private final File otherFiles;
21

22
    public CustomPreview(File metadataHtml, File otherFiles) {
1✔
23
        this.metadataHtml = metadataHtml;
1✔
24
        this.otherFiles = otherFiles;
1✔
25
    }
1✔
26

27
    public CustomPreview(File metadataHtml) {
1✔
28
        this.metadataHtml = metadataHtml;
1✔
29
        this.otherFiles = null;
1✔
30
    }
1✔
31

32
    @Override
33
    public void saveAllToZip(ZipFile zipFile) {
34
        if (this.metadataHtml != null) {
1✔
35
            try {
36
                ZipParameters zipParameters = new ZipParameters();
1✔
37
                zipParameters.setFileNameInZip("ro-crate-preview.html");
1✔
38
                zipFile.addFile(this.metadataHtml, zipParameters);
1✔
NEW
39
            } catch (ZipException e) {
×
NEW
40
                System.err.println("Exception writing preview html to zip");
×
41
            }
1✔
42
        }
43
        if (this.otherFiles != null) {
1✔
44
            try {
45
                zipFile.addFolder(this.otherFiles);
1✔
46
                zipFile.renameFile(this.otherFiles.getName() + "/", "ro-crate-preview_files/");
1✔
NEW
47
            } catch (ZipException e) {
×
NEW
48
                System.err.println("Exception writing preview files to zip");
×
49
            }
1✔
50
        }
51
    }
1✔
52

53
    @Override
54
    public void saveAllToFolder(File folder) {
55
        try {
56
            if (this.metadataHtml != null) {
1✔
57
                File fileInCrate = folder.toPath().resolve("ro-crate-preview.html").toFile();
1✔
58
                FileUtils.copyFile(this.metadataHtml, fileInCrate);
1✔
59
            }
60
            if (this.otherFiles != null) {
1✔
61
                File folderName = folder.toPath().resolve("ro-crate-preview_files").toFile();
1✔
62
                FileUtils.copyDirectory(this.otherFiles, folderName);
1✔
63
            }
NEW
64
        } catch (IOException e) {
×
NEW
65
            e.printStackTrace();
×
66
        }
1✔
67
    }
1✔
68
}
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

© 2026 Coveralls, Inc