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 21 import java.io.IOException; 22 import java.io.InputStream; 23 24 import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; 25 import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream; 26 27 /** 28 * Implements an input stream that can read entries from jar files. 29 * 30 * @NotThreadSafe 31 */ 32 public class JarArchiveInputStream extends ZipArchiveInputStream { 33 34 /** 35 * Checks if the signature matches what is expected for a jar file (in this case it is the same as for a ZIP file). 36 * 37 * @param signature the bytes to check 38 * @param length the number of bytes to check 39 * @return true, if this stream is a jar archive stream, false otherwise 40 */ 41 public static boolean matches(final byte[] signature, final int length) { 42 return ZipArchiveInputStream.matches(signature, length); 43 } 44 45 /** 46 * Creates an instance from the input stream using the default encoding. 47 * 48 * @param inputStream the input stream to wrap 49 */ 50 public JarArchiveInputStream(final InputStream inputStream) { 51 super(inputStream); 52 } 53 54 /** 55 * Creates an instance from the input stream using the specified encoding. 56 * 57 * @param inputStream the input stream to wrap 58 * @param encoding the encoding to use 59 * @since 1.10 60 */ 61 public JarArchiveInputStream(final InputStream inputStream, final String encoding) { 62 super(inputStream, encoding); 63 } 64 65 @Override 66 public JarArchiveEntry getNextEntry() throws IOException { 67 return getNextJarEntry(); 68 } 69 70 /** 71 * Gets the next entry. 72 * 73 * @return the next entry. 74 * @throws IOException if an I/O error occurs. 75 * @deprecated Use {@link #getNextEntry()}. 76 */ 77 @Deprecated 78 public JarArchiveEntry getNextJarEntry() throws IOException { 79 final ZipArchiveEntry entry = getNextZipEntry(); 80 return entry == null ? null : new JarArchiveEntry(entry); 81 } 82 }