程序包 proguard.io

类 JarWriter

java.lang.Object
proguard.io.JarWriter
所有已实现的接口:
AutoCloseable, DataEntryWriter
直接已知子类:
SignedJarWriter

public class JarWriter extends Object implements DataEntryWriter
This DataEntryWriter sends data entries to another given data entry writer, automatically adding a manifest file.

You'll typically wrap a ZipWriter or one of its extensions:

     new JarWriter(new ZipWriter(...))
 
  • 字段详细资料

    • DEFAULT_DIGEST_ALGORITHM

      public static final String DEFAULT_DIGEST_ALGORITHM
      另请参阅:
    • digestAlgorithms

      protected final String[] digestAlgorithms
    • creator

      protected final String creator
    • zipEntryWriter

      protected final DataEntryWriter zipEntryWriter
    • manifestEntryWriter

      protected final DataEntryWriter manifestEntryWriter
    • currentManifestEntry

      protected DataEntry currentManifestEntry
  • 构造器详细资料

    • JarWriter

      public JarWriter(DataEntryWriter zipEntryWriter)
      Creates a new JarWriter wth default manifest digest "SHA-256" and manifest file name "META-INF/MANIFEST.MF".
      参数:
      zipEntryWriter - the data entry writer that can provide output streams for the jar entries.
    • JarWriter

      public JarWriter(String[] digestAlgorithms, DataEntryWriter zipEntryWriter)
      Creates a new JarWriter wth default manifest file name "META-INF/MANIFEST.MF".
      参数:
      digestAlgorithms - the manifest digest algorithms, e.g. "SHA-256".
      zipEntryWriter - the data entry writer that can provide output streams for the jar entries.
    • JarWriter

      public JarWriter(String[] digestAlgorithms, String creator, DataEntryWriter zipEntryWriter)
      Creates a new JarWriter wth default manifest file name "META-INF/MANIFEST.MF".
      参数:
      digestAlgorithms - the manifest digest algorithms, e.g. "SHA-256".
      creator - the creator to mention in the manifest file.
      zipEntryWriter - the data entry writer that can provide output streams for the jar entries.
    • JarWriter

      public JarWriter(String[] digestAlgorithms, String creator, String manifestFileName, StringFunction manifestEntryNameFunction, DataEntryWriter zipEntryWriter, DataEntryWriter manifestEntryWriter)
      Creates a new JarWriter.
      参数:
      digestAlgorithms - the manifest digest algorithms, e.g. "SHA-256".
      creator - the creator to mention in the manifest file.
      manifestFileName - the manifest file name, e.g. "META-INF/MANIFEST.MF".
      manifestEntryNameFunction - the function to transform entry names in the manifest (not in the jar).
      zipEntryWriter - the data entry writer that can provide output streams for the jar entries.
      manifestEntryWriter - the data entry writer that can provide an output stream for the manifest file.
  • 方法详细资料

    • createDirectory

      public boolean createDirectory(DataEntry dataEntry) throws IOException
      从接口复制的说明: DataEntryWriter
      Creates a directory.
      指定者:
      createDirectory 在接口中 DataEntryWriter
      参数:
      dataEntry - the data entry for which the directory is to be created.
      返回:
      whether the directory has been created.
      抛出:
      IOException
    • sameOutputStream

      public boolean sameOutputStream(DataEntry dataEntry1, DataEntry dataEntry2) throws IOException
      从接口复制的说明: DataEntryWriter
      Returns whether the two given data entries would result in the same output stream.
      指定者:
      sameOutputStream 在接口中 DataEntryWriter
      参数:
      dataEntry1 - the first data entry.
      dataEntry2 - the second data entry.
      抛出:
      IOException
    • createOutputStream

      public OutputStream createOutputStream(DataEntry dataEntry) throws IOException
      从接口复制的说明: DataEntryWriter
      Creates a new output stream for writing data. The caller is responsible for closing the stream.
      指定者:
      createOutputStream 在接口中 DataEntryWriter
      参数:
      dataEntry - the data entry for which the output stream is to be created.
      返回:
      the output stream. The stream may be null to indicate that the data entry should not be written.
      抛出:
      IOException
    • close

      public void close() throws IOException
      从接口复制的说明: DataEntryWriter
      Finishes writing all data entries.

      Implementations typically create graphs of writers that can split and merge again, possibly even with cycles.

      For splits and merges, implementations need to be idempotent; once closed, subsequent attempts to close a writer have no effect. If needed, the wrapper NonClosingDataEntryWriter can avoid closing a branch prematurely.

      For cycles, implementations must perform any custom behavior, then delegate DataEntryWriter.close() invocations, and only finally clean up. It is possible that delegates call DataEntryWriter.createOutputStream(DataEntry) while DataEntryWriter.close() is in progress.

      指定者:
      close 在接口中 AutoCloseable
      指定者:
      close 在接口中 DataEntryWriter
      抛出:
      IOException
    • println

      public void println(PrintWriter pw, String prefix)
      从接口复制的说明: DataEntryWriter
      Prints out the structure of the data entry writer.
      指定者:
      println 在接口中 DataEntryWriter
      参数:
      pw - the print stream to which the structure should be printed.
      prefix - a prefix for every printed line.
    • openManifestFiles

      protected void openManifestFiles() throws IOException
      Prepares streams and writers for capturing digests of a parent entry.
      抛出:
      IOException
    • createManifestOutputStream

      protected OutputStream createManifestOutputStream(DataEntry manifestEntry) throws IOException
      Creates an output stream for the specified manifest file.
      抛出:
      IOException
    • finishIfNecessary

      protected void finishIfNecessary(DataEntry dataEntry) throws IOException
      Writes out the collected manifest file for the current jar, if we're entering a new jar with this data entry.
      抛出:
      IOException
    • finish

      protected void finish() throws IOException
      Writes out the collected manifest file before closing the jar, if any.
      抛出:
      IOException
    • printWriter

      protected PrintWriter printWriter(OutputStream outputStream) throws IOException
      Creates a convenience writer.
      参数:
      outputStream - the underlying output stream.
      抛出:
      IOException
    • main

      public static void main(String[] args)
      Provides a simple test for this class, creating a signed apk file (only v1) with the given name and a few aligned/compressed/uncompressed zip entries. Arguments: jar_filename Verify the jar with: jarsigner -verify -verbose /tmp/test.jar