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

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

05 May 2025 08:11AM UTC coverage: 90.169% (+0.8%) from 89.357%
#419

Pull #255

github

web-flow
Merge pull request #256 from kit-data-manager/make-spec-examples-executable

Make specification examples (from readme) executable
Pull Request #255: Next Version (v2.1.0-rc2 | v2.1.0)

63 of 70 new or added lines in 16 files covered. (90.0%)

14 existing lines in 5 files now uncovered.

1917 of 2126 relevant lines covered (90.17%)

0.9 hits per line

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

82.76
/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

7
import net.lingala.zip4j.ZipFile;
8
import net.lingala.zip4j.io.outputstream.ZipOutputStream;
9
import net.lingala.zip4j.model.ZipParameters;
10
import org.apache.commons.io.FileUtils;
11

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

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

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

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

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

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

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

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