org.schwa.dr
Class Reader<T extends Doc>

java.lang.Object
  extended by org.schwa.dr.Reader<T>
All Implemented Interfaces:
Iterable<T>, Iterator<T>

public final class Reader<T extends Doc>
extends Object
implements Iterable<T>, Iterator<T>

Reads in docrep documents of type T from the input stream provided in the constructor. This class implements the Iterator interface, providing an interator for that yields documents of type T.

Author:
Tim Dawborn

Field Summary
static byte WIRE_VERSION
          docrep wire protocol version that this reader knows how to read.
 
Constructor Summary
Reader(ByteArrayInputStream in, DocSchema docSchema)
          Constructs a new docrep reader given the input stream and document schema.
 
Method Summary
 boolean hasNext()
          Returns whether or not the reader iterator has any more documents to read in from the input stream.
 Iterator<T> iterator()
          Returns this same object as an Iterator to comply with the Iterable interface.
 T next()
          Reads the next document from the input stream and returns it.
 void remove()
          This optional method from Iterator is unsupported.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

WIRE_VERSION

public static final byte WIRE_VERSION
docrep wire protocol version that this reader knows how to read.

See Also:
Constant Field Values
Constructor Detail

Reader

public Reader(ByteArrayInputStream in,
              DocSchema docSchema)
Constructs a new docrep reader given the input stream and document schema.

Parameters:
in - The input stream to read from. This needs to be an input stream which has full InputStream.mark(int) support to implement lazy loading correctly. To ensure this is the case, the input stream must currently be a ByteArrayInputStream.
docSchema - The DocSchema instance to use for reading. Unlike the other docrep APIs, this argument cannot be optional as you cannot be the .class attribute of a generic type due to type erasure.
Method Detail

iterator

public Iterator<T> iterator()
Returns this same object as an Iterator to comply with the Iterable interface.

Specified by:
iterator in interface Iterable<T extends Doc>

hasNext

public boolean hasNext()
Returns whether or not the reader iterator has any more documents to read in from the input stream.

Specified by:
hasNext in interface Iterator<T extends Doc>

next

public T next()
Reads the next document from the input stream and returns it.

Specified by:
next in interface Iterator<T extends Doc>

remove

public void remove()
This optional method from Iterator is unsupported.

Specified by:
remove in interface Iterator<T extends Doc>
Throws:
UnsupportedOperationException


Copyright © 2014. All rights reserved.