|
@@ -121,12 +121,17 @@ public class ChunkInputStream extends InputStream implements Seekable {
|
|
|
return 0;
|
|
|
}
|
|
|
checkOpen();
|
|
|
- int available = prepareRead(len);
|
|
|
- if (available == EOF) {
|
|
|
- return EOF;
|
|
|
+ int total = 0;
|
|
|
+ while (len > 0) {
|
|
|
+ int available = prepareRead(len);
|
|
|
+ if (available == EOF) {
|
|
|
+ return total != 0 ? total : EOF;
|
|
|
+ }
|
|
|
+ buffers.get(bufferIndex).get(b, off + total, available);
|
|
|
+ len -= available;
|
|
|
+ total += available;
|
|
|
}
|
|
|
- buffers.get(bufferIndex).get(b, off, available);
|
|
|
- return available;
|
|
|
+ return total;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -196,13 +201,20 @@ public class ChunkInputStream extends InputStream implements Seekable {
|
|
|
// next chunk
|
|
|
chunkIndex += 1;
|
|
|
final ReadChunkResponseProto readChunkResponse;
|
|
|
+ final ChunkInfo chunkInfo = chunks.get(chunkIndex);
|
|
|
try {
|
|
|
- readChunkResponse = ContainerProtocolCalls.readChunk(xceiverClient,
|
|
|
- chunks.get(chunkIndex), blockID, traceID);
|
|
|
+ readChunkResponse = ContainerProtocolCalls
|
|
|
+ .readChunk(xceiverClient, chunkInfo, blockID, traceID);
|
|
|
} catch (IOException e) {
|
|
|
throw new IOException("Unexpected OzoneException: " + e.toString(), e);
|
|
|
}
|
|
|
ByteString byteString = readChunkResponse.getData();
|
|
|
+ if (byteString.size() != chunkInfo.getLen()) {
|
|
|
+ // Bytes read from chunk should be equal to chunk size.
|
|
|
+ throw new IOException(String
|
|
|
+ .format("Inconsistent read for chunk=%s len=%d bytesRead=%d",
|
|
|
+ chunkInfo.getChunkName(), chunkInfo.getLen(), byteString.size()));
|
|
|
+ }
|
|
|
buffers = byteString.asReadOnlyByteBufferList();
|
|
|
bufferIndex = 0;
|
|
|
}
|
|
@@ -260,4 +272,8 @@ public class ChunkInputStream extends InputStream implements Seekable {
|
|
|
public boolean seekToNewSource(long targetPos) throws IOException {
|
|
|
return false;
|
|
|
}
|
|
|
+
|
|
|
+ public BlockID getBlockID() {
|
|
|
+ return blockID;
|
|
|
+ }
|
|
|
}
|