1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.codehaus.plexus.archiver.bzip2;
18
19 import javax.annotation.Nonnull;
20 import javax.inject.Named;
21
22 import java.io.File;
23 import java.io.IOException;
24 import java.io.InputStream;
25
26 import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream;
27 import org.codehaus.plexus.archiver.AbstractUnArchiver;
28 import org.codehaus.plexus.archiver.ArchiverException;
29
30 import static org.codehaus.plexus.archiver.util.Streams.bufferedInputStream;
31 import static org.codehaus.plexus.archiver.util.Streams.bufferedOutputStream;
32 import static org.codehaus.plexus.archiver.util.Streams.copyFully;
33 import static org.codehaus.plexus.archiver.util.Streams.fileInputStream;
34 import static org.codehaus.plexus.archiver.util.Streams.fileOutputStream;
35
36
37
38
39 @Named("bzip2")
40 public class BZip2UnArchiver extends AbstractUnArchiver {
41
42 private static final String OPERATION_BZIP2 = "bzip2";
43
44 public BZip2UnArchiver() {}
45
46 public BZip2UnArchiver(File sourceFile) {
47 super(sourceFile);
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 getBZip2InputStream(bufferedInputStream(fileInputStream(getSourceFile(), OPERATION_BZIP2))),
59 bufferedOutputStream(fileOutputStream(getDestFile(), OPERATION_BZIP2)),
60 OPERATION_BZIP2);
61 }
62 }
63
64 public static @Nonnull BZip2CompressorInputStream getBZip2InputStream(InputStream bis) throws ArchiverException {
65 try {
66
67 return new BZip2CompressorInputStream(bis);
68 } catch (IOException e) {
69 throw new ArchiverException("Trouble creating BZIP2 compressor, invalid file ?", e);
70 }
71 }
72
73 @Override
74 protected void execute(String path, File outputDirectory) {
75 throw new UnsupportedOperationException("Targeted extraction not supported in BZIP2 format.");
76 }
77 }