use of com.mongodb.MongoSocketReadException in project mongo-java-driver by mongodb.
the class SocketChannelStream method read.
@Override
public ByteBuf read(final int numBytes) throws IOException {
ByteBuf buffer = bufferProvider.getBuffer(numBytes);
isTrue("open", !isClosed());
int totalBytesRead = 0;
while (totalBytesRead < buffer.limit()) {
int bytesRead = socketChannel.read(buffer.asNIO());
if (bytesRead == -1) {
buffer.release();
throw new MongoSocketReadException("Prematurely reached end of stream", getAddress());
}
totalBytesRead += bytesRead;
}
return buffer.flip();
}
use of com.mongodb.MongoSocketReadException in project mongo-java-driver by mongodb.
the class SocketStream method read.
@Override
public ByteBuf read(final int numBytes) throws IOException {
ByteBuf buffer = bufferProvider.getBuffer(numBytes);
int totalBytesRead = 0;
byte[] bytes = buffer.array();
while (totalBytesRead < buffer.limit()) {
int bytesRead = inputStream.read(bytes, totalBytesRead, buffer.limit() - totalBytesRead);
if (bytesRead == -1) {
buffer.release();
throw new MongoSocketReadException("Prematurely reached end of stream", getAddress());
}
totalBytesRead += bytesRead;
}
return buffer;
}
Aggregations