HDDS-416. Remove currentPosition from ChunkInputStreamEntry. Contributed by Lokesh Jain.

This commit is contained in:
Xiaoyu Yao 2018-09-11 15:12:59 -07:00
parent 598380ad5a
commit 1d567c25d0
1 changed files with 3 additions and 7 deletions

View File

@ -71,7 +71,7 @@ public class ChunkGroupInputStream extends InputStream implements Seekable {
} }
@VisibleForTesting @VisibleForTesting
public long getRemainingOfIndex(int index) { public long getRemainingOfIndex(int index) throws IOException {
return streamEntries.get(index).getRemaining(); return streamEntries.get(index).getRemaining();
} }
@ -206,31 +206,27 @@ public class ChunkGroupInputStream extends InputStream implements Seekable {
private final ChunkInputStream chunkInputStream; private final ChunkInputStream chunkInputStream;
private final long length; private final long length;
private long currentPosition;
public ChunkInputStreamEntry(ChunkInputStream chunkInputStream, public ChunkInputStreamEntry(ChunkInputStream chunkInputStream,
long length) { long length) {
this.chunkInputStream = chunkInputStream; this.chunkInputStream = chunkInputStream;
this.length = length; this.length = length;
this.currentPosition = 0;
} }
synchronized long getRemaining() { synchronized long getRemaining() throws IOException {
return length - currentPosition; return length - getPos();
} }
@Override @Override
public synchronized int read(byte[] b, int off, int len) public synchronized int read(byte[] b, int off, int len)
throws IOException { throws IOException {
int readLen = chunkInputStream.read(b, off, len); int readLen = chunkInputStream.read(b, off, len);
currentPosition += readLen;
return readLen; return readLen;
} }
@Override @Override
public synchronized int read() throws IOException { public synchronized int read() throws IOException {
int data = chunkInputStream.read(); int data = chunkInputStream.read();
currentPosition += 1;
return data; return data;
} }