JarArchiveInputStream.java

  1. /*
  2.  * Licensed to the Apache Software Foundation (ASF) under one
  3.  * or more contributor license agreements.  See the NOTICE file
  4.  * distributed with this work for additional information
  5.  * regarding copyright ownership.  The ASF licenses this file
  6.  * to you under the Apache License, Version 2.0 (the
  7.  * "License"); you may not use this file except in compliance
  8.  * with the License.  You may obtain a copy of the License at
  9.  *
  10.  * http://www.apache.org/licenses/LICENSE-2.0
  11.  *
  12.  * Unless required by applicable law or agreed to in writing,
  13.  * software distributed under the License is distributed on an
  14.  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15.  * KIND, either express or implied.  See the License for the
  16.  * specific language governing permissions and limitations
  17.  * under the License.
  18.  */
  19. package org.apache.commons.compress.archivers.jar;

  20. import java.io.IOException;
  21. import java.io.InputStream;

  22. import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
  23. import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream;

  24. /**
  25.  * Implements an input stream that can read entries from jar files.
  26.  *
  27.  * @NotThreadSafe
  28.  */
  29. public class JarArchiveInputStream extends ZipArchiveInputStream {

  30.     /**
  31.      * Checks if the signature matches what is expected for a jar file (in this case it is the same as for a ZIP file).
  32.      *
  33.      * @param signature the bytes to check
  34.      * @param length    the number of bytes to check
  35.      * @return true, if this stream is a jar archive stream, false otherwise
  36.      */
  37.     public static boolean matches(final byte[] signature, final int length) {
  38.         return ZipArchiveInputStream.matches(signature, length);
  39.     }

  40.     /**
  41.      * Creates an instance from the input stream using the default encoding.
  42.      *
  43.      * @param inputStream the input stream to wrap
  44.      */
  45.     public JarArchiveInputStream(final InputStream inputStream) {
  46.         super(inputStream);
  47.     }

  48.     /**
  49.      * Creates an instance from the input stream using the specified encoding.
  50.      *
  51.      * @param inputStream the input stream to wrap
  52.      * @param encoding    the encoding to use
  53.      * @since 1.10
  54.      */
  55.     public JarArchiveInputStream(final InputStream inputStream, final String encoding) {
  56.         super(inputStream, encoding);
  57.     }

  58.     @Override
  59.     public JarArchiveEntry getNextEntry() throws IOException {
  60.         return getNextJarEntry();
  61.     }

  62.     /**
  63.      * Gets the next entry.
  64.      *
  65.      * @return the next entry.
  66.      * @throws IOException if an I/O error occurs.
  67.      * @deprecated Use {@link #getNextEntry()}.
  68.      */
  69.     @Deprecated
  70.     public JarArchiveEntry getNextJarEntry() throws IOException {
  71.         final ZipArchiveEntry entry = getNextZipEntry();
  72.         return entry == null ? null : new JarArchiveEntry(entry);
  73.     }
  74. }