Class JarWriter
- java.lang.Object
- org.springframework.boot.loader.tools.JarWriter
- All Implemented Interfaces:
LoaderClassesWriter
public class JarWriter extends Object implements LoaderClassesWriter
Writes JAR content, ensuring valid directory entries are always create and duplicate items are ignored.
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Close the writer.void
writeEntries(JarFile jarFile)
Write all entries from the specified jar file.void
writeEntry(String entryName, InputStream inputStream)
Writes an entry.void
writeLoaderClasses()
Write the required spring-boot-loader classes to the JAR.void
writeLoaderClasses(String loaderJarResourceName)
Write the required spring-boot-loader classes to the JAR.void
writeManifest(Manifest manifest)
Write the specified manifest.void
writeNestedLibrary(String destination, Library library)
Write a nested library.
Constructor Detail
JarWriter
public JarWriter(File file) throws FileNotFoundException, IOException
Create a newJarWriter
instance.- Parameters:
file
- the file to write- Throws:
IOException
- if the file cannot be openedFileNotFoundException
- if the file cannot be found
JarWriter
public JarWriter(File file, LaunchScript launchScript) throws FileNotFoundException, IOException
Create a newJarWriter
instance.- Parameters:
file
- the file to writelaunchScript
- an optional launch script to prepend to the front of the jar- Throws:
IOException
- if the file cannot be openedFileNotFoundException
- if the file cannot be found
Method Detail
writeManifest
public void writeManifest(Manifest manifest) throws IOException
Write the specified manifest.- Parameters:
manifest
- the manifest to write- Throws:
IOException
- of the manifest cannot be written
writeEntries
public void writeEntries(JarFile jarFile) throws IOException
Write all entries from the specified jar file.- Parameters:
jarFile
- the source jar file- Throws:
IOException
- if the entries cannot be written
writeEntry
public void writeEntry(String entryName, InputStream inputStream) throws IOException
Writes an entry. TheinputStream
is closed once the entry has been written- Specified by:
writeEntry
in interfaceLoaderClassesWriter
- Parameters:
entryName
- The name of the entryinputStream
- The stream from which the entry's data can be read- Throws:
IOException
- if the write fails
writeNestedLibrary
public void writeNestedLibrary(String destination, Library library) throws IOException
Write a nested library.- Parameters:
destination
- the destination of the librarylibrary
- the library- Throws:
IOException
- if the write fails
writeLoaderClasses
public void writeLoaderClasses() throws IOException
Write the required spring-boot-loader classes to the JAR.- Specified by:
writeLoaderClasses
in interfaceLoaderClassesWriter
- Throws:
IOException
- if the classes cannot be written
writeLoaderClasses
public void writeLoaderClasses(String loaderJarResourceName) throws IOException
Write the required spring-boot-loader classes to the JAR.- Specified by:
writeLoaderClasses
in interfaceLoaderClassesWriter
- Parameters:
loaderJarResourceName
- the name of the resource containing the loader classes to be written- Throws:
IOException
- if the classes cannot be written
close
public void close() throws IOException
Close the writer.- Throws:
IOException
- if the file cannot be closed