类 ZipContent

java.lang.Object
org.springframework.boot.loader.zip.ZipContent
所有已实现的接口:
Closeable, AutoCloseable

public final class ZipContent extends Object implements Closeable
Provides raw access to content from a regular or nested zip file. This class performs the low level parsing of a zip file and provide access to raw entry data that it contains. Unlike 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
  • 方法详细资料

    • getKind

      public ZipContent.Kind getKind()
      Return the kind of content that was loaded.
      返回:
      the content kind
      从以下版本开始:
      3.2.2
    • openRawZipData

      public CloseableDataBlock openRawZipData() throws IOException
      Open a DataBlock containing 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

      public String getComment()
      Return the zip comment, if any.
      返回:
      the comment or null
    • getEntry

      public ZipContent.Entry getEntry(CharSequence name)
      Return the entry with the given name, if any.
      参数:
      name - the name of the entry to find
      返回:
      the entry or null
    • getEntry

      public ZipContent.Entry getEntry(CharSequence namePrefix, CharSequence name)
      Return the entry with the given name, if any.
      参数:
      namePrefix - an optional prefix for the name
      name - the name of the entry to find
      返回:
      the entry or null
    • hasEntry

      public boolean hasEntry(CharSequence namePrefix, CharSequence name)
      Return if an entry with the given name exists.
      参数:
      namePrefix - an optional prefix for the name
      name - the name of the entry to find
      返回:
      the entry or null
    • getEntry

      public ZipContent.Entry getEntry(int index)
      Return the entry at the specified index.
      参数:
      index - the entry index
      返回:
      the entry
      抛出:
      IndexOutOfBoundsException - if the index is out of bounds
    • getInfo

      public <I> I getInfo(Class<I> type, Function<ZipContent,I> function)
      Get or compute information based on the ZipContent.
      类型参数:
      I - the info type to get or compute
      参数:
      type - the info type to get or compute
      function - the function used to compute the information
      返回:
      the computed or existing information
    • hasJarSignatureFile

      public boolean hasJarSignatureFile()
      Returns true if this zip contains a jar signature file (META-INF/*.DSA).
      返回:
      if the zip contains a jar signature file
    • close

      public void close() throws IOException
      Close this jar file, releasing the underlying file if this was the last reference.
      指定者:
      close 在接口中 AutoCloseable
      指定者:
      close 在接口中 Closeable
      抛出:
      IOException
      另请参阅:
    • toString

      public String toString()
      覆盖:
      toString 在类中 Object
    • open

      public static ZipContent open(Path path) throws IOException
      Open ZipContent from the specified path. The resulting ZipContent must be closed by the caller.
      参数:
      path - the zip path
      返回:
      a ZipContent instance
      抛出:
      IOException - on I/O error
    • open

      public static ZipContent open(Path path, String nestedEntryName) throws IOException
      Open nested ZipContent from the specified path. The resulting ZipContent must be closed by the caller.
      参数:
      path - the zip path
      nestedEntryName - the nested entry name to open
      返回:
      a ZipContent instance
      抛出:
      IOException - on I/O error