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 createArchiveOutputStream(OutputStream s)38 public ArchiveOutputStream createArchiveOutputStream(OutputStream s) 39 throws IOException { 40 return createArchiveOutputStream(s, 41 Collections.<String, Object> emptyMap()); 42 } 43 44 /** {@inheritDoc} */ 45 @Override createArchiveOutputStream(OutputStream s, Map<String, Object> o)46 public ArchiveOutputStream createArchiveOutputStream(OutputStream s, 47 Map<String, Object> o) throws IOException { 48 BZip2CompressorOutputStream out; 49 int compressionLevel = getCompressionLevel(o); 50 if (compressionLevel != -1) { 51 out = new BZip2CompressorOutputStream(s, compressionLevel); 52 } else { 53 out = new BZip2CompressorOutputStream(s); 54 } 55 return tarFormat.createArchiveOutputStream(out, o); 56 } 57 58 /** {@inheritDoc} */ 59 @Override putEntry(ArchiveOutputStream out, ObjectId tree, String path, FileMode mode, ObjectLoader loader)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 /** {@inheritDoc} */ 67 @Override suffixes()68 public Iterable<String> suffixes() { 69 return SUFFIXES; 70 } 71 72 /** {@inheritDoc} */ 73 @Override equals(Object other)74 public boolean equals(Object other) { 75 return (other instanceof Tbz2Format); 76 } 77 78 /** {@inheritDoc} */ 79 @Override hashCode()80 public int hashCode() { 81 return getClass().hashCode(); 82 } 83 } 84