xref: /JGit/org.eclipse.jgit.archive/src/org/eclipse/jgit/archive/Tbz2Format.java (revision 6f82690aaf2be783be6d77f0903788ff0832472a)
1ed5199f6SJonathan Nieder /*
25c5f7c6bSMatthias Sohn  * Copyright (C) 2013 Google Inc. and others
3ed5199f6SJonathan Nieder  *
45c5f7c6bSMatthias Sohn  * This program and the accompanying materials are made available under the
55c5f7c6bSMatthias Sohn  * terms of the Eclipse Distribution License v. 1.0 which is available at
65c5f7c6bSMatthias Sohn  * https://www.eclipse.org/org/documents/edl-v10.php.
7ed5199f6SJonathan Nieder  *
85c5f7c6bSMatthias Sohn  * SPDX-License-Identifier: BSD-3-Clause
9ed5199f6SJonathan Nieder  */
10ed5199f6SJonathan Nieder package org.eclipse.jgit.archive;
11ed5199f6SJonathan Nieder 
12ed5199f6SJonathan Nieder import java.io.IOException;
13ed5199f6SJonathan Nieder import java.io.OutputStream;
1456cb2d92SJonathan Nieder import java.util.Arrays;
1556cb2d92SJonathan Nieder import java.util.Collections;
1656cb2d92SJonathan Nieder import java.util.List;
17c0c4c6f0SDavid Ostrovsky import java.util.Map;
18ed5199f6SJonathan Nieder 
19ed5199f6SJonathan Nieder import org.apache.commons.compress.archivers.ArchiveOutputStream;
20ed5199f6SJonathan Nieder import org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream;
21ed5199f6SJonathan Nieder import org.eclipse.jgit.api.ArchiveCommand;
22ed5199f6SJonathan Nieder import org.eclipse.jgit.lib.FileMode;
231448ec37SNaoki Takezoe import org.eclipse.jgit.lib.ObjectId;
24ed5199f6SJonathan Nieder import org.eclipse.jgit.lib.ObjectLoader;
25ed5199f6SJonathan Nieder 
26ed5199f6SJonathan Nieder /**
27ed5199f6SJonathan Nieder  * bzip2-compressed tarball (tar.bz2) format.
28ed5199f6SJonathan Nieder  */
29c0c4c6f0SDavid Ostrovsky public final class Tbz2Format extends BaseFormat implements
30c0c4c6f0SDavid Ostrovsky 		ArchiveCommand.Format<ArchiveOutputStream> {
314ceb25b6SRobin Rosenberg 	private static final List<String> SUFFIXES = Collections
324ceb25b6SRobin Rosenberg 			.unmodifiableList(Arrays.asList(".tar.bz2", ".tbz", ".tbz2")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
3356cb2d92SJonathan Nieder 
34ed5199f6SJonathan Nieder 	private final ArchiveCommand.Format<ArchiveOutputStream> tarFormat = new TarFormat();
35ed5199f6SJonathan Nieder 
3632022e97SMatthias Sohn 	/** {@inheritDoc} */
3730628e3bSMatthias Sohn 	@Override
createArchiveOutputStream(OutputStream s)38ed5199f6SJonathan Nieder 	public ArchiveOutputStream createArchiveOutputStream(OutputStream s)
39ed5199f6SJonathan Nieder 			throws IOException {
40c0c4c6f0SDavid Ostrovsky 		return createArchiveOutputStream(s,
41c0c4c6f0SDavid Ostrovsky 				Collections.<String, Object> emptyMap());
42c0c4c6f0SDavid Ostrovsky 	}
43c0c4c6f0SDavid Ostrovsky 
4432022e97SMatthias Sohn 	/** {@inheritDoc} */
4530628e3bSMatthias Sohn 	@Override
createArchiveOutputStream(OutputStream s, Map<String, Object> o)46c0c4c6f0SDavid Ostrovsky 	public ArchiveOutputStream createArchiveOutputStream(OutputStream s,
47c0c4c6f0SDavid Ostrovsky 			Map<String, Object> o) throws IOException {
48*6f82690aSYoussef Elghareeb 		BZip2CompressorOutputStream out;
49*6f82690aSYoussef Elghareeb 		int compressionLevel = getCompressionLevel(o);
50*6f82690aSYoussef Elghareeb 		if (compressionLevel != -1) {
51*6f82690aSYoussef Elghareeb 			out = new BZip2CompressorOutputStream(s, compressionLevel);
52*6f82690aSYoussef Elghareeb 		} else {
53*6f82690aSYoussef Elghareeb 			out = new BZip2CompressorOutputStream(s);
54*6f82690aSYoussef Elghareeb 		}
55c0c4c6f0SDavid Ostrovsky 		return tarFormat.createArchiveOutputStream(out, o);
56ed5199f6SJonathan Nieder 	}
57ed5199f6SJonathan Nieder 
5832022e97SMatthias Sohn 	/** {@inheritDoc} */
591448ec37SNaoki Takezoe 	@Override
putEntry(ArchiveOutputStream out, ObjectId tree, String path, FileMode mode, ObjectLoader loader)601448ec37SNaoki Takezoe 	public void putEntry(ArchiveOutputStream out,
611448ec37SNaoki Takezoe 			ObjectId tree, String path, FileMode mode, ObjectLoader loader)
621448ec37SNaoki Takezoe 			throws IOException {
631448ec37SNaoki Takezoe 		tarFormat.putEntry(out, tree, path, mode, loader);
64ed5199f6SJonathan Nieder 	}
6556cb2d92SJonathan Nieder 
6632022e97SMatthias Sohn 	/** {@inheritDoc} */
6730628e3bSMatthias Sohn 	@Override
suffixes()6856cb2d92SJonathan Nieder 	public Iterable<String> suffixes() {
6956cb2d92SJonathan Nieder 		return SUFFIXES;
7056cb2d92SJonathan Nieder 	}
710a14909bSJonathan Nieder 
7232022e97SMatthias Sohn 	/** {@inheritDoc} */
730a14909bSJonathan Nieder 	@Override
equals(Object other)740a14909bSJonathan Nieder 	public boolean equals(Object other) {
750a14909bSJonathan Nieder 		return (other instanceof Tbz2Format);
760a14909bSJonathan Nieder 	}
770a14909bSJonathan Nieder 
7832022e97SMatthias Sohn 	/** {@inheritDoc} */
790a14909bSJonathan Nieder 	@Override
hashCode()800a14909bSJonathan Nieder 	public int hashCode() {
810a14909bSJonathan Nieder 		return getClass().hashCode();
820a14909bSJonathan Nieder 	}
83ed5199f6SJonathan Nieder }
84