Class JarWriter


  • public class JarWriter
    extends java.lang.Object
    Writes JAR content, ensuring valid directory entries are always create and duplicate items are ignored.
    Author:
    Phillip Webb, Andy Wilkinson
    • Method Summary

      Modifier and Type Method Description
      void close()
      Close the writer.
      void writeEntries​(java.util.jar.JarFile jarFile)
      Write all entries from the specified jar file.
      void writeEntry​(java.lang.String entryName, java.io.InputStream inputStream)
      Writes an entry.
      void writeLoaderClasses()
      Write the required spring-boot-loader classes to the JAR.
      void writeManifest​(java.util.jar.Manifest manifest)
      Write the specified manifest.
      void writeNestedLibrary​(java.lang.String destination, Library library)
      Write a nested library.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • JarWriter

        public JarWriter​(java.io.File file)
                  throws java.io.FileNotFoundException,
                         java.io.IOException
        Create a new JarWriter instance.
        Parameters:
        file - the file to write
        Throws:
        java.io.IOException - if the file cannot be opened
        java.io.FileNotFoundException - if the file cannot be found
      • JarWriter

        public JarWriter​(java.io.File file,
                         LaunchScript launchScript)
                  throws java.io.FileNotFoundException,
                         java.io.IOException
        Create a new JarWriter instance.
        Parameters:
        file - the file to write
        launchScript - an optional launch script to prepend to the front of the jar
        Throws:
        java.io.IOException - if the file cannot be opened
        java.io.FileNotFoundException - if the file cannot be found
    • Method Detail

      • writeManifest

        public void writeManifest​(java.util.jar.Manifest manifest)
                           throws java.io.IOException
        Write the specified manifest.
        Parameters:
        manifest - the manifest to write
        Throws:
        java.io.IOException - of the manifest cannot be written
      • writeEntries

        public void writeEntries​(java.util.jar.JarFile jarFile)
                          throws java.io.IOException
        Write all entries from the specified jar file.
        Parameters:
        jarFile - the source jar file
        Throws:
        java.io.IOException - if the entries cannot be written
      • writeEntry

        public void writeEntry​(java.lang.String entryName,
                               java.io.InputStream inputStream)
                        throws java.io.IOException
        Writes an entry. The inputStream is closed once the entry has been written
        Parameters:
        entryName - The name of the entry
        inputStream - The stream from which the entry's data can be read
        Throws:
        java.io.IOException - if the write fails
      • writeNestedLibrary

        public void writeNestedLibrary​(java.lang.String destination,
                                       Library library)
                                throws java.io.IOException
        Write a nested library.
        Parameters:
        destination - the destination of the library
        library - the library
        Throws:
        java.io.IOException - if the write fails
      • writeLoaderClasses

        public void writeLoaderClasses()
                                throws java.io.IOException
        Write the required spring-boot-loader classes to the JAR.
        Throws:
        java.io.IOException - if the classes cannot be written
      • close

        public void close()
                   throws java.io.IOException
        Close the writer.
        Throws:
        java.io.IOException - if the file cannot be closed