1
2
3
4
5
6
7
8
9
10 package org.eclipse.jgit.archive;
11
12 import java.io.IOException;
13 import java.io.OutputStream;
14 import java.util.Arrays;
15 import java.util.Collections;
16 import java.util.List;
17 import java.util.Map;
18
19 import org.apache.commons.compress.archivers.ArchiveOutputStream;
20 import org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream;
21 import org.apache.commons.compress.compressors.gzip.GzipParameters;
22 import org.eclipse.jgit.api.ArchiveCommand;
23 import org.eclipse.jgit.lib.FileMode;
24 import org.eclipse.jgit.lib.ObjectId;
25 import org.eclipse.jgit.lib.ObjectLoader;
26
27
28
29
30 public final class TgzFormat extends BaseFormat implements
31 ArchiveCommand.Format<ArchiveOutputStream> {
32 private static final List<String> SUFFIXES = Collections
33 .unmodifiableList(Arrays.asList(".tar.gz", ".tgz"));
34
35 private final ArchiveCommand.Format<ArchiveOutputStream> tarFormat = new TarFormat();
36
37
38 @Override
39 public ArchiveOutputStream createArchiveOutputStream(OutputStream s)
40 throws IOException {
41 return createArchiveOutputStream(s,
42 Collections.<String, Object> emptyMap());
43 }
44
45
46 @Override
47 public ArchiveOutputStream createArchiveOutputStream(OutputStream s,
48 Map<String, Object> o) throws IOException {
49 GzipCompressorOutputStream out;
50 int compressionLevel = getCompressionLevel(o);
51 if (compressionLevel != -1) {
52 GzipParameters parameters = new GzipParameters();
53 parameters.setCompressionLevel(compressionLevel);
54 out = new GzipCompressorOutputStream(s, parameters);
55 } else {
56 out = new GzipCompressorOutputStream(s);
57 }
58 return tarFormat.createArchiveOutputStream(out, o);
59 }
60
61
62 @Override
63 public void putEntry(ArchiveOutputStream out,
64 ObjectId tree, String path, FileMode mode, ObjectLoader loader)
65 throws IOException {
66 tarFormat.putEntry(out, tree, path, mode, loader);
67 }
68
69
70 @Override
71 public Iterable<String> suffixes() {
72 return SUFFIXES;
73 }
74
75
76 @Override
77 public boolean equals(Object other) {
78 return (other instanceof TgzFormat);
79 }
80
81
82 @Override
83 public int hashCode() {
84 return getClass().hashCode();
85 }
86 }