Most visited

Recently visited

Added in API level 1

JarInputStream

public class JarInputStream
extends ZipInputStream

java.lang.Object
   ↳ java.io.InputStream
     ↳ java.io.FilterInputStream
       ↳ java.util.zip.InflaterInputStream
         ↳ java.util.zip.ZipInputStream
           ↳ java.util.jar.JarInputStream


JarInputStream类用于从任何输入流中读取JAR文件的内容。 它扩展了类java.util.zip.ZipInputStream ,支持读取可选的Manifest条目。 Manifest可用于存储关于JAR文件及其条目的元信息。

也可以看看:

Summary

Inherited constants

From class java.util.zip.ZipInputStream

Inherited fields

From class java.util.zip.InflaterInputStream
From class java.io.FilterInputStream

Public constructors

JarInputStream(InputStream in)

创建一个新的 JarInputStream并读取可选清单。

JarInputStream(InputStream in, boolean verify)

创建一个新的 JarInputStream并读取可选清单。

Public methods

Manifest getManifest()

如果没有,则返回此JAR文件的 Manifestnull

ZipEntry getNextEntry()

读取下一个ZIP文件条目并将该流定位在条目数据的开头。

JarEntry getNextJarEntry()

读取下一个JAR文件条目并将该流定位在条目数据的开头。

int read(byte[] b, int off, int len)

从当前JAR文件条目读入一个字节数组。

Protected methods

ZipEntry createZipEntry(String name)

为指定的JAR文件条目名称创建新的 JarEntryZipEntry )。

Inherited methods

From class java.util.zip.ZipInputStream
From class java.util.zip.InflaterInputStream
From class java.io.FilterInputStream
From class java.io.InputStream
From class java.lang.Object
From interface java.io.Closeable
From interface java.lang.AutoCloseable

Public constructors

JarInputStream

Added in API level 1
JarInputStream (InputStream in)

创建一个新的JarInputStream并读取可选清单。 如果清单存在,还会尝试在JarInputStream签名后验证签名。

Parameters
in InputStream: the actual input stream
Throws
IOException if an I/O error has occurred

JarInputStream

Added in API level 1
JarInputStream (InputStream in, 
                boolean verify)

创建一个新的JarInputStream并读取可选清单。 如果清单存在并且验证为真,那么当JarInputStream被签名时也会尝试验证签名。

Parameters
in InputStream: the actual input stream
verify boolean: whether or not to verify the JarInputStream if it is signed.
Throws
IOException if an I/O error has occurred

Public methods

getManifest

Added in API level 1
Manifest getManifest ()

如果没有,则返回此JAR文件的 Manifestnull

Returns
Manifest the Manifest for this JAR file, or null if none.

getNextEntry

Added in API level 1
ZipEntry getNextEntry ()

读取下一个ZIP文件条目并将该流定位在条目数据的开头。 如果已启用验证,则在为下一个条目定位流时检测到任何无效签名将导致异常。

Returns
ZipEntry the next ZIP file entry, or null if there are no more entries
Throws
ZipException if a ZIP file error has occurred
IOException if an I/O error has occurred
SecurityException if any of the jar file entries are incorrectly signed.

getNextJarEntry

Added in API level 1
JarEntry getNextJarEntry ()

读取下一个JAR文件条目并将该流定位在条目数据的开头。 如果已启用验证,则在为下一个条目定位流时检测到任何无效签名将导致异常。

Returns
JarEntry the next JAR file entry, or null if there are no more entries
Throws
ZipException if a ZIP file error has occurred
IOException if an I/O error has occurred
SecurityException if any of the jar file entries are incorrectly signed.

read

Added in API level 1
int read (byte[] b, 
                int off, 
                int len)

从当前JAR文件条目读入一个字节数组。 如果len不为零,则该方法会阻塞,直到某些输入可用; 否则,不读取字节并返回0 如果启用了验证,当前条目上的任何无效签名将在条目结束前的某个时间点上报。

Parameters
b byte: the buffer into which the data is read
off int: the start offset in the destination array b
len int: the maximum number of bytes to read
Returns
int the actual number of bytes read, or -1 if the end of the entry is reached
Throws
NullPointerException If b is null.
IndexOutOfBoundsException If off is negative, len is negative, or len is greater than b.length - off
ZipException if a ZIP file error has occurred
IOException if an I/O error has occurred
SecurityException if any of the jar file entries are incorrectly signed.

Protected methods

createZipEntry

Added in API level 1
ZipEntry createZipEntry (String name)

为指定的JAR文件条目名称创建一个新的JarEntryZipEntry )。 指定的JAR文件条目名称的清单属性将被复制到新的JarEntry

Parameters
name String: the name of the JAR/ZIP file entry
Returns
ZipEntry the JarEntry object just created

Hooray!