use of io.pravega.client.segment.impl.EndOfSegmentException in project pravega by pravega.
the class EventStreamReaderImpl method fetchEvent.
@Override
public Type fetchEvent(EventPointer pointer) throws NoSuchEventException {
Preconditions.checkNotNull(pointer);
// Create SegmentInputStream
@Cleanup EventSegmentReader inputStream = inputStreamFactory.createEventReaderForSegment(pointer.asImpl().getSegment(), pointer.asImpl().getEventLength());
inputStream.setOffset(pointer.asImpl().getEventStartOffset());
// Read event
try {
ByteBuffer buffer = inputStream.read();
return deserializer.deserialize(buffer);
} catch (EndOfSegmentException e) {
throw new NoSuchEventException(e.getMessage());
} catch (NoSuchSegmentException | SegmentTruncatedException e) {
throw new NoSuchEventException("Event no longer exists.");
}
}
use of io.pravega.client.segment.impl.EndOfSegmentException in project pravega by pravega.
the class ByteStreamReaderImpl method read.
@Override
public int read() throws IOException {
Exceptions.checkNotClosed(closed.get(), this);
ByteBuffer buffer = ByteBuffer.allocate(1);
try {
int read;
synchronized (input) {
read = input.read(buffer, Long.MAX_VALUE);
}
if (read > 0) {
buffer.flip();
return buffer.get() & 0xFF;
} else {
return read;
}
} catch (EndOfSegmentException e) {
return -1;
}
}
use of io.pravega.client.segment.impl.EndOfSegmentException in project pravega by pravega.
the class MockSegmentIoStreams method read.
/**
* Event read.
* @see io.pravega.client.segment.impl.EventSegmentReader#read(long)
*/
@Override
@Synchronized
public ByteBuffer read(long timeout) throws EndOfSegmentException, SegmentTruncatedException {
if (readOffset >= writeOffset) {
throw new EndOfSegmentException();
}
if (readOffset < startingOffset) {
throw new SegmentTruncatedException("Data below " + startingOffset + " has been truncated");
}
ByteBuffer buffer = dataWritten.floorEntry(readOffset).getValue();
readOffset += buffer.remaining();
ByteBuffer result = buffer.slice();
result.position(WireCommands.TYPE_PLUS_LENGTH_SIZE);
return result;
}
Aggregations