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.

TgzFormat.java 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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.gzip.GzipCompressorOutputStream;
  19. import org.apache.commons.compress.compressors.gzip.GzipParameters;
  20. import org.eclipse.jgit.api.ArchiveCommand;
  21. import org.eclipse.jgit.lib.FileMode;
  22. import org.eclipse.jgit.lib.ObjectId;
  23. import org.eclipse.jgit.lib.ObjectLoader;
  24. /**
  25. * gzip-compressed tarball (tar.gz) format.
  26. */
  27. public final class TgzFormat extends BaseFormat implements
  28. ArchiveCommand.Format<ArchiveOutputStream> {
  29. private static final List<String> SUFFIXES = Collections
  30. .unmodifiableList(Arrays.asList(".tar.gz", ".tgz")); //$NON-NLS-1$ //$NON-NLS-2$
  31. private final ArchiveCommand.Format<ArchiveOutputStream> tarFormat = new TarFormat();
  32. /** {@inheritDoc} */
  33. @Override
  34. public ArchiveOutputStream createArchiveOutputStream(OutputStream s)
  35. throws IOException {
  36. return createArchiveOutputStream(s,
  37. Collections.<String, Object> emptyMap());
  38. }
  39. /** {@inheritDoc} */
  40. @Override
  41. public ArchiveOutputStream createArchiveOutputStream(OutputStream s,
  42. Map<String, Object> o) throws IOException {
  43. GzipCompressorOutputStream out;
  44. int compressionLevel = getCompressionLevel(o);
  45. if (compressionLevel != -1) {
  46. GzipParameters parameters = new GzipParameters();
  47. parameters.setCompressionLevel(compressionLevel);
  48. out = new GzipCompressorOutputStream(s, parameters);
  49. } else {
  50. out = new GzipCompressorOutputStream(s);
  51. }
  52. return tarFormat.createArchiveOutputStream(out, o);
  53. }
  54. /** {@inheritDoc} */
  55. @Override
  56. public void putEntry(ArchiveOutputStream out,
  57. ObjectId tree, String path, FileMode mode, ObjectLoader loader)
  58. throws IOException {
  59. tarFormat.putEntry(out, tree, path, mode, loader);
  60. }
  61. /** {@inheritDoc} */
  62. @Override
  63. public Iterable<String> suffixes() {
  64. return SUFFIXES;
  65. }
  66. /** {@inheritDoc} */
  67. @Override
  68. public boolean equals(Object other) {
  69. return (other instanceof TgzFormat);
  70. }
  71. /** {@inheritDoc} */
  72. @Override
  73. public int hashCode() {
  74. return getClass().hashCode();
  75. }
  76. }