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 java.io.IOException;
19
20 import org.apache.commons.compress.compressors.xz.XZCompressorOutputStream;
21 import org.codehaus.plexus.archiver.ArchiverException;
22 import org.codehaus.plexus.archiver.util.Compressor;
23
24 import static org.codehaus.plexus.archiver.util.Streams.bufferedOutputStream;
25 import static org.codehaus.plexus.archiver.util.Streams.fileOutputStream;
26
27
28
29
30
31 public class XZCompressor extends Compressor {
32
33 private XZCompressorOutputStream xzOut;
34
35 public XZCompressor() {}
36
37 @Override
38 public void compress() throws ArchiverException {
39 try {
40 xzOut = new XZCompressorOutputStream(bufferedOutputStream(fileOutputStream(getDestFile())));
41 compress(getSource(), xzOut);
42 } catch (IOException ioe) {
43 throw new ArchiverException("Problem creating xz " + ioe.getMessage(), ioe);
44 }
45 }
46
47 @Override
48 public void close() {
49 try {
50 if (this.xzOut != null) {
51 this.xzOut.close();
52 xzOut = null;
53 }
54 } catch (final IOException e) {
55 throw new ArchiverException("Failure closing target.", e);
56 }
57 }
58 }