- int size = snapshotChunkSize;
- if (snapshotChunkSize > snapshotLength) {
- size = snapshotLength;
- } else if ((start + snapshotChunkSize) > snapshotLength) {
- size = snapshotLength - start;
+ if (replyStatus || currentChunk == null) {
+ int size = snapshotChunkSize;
+ if (snapshotChunkSize > snapshotSize) {
+ size = (int) snapshotSize;
+ } else if (start + snapshotChunkSize > snapshotSize) {
+ size = (int) (snapshotSize - start);
+ }
+
+ currentChunk = new byte[size];
+ int numRead = snapshotInputStream.read(currentChunk);
+ if (numRead != size) {
+ throw new IOException(String.format(
+ "The # of bytes read from the input stream, %d,"
+ + "does not match the expected # %d", numRead, size));
+ }
+
+ nextChunkHashCode = Arrays.hashCode(currentChunk);
+
+ LOG.debug("{}: Next chunk: total length={}, offset={}, size={}, hashCode={}", logName,
+ snapshotSize, start, size, nextChunkHashCode);