Package proguard.io
Class JarWriter
java.lang.Object
proguard.io.JarWriter
- All Implemented Interfaces:
AutoCloseable,DataEntryWriter
- Direct Known Subclasses:
SignedJarWriter
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(...))
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classThis FilterOutputStream automatically appends a file digest entry to a given manifest writer, when the stream is closed. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final Stringprotected DataEntrystatic final Stringprotected final String[]protected final DataEntryWriterprotected final DataEntryWriter -
Constructor Summary
ConstructorsConstructorDescriptionJarWriter(String[] digestAlgorithms, String creator, String manifestFileName, StringFunction manifestEntryNameFunction, DataEntryWriter zipEntryWriter, DataEntryWriter manifestEntryWriter) Creates a new JarWriter.JarWriter(String[] digestAlgorithms, String creator, DataEntryWriter zipEntryWriter) Creates a new JarWriter wth default manifest file name "META-INF/MANIFEST.MF".JarWriter(String[] digestAlgorithms, DataEntryWriter zipEntryWriter) Creates a new JarWriter wth default manifest file name "META-INF/MANIFEST.MF".JarWriter(DataEntryWriter zipEntryWriter) Creates a new JarWriter wth default manifest digest "SHA-256" and manifest file name "META-INF/MANIFEST.MF". -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Finishes writing all data entries.booleancreateDirectory(DataEntry dataEntry) Creates a directory.protected OutputStreamcreateManifestOutputStream(DataEntry manifestEntry) Creates an output stream for the specified manifest file.createOutputStream(DataEntry dataEntry) Creates a new output stream for writing data.protected voidfinish()Writes out the collected manifest file before closing the jar, if any.protected voidfinishIfNecessary(DataEntry dataEntry) Writes out the collected manifest file for the current jar, if we're entering a new jar with this data entry.static voidProvides 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.protected voidPrepares streams and writers for capturing digests of a parent entry.voidprintln(PrintWriter pw, String prefix) Prints out the structure of the data entry writer.protected PrintWriterprintWriter(OutputStream outputStream) Creates a convenience writer.booleansameOutputStream(DataEntry dataEntry1, DataEntry dataEntry2) Returns whether the two given data entries would result in the same output stream.
-
Field Details
-
DEFAULT_DIGEST_ALGORITHM
- See Also:
-
digestAlgorithms
-
creator
-
zipEntryWriter
-
manifestEntryWriter
-
currentManifestEntry
-
-
Constructor Details
-
JarWriter
Creates a new JarWriter wth default manifest digest "SHA-256" and manifest file name "META-INF/MANIFEST.MF".- Parameters:
zipEntryWriter- the data entry writer that can provide output streams for the jar entries.
-
JarWriter
Creates a new JarWriter wth default manifest file name "META-INF/MANIFEST.MF".- Parameters:
digestAlgorithms- the manifest digest algorithms, e.g. "SHA-256".zipEntryWriter- the data entry writer that can provide output streams for the jar entries.
-
JarWriter
Creates a new JarWriter wth default manifest file name "META-INF/MANIFEST.MF".- Parameters:
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.- Parameters:
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.
-
-
Method Details
-
createDirectory
Description copied from interface:DataEntryWriterCreates a directory.- Specified by:
createDirectoryin interfaceDataEntryWriter- Parameters:
dataEntry- the data entry for which the directory is to be created.- Returns:
- whether the directory has been created.
- Throws:
IOException
-
sameOutputStream
Description copied from interface:DataEntryWriterReturns whether the two given data entries would result in the same output stream.- Specified by:
sameOutputStreamin interfaceDataEntryWriter- Parameters:
dataEntry1- the first data entry.dataEntry2- the second data entry.- Throws:
IOException
-
createOutputStream
Description copied from interface:DataEntryWriterCreates a new output stream for writing data. The caller is responsible for closing the stream.- Specified by:
createOutputStreamin interfaceDataEntryWriter- Parameters:
dataEntry- the data entry for which the output stream is to be created.- Returns:
- the output stream. The stream may be
nullto indicate that the data entry should not be written. - Throws:
IOException
-
close
Description copied from interface:DataEntryWriterFinishes 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
NonClosingDataEntryWritercan 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 callDataEntryWriter.createOutputStream(DataEntry)whileDataEntryWriter.close()is in progress.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceDataEntryWriter- Throws:
IOException
-
println
Description copied from interface:DataEntryWriterPrints out the structure of the data entry writer.- Specified by:
printlnin interfaceDataEntryWriter- Parameters:
pw- the print stream to which the structure should be printed.prefix- a prefix for every printed line.
-
openManifestFiles
Prepares streams and writers for capturing digests of a parent entry.- Throws:
IOException
-
createManifestOutputStream
Creates an output stream for the specified manifest file.- Throws:
IOException
-
finishIfNecessary
Writes out the collected manifest file for the current jar, if we're entering a new jar with this data entry.- Throws:
IOException
-
finish
Writes out the collected manifest file before closing the jar, if any.- Throws:
IOException
-
printWriter
Creates a convenience writer.- Parameters:
outputStream- the underlying output stream.- Throws:
IOException
-
main
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
-