com.android.builder.signing
Class SignedJarBuilder

java.lang.Object
  extended by com.android.builder.signing.SignedJarBuilder

public class SignedJarBuilder
extends java.lang.Object

A Jar file builder with signature support.


Nested Class Summary
static interface SignedJarBuilder.IZipEntryFilter
          Classes which implement this interface provides a method to check whether a file should be added to a Jar file.
 
Constructor Summary
SignedJarBuilder(java.io.OutputStream out, java.security.PrivateKey key, java.security.cert.X509Certificate certificate, java.lang.String builtBy, java.lang.String createdBy)
          Creates a SignedJarBuilder with a given output stream, and signing information.
 
Method Summary
 void cleanUp()
          Clean up of the builder for interrupted workflow.
 void close()
          Closes the Jar archive by creating the manifest, and signing the archive.
 void writeFile(java.io.File inputFile, java.lang.String jarPath)
          Writes a new File into the archive.
 void writeZip(java.io.InputStream input, SignedJarBuilder.IZipEntryFilter filter)
          Copies the content of a Jar/Zip archive into the receiver archive.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SignedJarBuilder

public SignedJarBuilder(@NonNull
                        java.io.OutputStream out,
                        @Nullable
                        java.security.PrivateKey key,
                        @Nullable
                        java.security.cert.X509Certificate certificate,
                        @Nullable
                        java.lang.String builtBy,
                        @Nullable
                        java.lang.String createdBy)
                 throws java.io.IOException,
                        java.security.NoSuchAlgorithmException
Creates a SignedJarBuilder with a given output stream, and signing information.

If either key or certificate is null then the archive will not be signed.

Parameters:
out - the OutputStream where to write the Jar archive.
key - the PrivateKey used to sign the archive, or null.
certificate - the X509Certificate used to sign the archive, or null.
Throws:
java.io.IOException
java.security.NoSuchAlgorithmException
Method Detail

writeFile

public void writeFile(java.io.File inputFile,
                      java.lang.String jarPath)
               throws java.io.IOException
Writes a new File into the archive.

Parameters:
inputFile - the File to write.
jarPath - the filepath inside the archive.
Throws:
java.io.IOException

writeZip

public void writeZip(java.io.InputStream input,
                     SignedJarBuilder.IZipEntryFilter filter)
              throws java.io.IOException,
                     SignedJarBuilder.IZipEntryFilter.ZipAbortException
Copies the content of a Jar/Zip archive into the receiver archive.

An optional SignedJarBuilder.IZipEntryFilter allows to selectively choose which files to copy over.

Parameters:
input - the InputStream for the Jar/Zip to copy.
filter - the filter or null
Throws:
java.io.IOException
SignedJarBuilder.IZipEntryFilter.ZipAbortException - if the SignedJarBuilder.IZipEntryFilter filter indicated that the write must be aborted.

close

public void close()
           throws java.io.IOException,
                  SigningException
Closes the Jar archive by creating the manifest, and signing the archive.

Throws:
java.io.IOException
SigningException

cleanUp

public void cleanUp()
Clean up of the builder for interrupted workflow. This does nothing if close() was called successfully.