01: package com.vividsolutions.jump.io;
02:
03: import com.vividsolutions.jump.feature.*;
04: import com.vividsolutions.jump.io.*;
05: import java.io.*;
06:
07: /**
08: * Base class for FeatureInputStreamReaders.
09: * Handles the details of buffering the stream of features
10: * to allow for lookahead.
11: * This allows subclasses to implement the simpler semantics
12: * of "return null if no more features".
13: *
14: * Subclasses need to define readNext and close.
15: * They also need to set the featureSchema instance variable.
16: */
17: public abstract class BaseFeatureInputStream implements
18: FeatureInputStream {
19: private Feature nextFeature = null;
20:
21: public abstract FeatureSchema getFeatureSchema();
22:
23: public Feature next() throws Exception {
24: if (nextFeature == null)
25: return readNext();
26: Feature currFeature = nextFeature;
27: nextFeature = null;
28: return currFeature;
29: }
30:
31: public boolean hasNext() throws Exception {
32: if (nextFeature == null) {
33: nextFeature = readNext();
34: }
35: return nextFeature != null;
36: }
37:
38: /**
39: * Read the next feature, if any.
40: *
41: * @return the next Feature, or <code>null</code> if there is none
42: * @throws Exception
43: */
44: protected abstract Feature readNext() throws Exception;
45:
46: public abstract void close() throws Exception;
47: }
|