View Javadoc
1   /*
2    * Copyright (C) 2013 Google Inc. and others
3    *
4    * This program and the accompanying materials are made available under the
5    * terms of the Eclipse Distribution License v. 1.0 which is available at
6    * https://www.eclipse.org/org/documents/edl-v10.php.
7    *
8    * SPDX-License-Identifier: BSD-3-Clause
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.bzip2.BZip2CompressorOutputStream;
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   * bzip2-compressed tarball (tar.bz2) format.
28   */
29  public final class Tbz2Format extends BaseFormat implements
30  		ArchiveCommand.Format<ArchiveOutputStream> {
31  	private static final List<String> SUFFIXES = Collections
32  			.unmodifiableList(Arrays.asList(".tar.bz2", ".tbz", ".tbz2")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
33  
34  	private final ArchiveCommand.Format<ArchiveOutputStream> tarFormat = new TarFormat();
35  
36  	/** {@inheritDoc} */
37  	@Override
38  	public ArchiveOutputStream createArchiveOutputStream(OutputStream s)
39  			throws IOException {
40  		return createArchiveOutputStream(s,
41  				Collections.<String, Object> emptyMap());
42  	}
43  
44  	/** {@inheritDoc} */
45  	@Override
46  	public ArchiveOutputStream createArchiveOutputStream(OutputStream s,
47  			Map<String, Object> o) throws IOException {
48  		BZip2CompressorOutputStream out = new BZip2CompressorOutputStream(s);
49  		return tarFormat.createArchiveOutputStream(out, o);
50  	}
51  
52  	/** {@inheritDoc} */
53  	@Override
54  	public void putEntry(ArchiveOutputStream out,
55  			ObjectId tree, String path, FileMode mode, ObjectLoader loader)
56  			throws IOException {
57  		tarFormat.putEntry(out, tree, path, mode, loader);
58  	}
59  
60  	/** {@inheritDoc} */
61  	@Override
62  	public Iterable<String> suffixes() {
63  		return SUFFIXES;
64  	}
65  
66  	/** {@inheritDoc} */
67  	@Override
68  	public boolean equals(Object other) {
69  		return (other instanceof Tbz2Format);
70  	}
71  
72  	/** {@inheritDoc} */
73  	@Override
74  	public int hashCode() {
75  		return getClass().hashCode();
76  	}
77  }