22
33import software .coley .llzip .util .OffsetComparator ;
44
5+ import java .io .Closeable ;
56import java .util .ArrayList ;
67import java .util .List ;
78import java .util .function .Predicate ;
1213 *
1314 * @author Matt Coley
1415 */
15- public class ZipArchive {
16+ public class ZipArchive implements AutoCloseable {
1617 private final List <ZipPart > parts = new ArrayList <>();
18+ private final Closeable closableBackingResource ;
19+
20+ /**
21+ * @param closableBackingResource
22+ * Closable resource backing the zip archive.
23+ */
24+ public ZipArchive (Closeable closableBackingResource ) {
25+ this .closableBackingResource = closableBackingResource ;
26+ }
1727
1828 /**
1929 * @return All parts of the zip archive.
@@ -95,6 +105,13 @@ public EndOfCentralDirectory getEnd() {
95105 .findFirst ().orElse (null );
96106 }
97107
108+ /**
109+ * @return Closable resource backing the zip archive.
110+ */
111+ protected Closeable getClosableBackingResource () {
112+ return closableBackingResource ;
113+ }
114+
98115 @ Override
99116 public boolean equals (Object o ) {
100117 if (this == o ) return true ;
@@ -109,4 +126,10 @@ public boolean equals(Object o) {
109126 public int hashCode () {
110127 return parts .hashCode ();
111128 }
129+
130+ @ Override
131+ public void close () throws Exception {
132+ if (closableBackingResource != null )
133+ closableBackingResource .close ();
134+ }
112135}
0 commit comments