1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.codehaus.plexus.components.io.resources.proxy;
17
18 import java.io.Closeable;
19 import java.io.IOException;
20 import java.util.Iterator;
21 import java.util.NoSuchElementException;
22
23 import org.codehaus.plexus.components.io.resources.PlexusIoResource;
24
25 abstract class ForwardingIterator implements Iterator<PlexusIoResource>, Closeable {
26 private final Object possiblyCloseable;
27
28 private PlexusIoResource next = null;
29
30 ForwardingIterator(Object possiblyCloseable) {
31 this.possiblyCloseable = possiblyCloseable;
32 }
33
34 public boolean hasNext() {
35 if (next == null) {
36 try {
37 next = getNextResource();
38 } catch (IOException e) {
39 throw new RuntimeException(e);
40 }
41 }
42 return next != null;
43 }
44
45 public PlexusIoResource next() {
46 if (!hasNext()) {
47 throw new NoSuchElementException();
48 }
49 PlexusIoResource ret = next;
50 next = null;
51 return ret;
52 }
53
54 public void remove() {
55 throw new UnsupportedOperationException();
56 }
57
58 public void close() throws IOException {
59 if (possiblyCloseable instanceof Closeable) {
60 ((Closeable) possiblyCloseable).close();
61 }
62 }
63
64
65
66
67 protected abstract PlexusIoResource getNextResource() throws IOException;
68 }