xref: /JGit/org.eclipse.jgit.archive/src/org/eclipse/jgit/archive/TxzFormat.java (revision 6f82690aaf2be783be6d77f0903788ff0832472a)
17f2f5973SJonathan Nieder /*
25c5f7c6bSMatthias Sohn  * Copyright (C) 2013 Google Inc. and others
37f2f5973SJonathan 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.
77f2f5973SJonathan Nieder  *
85c5f7c6bSMatthias Sohn  * SPDX-License-Identifier: BSD-3-Clause
97f2f5973SJonathan Nieder  */
107f2f5973SJonathan Nieder package org.eclipse.jgit.archive;
117f2f5973SJonathan Nieder 
127f2f5973SJonathan Nieder import java.io.IOException;
137f2f5973SJonathan 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;
187f2f5973SJonathan Nieder 
197f2f5973SJonathan Nieder import org.apache.commons.compress.archivers.ArchiveOutputStream;
207f2f5973SJonathan Nieder import org.apache.commons.compress.compressors.xz.XZCompressorOutputStream;
217f2f5973SJonathan Nieder import org.eclipse.jgit.api.ArchiveCommand;
227f2f5973SJonathan Nieder import org.eclipse.jgit.lib.FileMode;
231448ec37SNaoki Takezoe import org.eclipse.jgit.lib.ObjectId;
247f2f5973SJonathan Nieder import org.eclipse.jgit.lib.ObjectLoader;
257f2f5973SJonathan Nieder 
26659cadf0SJonathan Nieder /**
27659cadf0SJonathan Nieder  * Xz-compressed tar (tar.xz) format.
28659cadf0SJonathan Nieder  */
29c0c4c6f0SDavid Ostrovsky public final class TxzFormat extends BaseFormat implements
30c0c4c6f0SDavid Ostrovsky 		ArchiveCommand.Format<ArchiveOutputStream> {
314ceb25b6SRobin Rosenberg 	private static final List<String> SUFFIXES = Collections
324ceb25b6SRobin Rosenberg 			.unmodifiableList(Arrays.asList(".tar.xz", ".txz")); //$NON-NLS-1$ //$NON-NLS-2$
3356cb2d92SJonathan Nieder 
347f2f5973SJonathan Nieder 	private final ArchiveCommand.Format<ArchiveOutputStream> tarFormat = new TarFormat();
357f2f5973SJonathan Nieder 
3632022e97SMatthias Sohn 	/** {@inheritDoc} */
3730628e3bSMatthias Sohn 	@Override
createArchiveOutputStream(OutputStream s)387f2f5973SJonathan Nieder 	public ArchiveOutputStream createArchiveOutputStream(OutputStream s)
397f2f5973SJonathan 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 		XZCompressorOutputStream out;
49*6f82690aSYoussef Elghareeb 		int compressionLevel = getCompressionLevel(o);
50*6f82690aSYoussef Elghareeb 		if (compressionLevel != -1) {
51*6f82690aSYoussef Elghareeb 			out = new XZCompressorOutputStream(s, compressionLevel);
52*6f82690aSYoussef Elghareeb 		} else {
53*6f82690aSYoussef Elghareeb 			out = new XZCompressorOutputStream(s);
54*6f82690aSYoussef Elghareeb 		}
55c0c4c6f0SDavid Ostrovsky 		return tarFormat.createArchiveOutputStream(out, o);
567f2f5973SJonathan Nieder 	}
577f2f5973SJonathan 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);
647f2f5973SJonathan 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 TxzFormat);
760a14909bSJonathan Nieder 	}
770a14909bSJonathan Nieder 
7832022e97SMatthias Sohn 	/** {@inheritDoc} */
790a14909bSJonathan Nieder 	@Override
hashCode()800a14909bSJonathan Nieder 	public int hashCode() {
810a14909bSJonathan Nieder 		return getClass().hashCode();
820a14909bSJonathan Nieder 	}
837f2f5973SJonathan Nieder }
84