|
1 | 1 | /*
|
2 |
| - * Copyright (c) 1996, 2024, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 1996, 2025, Oracle and/or its affiliates. All rights reserved. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
4 | 4 | *
|
5 | 5 | * This code is free software; you can redistribute it and/or modify it
|
|
31 | 31 | import java.io.OutputStream;
|
32 | 32 | import java.io.PushbackInputStream;
|
33 | 33 | import java.nio.charset.Charset;
|
| 34 | +import java.util.Iterator; |
| 35 | +import java.util.NoSuchElementException; |
34 | 36 | import java.util.Objects;
|
35 | 37 |
|
36 | 38 | import sun.nio.cs.UTF_8;
|
|
75 | 77 | * @author David Connelly
|
76 | 78 | * @since 1.1
|
77 | 79 | */
|
78 |
| -public class ZipInputStream extends InflaterInputStream implements ZipConstants { |
| 80 | +public class ZipInputStream extends InflaterInputStream implements ZipConstants, Iterable { |
79 | 81 | private ZipEntry entry;
|
80 | 82 | private int flag;
|
81 | 83 | private CRC32 crc = new CRC32();
|
@@ -488,6 +490,25 @@ public void close() throws IOException {
|
488 | 490 | }
|
489 | 491 | }
|
490 | 492 |
|
| 493 | + public Iterator<ZipEntry> iterator() { |
| 494 | + return new Iterator<ZipEntry>() { |
| 495 | + private ZipEntry nextEntry; |
| 496 | + |
| 497 | + public boolean hasNext() { |
| 498 | + if (nextEntry == null) |
| 499 | + nextEntry = getNextEntry(); |
| 500 | + return nextEntry != null; |
| 501 | + } |
| 502 | + |
| 503 | + public ZipEntry next() { |
| 504 | + if (!hasNext()) |
| 505 | + throw new NoSuchElementException(); |
| 506 | + |
| 507 | + return currentEntry; |
| 508 | + } |
| 509 | + } |
| 510 | + } |
| 511 | + |
491 | 512 | private byte[] b = new byte[256];
|
492 | 513 |
|
493 | 514 | /*
|
|
0 commit comments