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.annotation.Nonnull;
19 import javax.inject.Named;
20
21 import java.io.File;
22 import java.io.IOException;
23 import java.io.InputStream;
24
25 import org.apache.commons.compress.compressors.xz.XZCompressorInputStream;
26 import org.codehaus.plexus.archiver.AbstractUnArchiver;
27 import org.codehaus.plexus.archiver.ArchiverException;
28
29 import static org.codehaus.plexus.archiver.util.Streams.bufferedInputStream;
30 import static org.codehaus.plexus.archiver.util.Streams.bufferedOutputStream;
31 import static org.codehaus.plexus.archiver.util.Streams.copyFully;
32 import static org.codehaus.plexus.archiver.util.Streams.fileInputStream;
33 import static org.codehaus.plexus.archiver.util.Streams.fileOutputStream;
34
35
36
37
38
39 @Named("xz")
40 public class XZUnArchiver extends AbstractUnArchiver {
41
42 private static final String OPERATION_XZ = "xz";
43
44 public XZUnArchiver() {}
45
46 public XZUnArchiver(File source) {
47 super(source);
48 }
49
50 @Override
51 protected void execute() throws ArchiverException {
52 if (getSourceFile().lastModified() > getDestFile().lastModified()) {
53 getLogger()
54 .info("Expanding " + getSourceFile().getAbsolutePath() + " to "
55 + getDestFile().getAbsolutePath());
56
57 copyFully(
58 getXZInputStream(bufferedInputStream(fileInputStream(getSourceFile(), OPERATION_XZ))),
59 bufferedOutputStream(fileOutputStream(getDestFile(), OPERATION_XZ)),
60 OPERATION_XZ);
61 }
62 }
63
64 public static @Nonnull XZCompressorInputStream getXZInputStream(InputStream in) throws ArchiverException {
65 try {
66 return new XZCompressorInputStream(in);
67 } catch (IOException ioe) {
68 throw new ArchiverException("Trouble creating BZIP2 compressor, invalid file ?", ioe);
69 }
70 }
71
72 @Override
73 protected void execute(String path, File outputDirectory) throws ArchiverException {
74 throw new UnsupportedOperationException("Targeted execution not supported in xz format");
75 }
76 }