package org.gcube.data.streams.adapters; import gr.uoa.di.madgik.grs.buffer.IBuffer.Status; import gr.uoa.di.madgik.grs.reader.ForwardReader; import gr.uoa.di.madgik.grs.reader.GRS2ReaderException; import gr.uoa.di.madgik.grs.record.Record; import gr.uoa.di.madgik.grs.record.exception.GRS2UncheckedException; import java.net.URI; import java.util.Iterator; import java.util.concurrent.TimeUnit; import org.gcube.data.streams.LookAheadStream; import org.gcube.data.streams.Stream; import org.gcube.data.streams.exceptions.StreamException; import org.gcube.data.streams.exceptions.StreamOpenException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * A {@link Stream} adapter for gRS2 resultsets. *
* This implementation is not thread safe.
*
* @author Fabio Simeoni
*
*/
public class ResultsetStreamnull
.
* */
public ResultsetStream(URI locator) throws IllegalArgumentException {
if (locator==null)
throw new IllegalArgumentException("invalid or null locator");
this.locator=locator;
}
public void setTimeout(long timeout, TimeUnit unit) throws IllegalArgumentException {
if (timeout<=0 || timeoutUnit==null)
throw new IllegalArgumentException("invalid timeout or null timeout unit");
this.timeout = timeout;
this.timeoutUnit = unit;
}
@Override
protected E delegateNext() {
try {
if (lookAheadFailure!=null)
throw lookAheadFailure;
else
try {
return iterator.next();
}
catch(GRS2UncheckedException e) {
//get underlying cause
Throwable cause = e.getCause();
//rewrap checked cause as appropriate to this layer
if (cause instanceof RuntimeException)
throw (RuntimeException) cause;
else
throw new StreamException(cause);
}
}
finally {
lookAheadFailure=null;
}
}
@Override
protected boolean delegateHasNext() {
if (closed)
return false;
if (!open) {
try {
reader = new ForwardReader