1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.codehaus.plexus.archiver.xz;
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
32 @Named("xz")
33 public class XZArchiver extends AbstractArchiver {
34
35 private final XZCompressor compressor = new XZCompressor();
36
37 public XZArchiver() {}
38
39 @Override
40 protected void execute() throws ArchiverException, IOException {
41 if (!checkForced()) {
42 return;
43 }
44
45 ResourceIterator iter = getResources();
46 if (!iter.hasNext()) {
47 throw new EmptyArchiveException("archive cannot be empty");
48 }
49 ArchiveEntry entry = iter.next();
50 if (iter.hasNext()) {
51 throw new ArchiverException("There is more than one file in input.");
52 }
53 compressor.setSource(entry.getResource());
54 compressor.setDestFile(getDestFile());
55 compressor.compress();
56 }
57
58 @Override
59 public boolean isSupportingForced() {
60 return true;
61 }
62
63 @Override
64 protected void close() throws IOException {
65 compressor.close();
66 }
67
68 @Override
69 protected String getArchiveType() {
70 return "xz";
71 }
72 }