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