You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Tbz2Format.java 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. import java.io.IOException;
  12. import java.io.OutputStream;
  13. import java.util.Arrays;
  14. import java.util.Collections;
  15. import java.util.List;
  16. import java.util.Map;
  17. import org.apache.commons.compress.archivers.ArchiveOutputStream;
  18. import org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream;
  19. import org.eclipse.jgit.api.ArchiveCommand;
  20. import org.eclipse.jgit.lib.FileMode;
  21. import org.eclipse.jgit.lib.ObjectId;
  22. import org.eclipse.jgit.lib.ObjectLoader;
  23. /**
  24. * bzip2-compressed tarball (tar.bz2) format.
  25. */
  26. public final class Tbz2Format extends BaseFormat implements
  27. ArchiveCommand.Format<ArchiveOutputStream> {
  28. private static final List<String> SUFFIXES = Collections
  29. .unmodifiableList(Arrays.asList(".tar.bz2", ".tbz", ".tbz2")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
  30. private final ArchiveCommand.Format<ArchiveOutputStream> tarFormat = new TarFormat();
  31. /** {@inheritDoc} */
  32. @Override
  33. public ArchiveOutputStream createArchiveOutputStream(OutputStream s)
  34. throws IOException {
  35. return createArchiveOutputStream(s,
  36. Collections.<String, Object> emptyMap());
  37. }
  38. /** {@inheritDoc} */
  39. @Override
  40. public ArchiveOutputStream createArchiveOutputStream(OutputStream s,
  41. Map<String, Object> o) throws IOException {
  42. BZip2CompressorOutputStream out = new BZip2CompressorOutputStream(s);
  43. return tarFormat.createArchiveOutputStream(out, o);
  44. }
  45. /** {@inheritDoc} */
  46. @Override
  47. public void putEntry(ArchiveOutputStream out,
  48. ObjectId tree, String path, FileMode mode, ObjectLoader loader)
  49. throws IOException {
  50. tarFormat.putEntry(out, tree, path, mode, loader);
  51. }
  52. /** {@inheritDoc} */
  53. @Override
  54. public Iterable<String> suffixes() {
  55. return SUFFIXES;
  56. }
  57. /** {@inheritDoc} */
  58. @Override
  59. public boolean equals(Object other) {
  60. return (other instanceof Tbz2Format);
  61. }
  62. /** {@inheritDoc} */
  63. @Override
  64. public int hashCode() {
  65. return getClass().hashCode();
  66. }
  67. }