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.xz.XZCompressorOutputStream;
21 import org.eclipse.jgit.api.ArchiveCommand;
22 import org.eclipse.jgit.lib.FileMode;
23 import org.eclipse.jgit.lib.ObjectId;
24 import org.eclipse.jgit.lib.ObjectLoader;
25
26
27
28
29 public final class TxzFormat extends BaseFormat implements
30 ArchiveCommand.Format<ArchiveOutputStream> {
31 private static final List<String> SUFFIXES = Collections
32 .unmodifiableList(Arrays.asList(".tar.xz", ".txz"));
33
34 private final ArchiveCommand.Format<ArchiveOutputStream> tarFormat = new TarFormat();
35
36
37 @Override
38 public ArchiveOutputStream createArchiveOutputStream(OutputStream s)
39 throws IOException {
40 return createArchiveOutputStream(s,
41 Collections.<String, Object> emptyMap());
42 }
43
44
45 @Override
46 public ArchiveOutputStream createArchiveOutputStream(OutputStream s,
47 Map<String, Object> o) throws IOException {
48 XZCompressorOutputStream out;
49 int compressionLevel = getCompressionLevel(o);
50 if (compressionLevel != -1) {
51 out = new XZCompressorOutputStream(s, compressionLevel);
52 } else {
53 out = new XZCompressorOutputStream(s);
54 }
55 return tarFormat.createArchiveOutputStream(out, o);
56 }
57
58
59 @Override
60 public void putEntry(ArchiveOutputStream out,
61 ObjectId tree, String path, FileMode mode, ObjectLoader loader)
62 throws IOException {
63 tarFormat.putEntry(out, tree, path, mode, loader);
64 }
65
66
67 @Override
68 public Iterable<String> suffixes() {
69 return SUFFIXES;
70 }
71
72
73 @Override
74 public boolean equals(Object other) {
75 return (other instanceof TxzFormat);
76 }
77
78
79 @Override
80 public int hashCode() {
81 return getClass().hashCode();
82 }
83 }