Class DefaultDataBag<E>
- java.lang.Object
-
- org.apache.jena.atlas.data.AbstractDataBag<E>
-
- org.apache.jena.atlas.data.DefaultDataBag<E>
-
- All Implemented Interfaces:
java.lang.Iterable<E>,DataBag<E>,org.apache.jena.atlas.lib.Closeable,org.apache.jena.atlas.lib.Sink<E>
public class DefaultDataBag<E> extends AbstractDataBag<E>
This data bag will gather items in memory until a size threshold is passed, at which point it will write out all of the items to disk using the supplied serializer.
After adding is finished, call
iterator()to set up the data bag for reading back items and iterating over them.IMPORTANT: You may not add any more items after this call. You may subsequently call
iterator()multiple times which will give you a new iterator for each invocation. If you do not consume the entire iterator, you should callIter.close(Iterator)to close any FileInputStreams associated with the iterator.Additionally, make sure to call
close()when you are finished to free any system resources (preferably in a finally block).Implementation Notes: Data is stored in an ArrayList as it comes in. When it is time to spill, that data is written to disk. Additional data is appended directly to that file for the rest of the add phase. Creating an iterator will read all the data out of that single file.
-
-
Constructor Summary
Constructors Constructor Description DefaultDataBag(ThresholdPolicy<E> policy, SerializationFactory<E> serializerFactory)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(E item)Add a tuple to the bag.voidclose()voidflush()booleanisDistinct()Find out if the bag is distinct.booleanisSorted()Find out if the bag is sorted.java.util.Iterator<E>iterator()-
Methods inherited from class org.apache.jena.atlas.data.AbstractDataBag
isEmpty, send, size
-
-
-
-
Constructor Detail
-
DefaultDataBag
public DefaultDataBag(ThresholdPolicy<E> policy, SerializationFactory<E> serializerFactory)
-
-
Method Detail
-
add
public void add(E item)
Description copied from interface:DataBagAdd a tuple to the bag.- Parameters:
item- tuple to add.
-
isSorted
public boolean isSorted()
Description copied from interface:DataBagFind out if the bag is sorted.- Returns:
- true if this is a sorted data bag, false otherwise.
-
isDistinct
public boolean isDistinct()
Description copied from interface:DataBagFind out if the bag is distinct.- Returns:
- true if the bag is a distinct bag, false otherwise.
-
flush
public void flush()
-
iterator
public java.util.Iterator<E> iterator()
-
close
public void close()
-
-