Class SignerJar

java.lang.Object
pro.gravit.launchserver.binary.SignerJar
All Implemented Interfaces:
AutoCloseable

public class SignerJar extends Object implements AutoCloseable
Generator of signed Jars. It stores some data in memory therefore it is not suited for creation of large files. The usage:
 KeyStore keystore = KeyStore.getInstance("JKS");
 keyStore.load(keystoreStream, "keystorePassword");
 SignerJar jar = new SignerJar(out, keyStore, "keyAlias", "keyPassword");
 signedJar.addManifestAttribute("Main-Class", "com.example.MainClass");
 signedJar.addManifestAttribute("Application-Name", "Example");
 signedJar.addManifestAttribute("Permissions", "all-permissions");
 signedJar.addManifestAttribute("Codebase", "*");
 signedJar.addFileContents("com/example/MainClass.class", clsData);
 signedJar.addFileContents("JNLP-INF/APPLICATION.JNLP", generateJnlpContents());
 signedJar.close();
 
  • Constructor Details

  • Method Details

    • addFileContents

      public void addFileContents(String filename, byte[] contents) throws IOException
      Adds a file to the JAR. The file is immediately added to the zipped output stream. This method cannot be called once the stream is closed.
      Parameters:
      filename - name of the file to add (use forward slash as a path separator)
      contents - contents of the file
      Throws:
      IOException
      NullPointerException - if any of the arguments is null
    • addFileContents

      public void addFileContents(String filename, InputStream contents) throws IOException
      Adds a file to the JAR. The file is immediately added to the zipped output stream. This method cannot be called once the stream is closed.
      Parameters:
      filename - name of the file to add (use forward slash as a path separator)
      contents - contents of the file
      Throws:
      IOException
      NullPointerException - if any of the arguments is null
    • addFileContents

      public void addFileContents(ZipEntry entry, byte[] contents) throws IOException
      Adds a file to the JAR. The file is immediately added to the zipped output stream. This method cannot be called once the stream is closed.
      Parameters:
      entry - name of the file to add (use forward slash as a path separator)
      contents - contents of the file
      Throws:
      IOException
      NullPointerException - if any of the arguments is null
    • addFileContents

      public void addFileContents(ZipEntry entry, InputStream contents) throws IOException
      Adds a file to the JAR. The file is immediately added to the zipped output stream. This method cannot be called once the stream is closed.
      Parameters:
      entry - name of the file to add (use forward slash as a path separator)
      contents - contents of the file
      Throws:
      IOException
      NullPointerException - if any of the arguments is null
    • addManifestAttribute

      public void addManifestAttribute(String name, String value)
      Adds a header to the manifest of the JAR.
      Parameters:
      name - name of the attribute, it is placed into the main section of the manifest file
      value - value of the attribute
    • close

      public void close() throws IOException
      Closes the JAR file by writing the manifest and signature data to it and finishing the ZIP entries. It closes the underlying stream.
      Specified by:
      close in interface AutoCloseable
      Throws:
      IOException
      RuntimeException - if the signing goes wrong
    • finish

      public void finish() throws IOException
      Finishes the JAR file by writing the manifest and signature data to it and finishing the ZIP entries. It leaves the underlying stream open.
      Throws:
      IOException
      RuntimeException - if the signing goes wrong
    • getZos

      public ZipOutputStream getZos()