Commit c56fbf8c authored by Andy Wilkinson's avatar Andy Wilkinson

Allow Archives to be closed so they can release resources

Closes gh-17126
parent 4748626f
......@@ -30,7 +30,7 @@ import org.springframework.boot.loader.Launcher;
* @author Phillip Webb
* @see JarFileArchive
*/
public interface Archive extends Iterable<Archive.Entry> {
public interface Archive extends Iterable<Archive.Entry>, AutoCloseable {
/**
* Returns a URL that can be used to load the archive.
......@@ -54,6 +54,16 @@ public interface Archive extends Iterable<Archive.Entry> {
*/
List<Archive> getNestedArchives(EntryFilter filter) throws IOException;
/**
* Closes the {@code Archive}, releasing any open resources.
* @throws Exception if an error occurs during close processing
* @since 2.2.0
*/
@Override
default void close() throws Exception {
}
/**
* Represents a single entry in the archive.
*/
......
......@@ -94,6 +94,11 @@ public class JarFileArchive implements Archive {
return new EntryIterator(this.jarFile.entries());
}
@Override
public void close() throws IOException {
this.jarFile.close();
}
protected Archive getNestedArchive(Entry entry) throws IOException {
JarEntry jarEntry = ((JarFileEntry) entry).getJarEntry();
if (jarEntry.getComment().startsWith(UNPACK_MARKER)) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment