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

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

15 Apr 2025 08:24AM UTC coverage: 86.955%. First build
#348

Pull #233

github

web-flow
Merge pull request #244 from kit-data-manager/renovate/commons-io-commons-io-2.x

chore(deps): update dependency commons-io:commons-io to v2.19.0
Pull Request #233: Version 2.1.0

521 of 659 new or added lines in 18 files covered. (79.06%)

1873 of 2154 relevant lines covered (86.95%)

0.87 hits per line

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

85.71
/src/main/java/edu/kit/datamanager/ro_crate/preview/StaticPreview.java
1
package edu.kit.datamanager.ro_crate.preview;
2

3
import edu.kit.datamanager.ro_crate.util.ZipUtil;
4
import java.io.File;
5
import java.io.IOException;
6
import net.lingala.zip4j.ZipFile;
7
import net.lingala.zip4j.io.outputstream.ZipOutputStream;
8
import net.lingala.zip4j.model.ZipParameters;
9
import org.apache.commons.io.FileUtils;
10

11
/**
12
 * This class adds a static preview to the crate, which consists of a
13
 * metadataHtml file and a folder containing other files required to render
14
 * metadataHtml. If will be put unchanged to the writer output, i.e., a zip
15
 * file, folder, or stream.
16
 *
17
 * @author jejkal
18
 */
19
public class StaticPreview implements CratePreview {
20

21
    private final File metadataHtml;
22
    private final File otherFiles;
23

24
    public StaticPreview(File metadataHtml, File otherFiles) {
1✔
25
        this.metadataHtml = metadataHtml;
1✔
26
        this.otherFiles = otherFiles;
1✔
27
    }
1✔
28

29
    public StaticPreview(File metadataHtml) {
1✔
30
        this.metadataHtml = metadataHtml;
1✔
31
        this.otherFiles = null;
1✔
32
    }
1✔
33

34
    @Override
35
    public void saveAllToZip(ZipFile zipFile) throws IOException {
36
        if (this.metadataHtml != null) {
1✔
37
            ZipParameters zipParameters = new ZipParameters();
1✔
38
            zipParameters.setFileNameInZip("ro-crate-preview.html");
1✔
39
            zipFile.addFile(this.metadataHtml, zipParameters);
1✔
40
        }
41

42
        if (this.otherFiles != null) {
1✔
43
            zipFile.addFolder(this.otherFiles);
1✔
44
            zipFile.renameFile(this.otherFiles.getName() + "/", "ro-crate-preview_files/");
1✔
45
        }
46
    }
1✔
47

48
    @Override
49
    public void saveAllToFolder(File folder) throws IOException {
50
        if (folder == null || !folder.exists()) {
1✔
NEW
51
            throw new IOException("Preview target folder " + folder + " does not exist.");
×
52
        }
53
        
54
        if (this.metadataHtml != null) {
1✔
55
            File fileInCrate = folder.toPath().resolve("ro-crate-preview.html").toFile();
1✔
56
            FileUtils.copyFile(this.metadataHtml, fileInCrate);
1✔
57
        }
58
        if (this.otherFiles != null) {
1✔
59
            File folderName = folder.toPath().resolve("ro-crate-preview_files").toFile();
1✔
60
            FileUtils.copyDirectory(this.otherFiles, folderName);
1✔
61
        }
62
    }
1✔
63

64
    @Override
65
    public void saveAllToStream(String metadata, ZipOutputStream stream) throws IOException {
NEW
66
        ZipUtil.addFileToZipStream(stream, this.metadataHtml, "ro-crate-preview.html");
×
NEW
67
        ZipUtil.addFolderToZipStream(stream, this.otherFiles, this.otherFiles.getName());
×
NEW
68
    }
×
69
}
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