use of java.util.NoSuchElementException in project camel by apache.
the class TestPublisher method subscribe.
@Override
public void subscribe(Subscriber<? super T> subscriber) {
subscriber.onSubscribe(new Subscription() {
private Iterator<T> it = data.iterator();
private AtomicLong requested = new AtomicLong(0);
private Object monitor = new Object();
@Override
public void request(long l) {
this.requested.addAndGet(l);
new Thread() {
@Override
public void run() {
synchronized (monitor) {
boolean wasNonEmpty = it.hasNext();
while (requested.longValue() > 0 && it.hasNext()) {
T d = it.next();
requested.decrementAndGet();
if (delay > 0) {
try {
Thread.sleep(delay);
} catch (InterruptedException ex) {
}
}
subscriber.onNext(d);
}
if (wasNonEmpty && !it.hasNext()) {
// data cannot be added to this test publisher
subscriber.onComplete();
}
}
}
}.start();
}
@Override
public void cancel() {
synchronized (monitor) {
this.requested.set(0);
this.it = new Iterator<T>() {
@Override
public boolean hasNext() {
return false;
}
@Override
public T next() {
throw new NoSuchElementException();
}
};
new Thread() {
public void run() {
subscriber.onComplete();
}
}.start();
}
}
});
}
use of java.util.NoSuchElementException in project robovm by robovm.
the class BasicHeaderElementIterator method nextElement.
public HeaderElement nextElement() throws NoSuchElementException {
if (this.currentElement == null) {
parseNextElement();
}
if (this.currentElement == null) {
throw new NoSuchElementException("No more header elements available");
}
HeaderElement element = this.currentElement;
this.currentElement = null;
return element;
}
use of java.util.NoSuchElementException in project okhttp by square.
the class Cache method urls.
/**
* Returns an iterator over the URLs in this cache. This iterator doesn't throw {@code
* ConcurrentModificationException}, but if new responses are added while iterating, their URLs
* will not be returned. If existing responses are evicted during iteration, they will be absent
* (unless they were already returned).
*
* <p>The iterator supports {@linkplain Iterator#remove}. Removing a URL from the iterator evicts
* the corresponding response from the cache. Use this to evict selected responses.
*/
public Iterator<String> urls() throws IOException {
return new Iterator<String>() {
final Iterator<DiskLruCache.Snapshot> delegate = cache.snapshots();
String nextUrl;
boolean canRemove;
@Override
public boolean hasNext() {
if (nextUrl != null)
return true;
// Prevent delegate.remove() on the wrong item!
canRemove = false;
while (delegate.hasNext()) {
DiskLruCache.Snapshot snapshot = delegate.next();
try {
BufferedSource metadata = Okio.buffer(snapshot.getSource(ENTRY_METADATA));
nextUrl = metadata.readUtf8LineStrict();
return true;
} catch (IOException ignored) {
// We couldn't read the metadata for this snapshot; possibly because the host filesystem
// has disappeared! Skip it.
} finally {
snapshot.close();
}
}
return false;
}
@Override
public String next() {
if (!hasNext())
throw new NoSuchElementException();
String result = nextUrl;
nextUrl = null;
canRemove = true;
return result;
}
@Override
public void remove() {
if (!canRemove)
throw new IllegalStateException("remove() before next()");
delegate.remove();
}
};
}
use of java.util.NoSuchElementException in project databus by linkedin.
the class EventLogReader method read.
public Checkpoint read() {
Checkpoint checkPoint = new Checkpoint();
checkPoint.setFlexible();
if (_enabled) {
// ArrayList<InternalDatabusEventsListener> eventListeners = new ArrayList<InternalDatabusEventsListener>();
_eventBuffer.addInternalListener(checkPoint);
_eventBuffer.addInternalListener(this);
if (_filesToRead != null) {
for (File f : _filesToRead) {
FileChannel readChannel = null;
try {
readChannel = new FileInputStream(f).getChannel();
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}
int numEvents = 0;
try {
numEvents = _eventBuffer.readEvents(readChannel, getEncoding(f));
} catch (InvalidEventException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
LOG.info("Read " + numEvents + " events");
}
_eventBuffer.removeInternalListener(checkPoint);
_eventBuffer.removeInternalListener(this);
LOG.info("Checkpoint = " + checkPoint);
if (_eventSeen) {
DbusEventIterator iter = _eventBuffer.acquireIterator("EventLogReader:firstEvent");
try {
DbusEvent event = iter.next();
String firstEventContent = event.toString();
// if we didn't wrap the buffer, and the first event is not an eop marker, delete the first window
if (_firstEventContent.equalsIgnoreCase(firstEventContent) && !event.isEndOfPeriodMarker()) {
long result = _eventBuffer.deleteFirstWindow();
if (result < 0) {
throw new RuntimeException("eventBuffer could not delete first window");
}
}
} finally {
_eventBuffer.releaseIterator(iter);
}
if (_lastEopOffset >= 0) {
iter = _eventBuffer.new DbusEventIterator(this._lastEopOffset, _eventBuffer.getTail(), "EventLogReader:lastEOP");
try {
DbusEvent event = iter.next();
if (!event.isEndOfPeriodMarker()) {
throw new RuntimeException("Tried reading end of period marker, but failed");
}
if (iter.hasNext()) {
_eventBuffer.setTail(iter.getCurrentPosition());
}
} catch (NoSuchElementException e) {
LOG.error("NoSuchElementException at : " + _eventBuffer.getBufferPositionParser().toString(_lastEopOffset));
throw e;
} finally {
_eventBuffer.releaseIterator(iter);
}
}
}
}
}
return checkPoint;
}
use of java.util.NoSuchElementException in project zoj by licheng.
the class Main method main.
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
try {
for (; ; ) {
int a = in.nextInt();
int b = in.nextInt();
out.println(a + b);
}
} catch (NoSuchElementException e) {
}
out.close();
}
Aggregations