Allow Archives to be closed so they can release resources
Closes gh-17126
This commit is contained in:
parent
4748626f45
commit
c56fbf8c3d
|
|
@ -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)) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue