Java Code Examples for org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils#limit()

The following examples show how to use org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils#limit() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FileSystemStorage.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Override
public Iterator<String> head(final String location, final int totalLines) {
    try {
        return IteratorUtils.limit((Iterator) new TextIterator(this.fs.getConf(), new Path(location)), totalLines);
    } catch (final IOException e) {
        throw new IllegalStateException(e.getMessage(), e);
    }
}
 
Example 2
Source File: FileSystemStorage.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Override
public Iterator<Vertex> head(final String location, final Class readerClass, final int totalLines) {
    final org.apache.commons.configuration2.Configuration configuration = new BaseConfiguration();
    configuration.setProperty(Constants.GREMLIN_HADOOP_INPUT_LOCATION, Constants.getSearchGraphLocation(location, this).get());
    configuration.setProperty(Constants.GREMLIN_HADOOP_GRAPH_READER, readerClass.getCanonicalName());
    try {
        if (InputFormat.class.isAssignableFrom(readerClass))
            return IteratorUtils.limit(new HadoopVertexIterator(HadoopGraph.open(configuration)), totalLines);
    } catch (final IOException e) {
        throw new IllegalStateException(e.getMessage(), e);
    }
    throw new IllegalArgumentException("The provided parser class must be an " + InputFormat.class.getCanonicalName() + ": " + readerClass.getCanonicalName());

}
 
Example 3
Source File: FileSystemStorage.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Override
public <K, V> Iterator<KeyValue<K, V>> head(final String location, final String memoryKey, final Class readerClass, final int totalLines) {
    if (!readerClass.equals(SequenceFileInputFormat.class))
        throw new IllegalArgumentException("Only " + SequenceFileInputFormat.class.getCanonicalName() + " memories are supported");
    final Configuration configuration = new Configuration();
    try {
        return IteratorUtils.limit((Iterator) new ObjectWritableIterator(configuration, new Path(Constants.getMemoryLocation(location, memoryKey))), totalLines);
    } catch (final IOException e) {
        throw new IllegalStateException(e.getMessage(), e);
    }
}