use of com.google.common.collect.AbstractIterator in project presto by prestodb.
the class PagesIndex method getSortedPages.
public Iterator<Page> getSortedPages() {
return new AbstractIterator<Page>() {
private int currentPosition;
private final PageBuilder pageBuilder = new PageBuilder(types);
private final int[] outputChannels = new int[types.size()];
{
Arrays.setAll(outputChannels, IntUnaryOperator.identity());
}
@Override
public Page computeNext() {
currentPosition = buildPage(currentPosition, outputChannels, pageBuilder);
if (pageBuilder.isEmpty()) {
return endOfData();
}
Page page = pageBuilder.build();
pageBuilder.reset();
return page;
}
};
}
use of com.google.common.collect.AbstractIterator in project presto by prestodb.
the class FileFragmentResultCacheManager method closeWhenExhausted.
private static <T> Iterator<T> closeWhenExhausted(Iterator<T> iterator, Closeable resource) {
requireNonNull(iterator, "iterator is null");
requireNonNull(resource, "resource is null");
return new AbstractIterator<T>() {
@Override
protected T computeNext() {
if (iterator.hasNext()) {
return iterator.next();
}
try {
resource.close();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
return endOfData();
}
};
}
use of com.google.common.collect.AbstractIterator in project presto by prestodb.
the class FileSingleStreamSpiller method closeWhenExhausted.
private static <T> Iterator<T> closeWhenExhausted(Iterator<T> iterator, Closeable resource) {
requireNonNull(iterator, "iterator is null");
requireNonNull(resource, "resource is null");
return new AbstractIterator<T>() {
@Override
protected T computeNext() {
if (iterator.hasNext()) {
return iterator.next();
}
try {
resource.close();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
return endOfData();
}
};
}
use of com.google.common.collect.AbstractIterator in project voldemort by voldemort.
the class AdminCommandStream method readEntriesBinary.
private static Iterator<Pair<ByteArray, Versioned<byte[]>>> readEntriesBinary(File inputDir, String storeName) throws IOException {
File inputFile = new File(inputDir, storeName + ".entries");
if (!inputFile.exists()) {
throw new FileNotFoundException("File " + inputFile.getAbsolutePath() + " does not exist!");
}
final DataInputStream dis = new DataInputStream(new BufferedInputStream(new FileInputStream(inputFile)));
return new AbstractIterator<Pair<ByteArray, Versioned<byte[]>>>() {
@Override
protected Pair<ByteArray, Versioned<byte[]>> computeNext() {
try {
int length = dis.readInt();
byte[] keyBytes = new byte[length];
ByteUtils.read(dis, keyBytes);
length = dis.readInt();
byte[] versionBytes = new byte[length];
ByteUtils.read(dis, versionBytes);
length = dis.readInt();
byte[] valueBytes = new byte[length];
ByteUtils.read(dis, valueBytes);
ByteArray key = new ByteArray(keyBytes);
VectorClock version = new VectorClock(versionBytes);
Versioned<byte[]> value = new Versioned<byte[]>(valueBytes, version);
return new Pair<ByteArray, Versioned<byte[]>>(key, value);
} catch (EOFException e) {
try {
dis.close();
} catch (IOException ie) {
ie.printStackTrace();
}
return endOfData();
} catch (IOException e) {
try {
dis.close();
} catch (IOException ie) {
ie.printStackTrace();
}
throw new VoldemortException("Error reading from input file ", e);
}
}
};
}
use of com.google.common.collect.AbstractIterator in project xtext-core by eclipse.
the class SemanticRegionIterable method iterator.
@Override
public Iterator<ISemanticRegion> iterator() {
return new AbstractIterator<ISemanticRegion>() {
private ISemanticRegion next = first;
@Override
protected ISemanticRegion computeNext() {
if (next == null)
return endOfData();
ISemanticRegion result = next;
next = next.getNextSemanticRegion();
if (result == last)
next = null;
return result;
}
};
}
Aggregations