use of io.pravega.shared.protocol.netty.InvalidMessageException in project pravega by pravega.
the class SegmentInputStreamImpl method readEventData.
private ByteBuffer readEventData(long timeout) throws EndOfSegmentException, SegmentTruncatedException {
fillBuffer();
if (receivedTruncated) {
throw new SegmentTruncatedException();
}
while (buffer.dataAvailable() < WireCommands.TYPE_PLUS_LENGTH_SIZE) {
if (buffer.dataAvailable() == 0 && receivedEndOfSegment) {
throw new EndOfSegmentException();
}
Futures.await(outstandingRequest, timeout);
if (!outstandingRequest.isDone()) {
return null;
}
handleRequest();
}
headerReadingBuffer.clear();
offset += buffer.read(headerReadingBuffer);
headerReadingBuffer.flip();
int type = headerReadingBuffer.getInt();
int length = headerReadingBuffer.getInt();
if (type != WireCommandType.EVENT.getCode()) {
throw new InvalidMessageException("Event was of wrong type: " + type);
}
if (length < 0 || length > WireCommands.MAX_WIRECOMMAND_SIZE) {
throw new InvalidMessageException("Event of invalid length: " + length);
}
ByteBuffer result = ByteBuffer.allocate(length);
offset += buffer.read(result);
while (result.hasRemaining()) {
issueRequestIfNeeded();
handleRequest();
offset += buffer.read(result);
}
result.flip();
return result;
}
use of io.pravega.shared.protocol.netty.InvalidMessageException in project pravega by pravega.
the class EventSegmentReaderImpl method readEvent.
private ByteBuffer readEvent(long firstByteTimeoutMillis) throws EndOfSegmentException, SegmentTruncatedException, TimeoutException {
headerReadingBuffer.clear();
int read = in.read(headerReadingBuffer, firstByteTimeoutMillis);
if (read == 0) {
// a resend will not be triggered in-case of a firstByteTimeout.
return null;
}
while (headerReadingBuffer.hasRemaining()) {
readEventDataFromSegmentInputStream(headerReadingBuffer);
}
headerReadingBuffer.flip();
int type = headerReadingBuffer.getInt();
int length = headerReadingBuffer.getInt();
if (type != WireCommandType.EVENT.getCode()) {
throw new InvalidMessageException("Event was of wrong type: " + type);
}
if (length < 0) {
throw new InvalidMessageException("Event of invalid length: " + length);
}
ByteBuffer result = ByteBuffer.allocate(length);
readEventDataFromSegmentInputStream(result);
while (result.hasRemaining()) {
readEventDataFromSegmentInputStream(result);
}
result.flip();
return result;
}
Aggregations