类 ZipContent
- 所有已实现的接口:
Closeable,AutoCloseable
ZipFile, this implementation can load content
from a zip file nested inside another file as long as the entry is not compressed.
In order to reduce memory consumption, this implementation stores only the hash of the
entry names, the central directory offsets and the original positions. Entries are
stored internally in hashCode order so that a binary search can be used to
quickly find an entry by name or determine if the zip file doesn't have a given entry.
ZipContent for a typical Spring Boot application JAR will have somewhere in the
region of 10,500 entries which should consume about 122K.
ZipContent results are cached and it is assumed that zip content will not
change once loaded. Entries and Strings are not cached and will be recreated on each
access which may produce a lot of garbage.
This implementation does not use Cleaner.Cleanable so care must be taken to release
ZipContent resources. The close() method should be called explicitly
or by try-with-resources. Care must be take to only call close once.
- 从以下版本开始:
- 3.2.0
- 作者:
- Phillip Webb, Andy Wilkinson
-
嵌套类概要
嵌套类修饰符和类型类说明classA single zip content entry.static enumZip content kinds. -
方法概要
修饰符和类型方法说明voidclose()Close this jar file, releasing the underlying file if this was the last reference.Return the zip comment, if any.getEntry(int index) Return the entry at the specified index.getEntry(CharSequence name) Return the entry with the given name, if any.getEntry(CharSequence namePrefix, CharSequence name) Return the entry with the given name, if any.<I> IgetInfo(Class<I> type, Function<ZipContent, I> function) Get or compute information based on theZipContent.getKind()Return the kind of content that was loaded.booleanhasEntry(CharSequence namePrefix, CharSequence name) Return if an entry with the given name exists.booleanReturnstrueif this zip contains a jar signature file (META-INF/*.DSA).static ZipContentOpenZipContentfrom the specified path.static ZipContentOpen nestedZipContentfrom the specified path.Open aDataBlockcontaining the raw zip data.intsize()Returns the number of entries in the ZIP file.toString()
-
方法详细资料
-
getKind
Return the kind of content that was loaded.- 返回:
- the content kind
- 从以下版本开始:
- 3.2.2
-
openRawZipData
Open aDataBlockcontaining the raw zip data. For container zip files, this may be smaller than the original file since additional bytes are permitted at the front of a zip file. For nested zip files, this will be only the contents of the nest zip.For nested directory zip files, a virtual data block will be created containing only the relevant content.
To release resources, the
close()method of the data block should be called explicitly or by try-with-resources.The returned data block should not be accessed once
close()has been called.- 返回:
- the zip data
- 抛出:
IOException- on I/O error
-
size
public int size()Returns the number of entries in the ZIP file.- 返回:
- the number of entries
-
getComment
Return the zip comment, if any.- 返回:
- the comment or
null
-
getEntry
Return the entry with the given name, if any.- 参数:
name- the name of the entry to find- 返回:
- the entry or
null
-
getEntry
Return the entry with the given name, if any.- 参数:
namePrefix- an optional prefix for the namename- the name of the entry to find- 返回:
- the entry or
null
-
hasEntry
Return if an entry with the given name exists.- 参数:
namePrefix- an optional prefix for the namename- the name of the entry to find- 返回:
- the entry or
null
-
getEntry
Return the entry at the specified index.- 参数:
index- the entry index- 返回:
- the entry
- 抛出:
IndexOutOfBoundsException- if the index is out of bounds
-
getInfo
Get or compute information based on theZipContent.- 类型参数:
I- the info type to get or compute- 参数:
type- the info type to get or computefunction- the function used to compute the information- 返回:
- the computed or existing information
-
hasJarSignatureFile
public boolean hasJarSignatureFile()Returnstrueif this zip contains a jar signature file (META-INF/*.DSA).- 返回:
- if the zip contains a jar signature file
-
close
Close this jar file, releasing the underlying file if this was the last reference.- 指定者:
close在接口中AutoCloseable- 指定者:
close在接口中Closeable- 抛出:
IOException- 另请参阅:
-
toString
-
open
- 参数:
path- the zip path- 返回:
- a
ZipContentinstance - 抛出:
IOException- on I/O error
-
open
Open nestedZipContentfrom the specified path. The resultingZipContentmust beclosedby the caller.- 参数:
path- the zip pathnestedEntryName- the nested entry name to open- 返回:
- a
ZipContentinstance - 抛出:
IOException- on I/O error
-