1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.codehaus.plexus.archiver.zstd;
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.zstandard.ZstdCompressorInputStream;
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 @Named("zst")
39 public class ZstdUnArchiver extends AbstractUnArchiver {
40
41 private static final String OPERATION_ZSTD = "zstd";
42
43 public ZstdUnArchiver() {}
44
45 public ZstdUnArchiver(File source) {
46 super(source);
47 }
48
49 @Override
50 protected void execute() throws ArchiverException {
51 if (getSourceFile().lastModified() > getDestFile().lastModified()) {
52 getLogger()
53 .info("Expanding " + getSourceFile().getAbsolutePath() + " to "
54 + getDestFile().getAbsolutePath());
55
56 copyFully(
57 getZstdInputStream(bufferedInputStream(fileInputStream(getSourceFile(), OPERATION_ZSTD))),
58 bufferedOutputStream(fileOutputStream(getDestFile(), OPERATION_ZSTD)),
59 OPERATION_ZSTD);
60 }
61 }
62
63 public static @Nonnull ZstdCompressorInputStream getZstdInputStream(InputStream in) throws ArchiverException {
64 try {
65 return new ZstdCompressorInputStream(in);
66 } catch (IOException ioe) {
67 throw new ArchiverException("Trouble creating Zstd compressor, invalid file ?", ioe);
68 }
69 }
70
71 @Override
72 protected void execute(String path, File outputDirectory) throws ArchiverException {
73 throw new UnsupportedOperationException("Targeted execution not supported in zstd format");
74 }
75 }