List of usage examples for java.util Iterator Iterator
Iterator
From source file:io.druid.firehose.oss.StaticOSSFirehoseFactory.java
@Override public Firehose connect(StringInputRowParser firehoseParser) throws IOException { Preconditions.checkNotNull(ossClient, "null ossClient"); final LinkedList<URI> objectQueue = Lists.newLinkedList(uris); return new FileIteratingFirehose(new Iterator<LineIterator>() { @Override//w ww .j a va2 s . c o m public boolean hasNext() { return !objectQueue.isEmpty(); } @Override public LineIterator next() { final URI nextURI = objectQueue.poll(); final String bucket = nextURI.getAuthority(); final String key = nextURI.getPath().startsWith("/") ? nextURI.getPath().substring(1) : nextURI.getPath(); log.info("reading from bucket[%s] object[%s] (%s)", bucket, key, nextURI); try { final InputStream innerInputStream = ossClient.getObject(bucket, key).getObjectContent(); final InputStream outerInputStream = key.endsWith(".gz") ? CompressionUtils.gzipInputStream(innerInputStream) : innerInputStream; return IOUtils.lineIterator( new BufferedReader(new InputStreamReader(outerInputStream, Charsets.UTF_8))); } catch (Exception e) { log.error(e, "exception reading from bucket[%s] object[%s]", bucket, key); throw Throwables.propagate(e); } } @Override public void remove() { throw new UnsupportedOperationException(); } }, firehoseParser); }
From source file:io.druid.firehose.cloudfiles.StaticCloudFilesFirehoseFactory.java
@Override public Firehose connect(StringInputRowParser stringInputRowParser) throws IOException, ParseException { Preconditions.checkNotNull(cloudFilesApi, "null cloudFilesApi"); final LinkedList<CloudFilesBlob> objectQueue = Lists.newLinkedList(blobs); return new FileIteratingFirehose(new Iterator<LineIterator>() { @Override// w ww . j a v a 2 s . c om public boolean hasNext() { return !objectQueue.isEmpty(); } @Override public LineIterator next() { final CloudFilesBlob nextURI = objectQueue.poll(); final String region = nextURI.getRegion(); final String container = nextURI.getContainer(); final String path = nextURI.getPath(); log.info("Retrieving file from region[%s], container[%s] and path [%s]", region, container, path); CloudFilesObjectApiProxy objectApi = new CloudFilesObjectApiProxy(cloudFilesApi, region, container); final CloudFilesByteSource byteSource = new CloudFilesByteSource(objectApi, path); try { final InputStream innerInputStream = byteSource.openStream(); final InputStream outerInputStream = path.endsWith(".gz") ? CompressionUtils.gzipInputStream(innerInputStream) : innerInputStream; return IOUtils.lineIterator( new BufferedReader(new InputStreamReader(outerInputStream, Charsets.UTF_8))); } catch (IOException e) { log.error(e, "Exception opening container[%s] blob[%s] from region[%s]", container, path, region); throw Throwables.propagate(e); } } @Override public void remove() { throw new UnsupportedOperationException(); } }, stringInputRowParser); }
From source file:io.druid.segment.realtime.firehose.LocalFirehoseFactory.java
@Override public Firehose connect(StringInputRowParser firehoseParser) throws IOException { log.info("Searching for all [%s] in and beneath [%s]", filter, baseDir.getAbsoluteFile()); Collection<File> foundFiles = FileUtils.listFiles(baseDir.getAbsoluteFile(), new WildcardFileFilter(filter), TrueFileFilter.INSTANCE);/*from w w w . ja v a 2s. c o m*/ if (foundFiles == null || foundFiles.isEmpty()) { throw new ISE("Found no files to ingest! Check your schema."); } log.info("Found files: " + foundFiles); final LinkedList<File> files = Lists.newLinkedList(foundFiles); return new FileIteratingFirehose(new Iterator<LineIterator>() { @Override public boolean hasNext() { return !files.isEmpty(); } @Override public LineIterator next() { try { return FileUtils.lineIterator(files.poll()); } catch (Exception e) { throw Throwables.propagate(e); } } @Override public void remove() { throw new UnsupportedOperationException(); } }, firehoseParser); }
From source file:org.apache.hadoop.hbase.rest.TableScanResource.java
@GET @Produces({ Constants.MIMETYPE_XML, Constants.MIMETYPE_JSON }) public CellSetModelStream get(final @Context UriInfo uriInfo) { servlet.getMetrics().incrementRequests(1); final int rowsToSend = userRequestedLimit; servlet.getMetrics().incrementSucessfulScanRequests(1); final Iterator<Result> itr = results.iterator(); return new CellSetModelStream(new ArrayList<RowModel>() { public Iterator<RowModel> iterator() { return new Iterator<RowModel>() { int count = rowsToSend; @Override//from www. j a v a 2s .com public boolean hasNext() { if (count > 0) { return itr.hasNext(); } else { return false; } } @Override public void remove() { throw new UnsupportedOperationException( "Remove method cannot be used in CellSetModelStream"); } @Override public RowModel next() { Result rs = itr.next(); if ((rs == null) || (count <= 0)) { return null; } byte[] rowKey = rs.getRow(); RowModel rModel = new RowModel(rowKey); List<Cell> kvs = rs.listCells(); for (Cell kv : kvs) { rModel.addCell(new CellModel(CellUtil.cloneFamily(kv), CellUtil.cloneQualifier(kv), kv.getTimestamp(), CellUtil.cloneValue(kv))); } count--; return rModel; } }; } }); }
From source file:edu.dfci.cccb.mev.deseq.domain.simple.FileBackedDESeq.java
private Iterable<Entry> iterateEntries(final File file) { return new Iterable<Entry>() { /* (non-Javadoc) * @see java.lang.Iterable#iterator() */ @Override//w w w. j a v a2 s . com @SneakyThrows(IOException.class) public Iterator<Entry> iterator() { return new Iterator<Entry>() { private final BufferedReader reader = new BufferedReader(new FileReader(file)); private String current = null; @Override @Synchronized @SneakyThrows(IOException.class) public boolean hasNext() { return current == null ? (current = reader.readLine()) != null : true; } @Override @Synchronized public Entry next() { hasNext(); Entry result = parse(current); current = null; return result; } @Override public void remove() { throw new UnsupportedOperationException(); } }; } }; }
From source file:com.neoprojectmanager.model.NodeWrapper.java
/** * Creates an Iterator of NodeWrapper that iterates over the node returned * traversing the specified relationship starting from the given node. * /*from w w w.j av a 2 s .c o m*/ * @param <T> * @param nodeWrapperClass * @param gdbs * @param node * @param order * @param stopEv * @param retEv * @param relTuple * @return */ public static <T extends NodeWrapper> Iterator<T> getNodeWrapperIterator(final Class<T> nodeWrapperClass, final GraphDatabaseService gdbs, final Node node, final Order order, final StopEvaluator stopEv, final ReturnableEvaluator retEv, final RelTup... relTuple) { return new Iterator<T>() { /** * WARNING: checking that the nodes returned from this traverser are * correctly managed by the NodeWrapper class specified can be * performed only at runtime. */ private final Iterator<Node> iterator = node.traverse(order, stopEv, retEv, flattenRelTuples(relTuple)) .iterator(); public boolean hasNext() { return iterator.hasNext(); } public T next() { Node nextNode = iterator.next(); try { return nodeWrapperClass.getDeclaredConstructor(Node.class, GraphDatabaseService.class) .newInstance(nextNode, gdbs); } catch (Exception e) { e.printStackTrace(); return null; } } public void remove() { throw new NotImplementedException("This method is not allowed."); } }; }
From source file:org.apache.ambari.server.serveraction.kerberos.AbstractKerberosDataFileReader.java
/** * Gets an iterator to use to access the records in the data file. * <p/>//from w w w . j a v a 2 s .co m * Each item is a Map of column names to values. * * @return an Iterator of records from the data file, each record is represented as a Map of * column name (String) to column value (String) */ @Override public Iterator<Map<String, String>> iterator() { return new Iterator<Map<String, String>>() { Iterator<CSVRecord> iterator = (csvParser == null) ? null : csvParser.iterator(); @Override public boolean hasNext() { return (iterator != null) && iterator.hasNext(); } @Override public Map<String, String> next() { return (iterator == null) ? null : iterator.next().toMap(); } @Override public void remove() { if (iterator != null) { iterator.remove(); } } }; }
From source file:com.wrmsr.kleist.util.Itertools.java
public static <T> Iterator<EnumeratedElement<T>> enumerate(Iterator<T> iterator) { return new Iterator<EnumeratedElement<T>>() { private int index = 0; @Override/* w ww .j a v a 2 s. c om*/ public boolean hasNext() { return iterator.hasNext(); } @Override public EnumeratedElement<T> next() { return new EnumeratedElement<>(index++, iterator.next()); } }; }
From source file:org.commonjava.cartographer.graph.spi.jung.model.JungGraphPath.java
@Override public Iterator<ProjectRelationship<?, ?>> iterator() { return new Iterator<ProjectRelationship<?, ?>>() { private int next = 0; @Override/*from ww w.j a v a2s.c om*/ public boolean hasNext() { return rels.length > next; } @Override public ProjectRelationship<?, ?> next() { return rels[next++]; } @Override public void remove() { throw new UnsupportedOperationException("Immutable array of GAV's. Remove not supported."); } }; }
From source file:jef.tools.ArrayUtils.java
/** * CharSequence????char/*from w w w. ja v a 2 s. c o m*/ * ?CharBuffer,StringBuilder,StringbufferIterator??? * * @param e * @return */ public static Iterable<Character> toIterable(final CharSequence e) { return new Iterable<Character>() { public Iterator<Character> iterator() { return new Iterator<Character>() { int n = 0; public boolean hasNext() { return n < e.length(); } public Character next() { return e.charAt(n++); } public void remove() { throw new UnsupportedOperationException(); } }; } }; }