1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.codehaus.plexus.archiver.zstd;
17
18 import javax.inject.Named;
19
20 import java.io.IOException;
21
22 import org.codehaus.plexus.archiver.AbstractArchiver;
23 import org.codehaus.plexus.archiver.ArchiveEntry;
24 import org.codehaus.plexus.archiver.ArchiverException;
25 import org.codehaus.plexus.archiver.ResourceIterator;
26 import org.codehaus.plexus.archiver.exceptions.EmptyArchiveException;
27
28
29
30
31 @Named("zst")
32 public class ZstdArchiver extends AbstractArchiver {
33
34 private final ZstdCompressor compressor = new ZstdCompressor();
35
36 public ZstdArchiver() {}
37
38
39
40
41 public void setLevel(Integer level) throws ArchiverException {
42 compressor.setLevel(level);
43 }
44
45 @Override
46 protected void execute() throws ArchiverException, IOException {
47 if (!checkForced()) {
48 return;
49 }
50
51 ResourceIterator iter = getResources();
52 if (!iter.hasNext()) {
53 throw new EmptyArchiveException("archive cannot be empty");
54 }
55 ArchiveEntry entry = iter.next();
56 if (iter.hasNext()) {
57 throw new ArchiverException("There is more than one file in input.");
58 }
59 compressor.setSource(entry.getResource());
60 compressor.setDestFile(getDestFile());
61 compressor.compress();
62 }
63
64 @Override
65 public boolean isSupportingForced() {
66 return true;
67 }
68
69 @Override
70 protected void close() throws IOException {
71 compressor.close();
72 }
73
74 @Override
75 protected String getArchiveType() {
76 return "zstd";
77 }
78 }