1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-06 03:50:19 +02:00

inheritance instead of aggregation

This commit is contained in:
Nikolay Pultsin 2011-04-11 22:11:55 +01:00
parent f16565bfb1
commit d25952b58c

View file

@ -22,51 +22,25 @@ package org.geometerplus.zlibrary.core.util;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
public class SliceInputStream extends InputStream { public class SliceInputStream extends ZLInputStreamWithOffset {
private final ZLInputStreamWithOffset myBase;
private final int myStart; private final int myStart;
private final int myLength; private final int myLength;
public SliceInputStream(InputStream base, int start, int length) throws IOException { public SliceInputStream(InputStream base, int start, int length) throws IOException {
myBase = new ZLInputStreamWithOffset(base); super(base);
myBase.skip(start); super.skip(start);
myStart = start; myStart = start;
myLength = length; myLength = length;
} }
@Override @Override
public int available() throws IOException { public int available() throws IOException {
return Math.min(myBase.available(), Math.max(myStart + myLength - myBase.offset(), 0)); return Math.min(super.available(), Math.max(myStart + myLength - super.offset(), 0));
}
@Override
public long skip(long n) throws IOException {
return myBase.skip(n);
}
@Override
public int read() throws IOException {
return myBase.read();
}
@Override
public void close() throws IOException {
myBase.close();
}
@Override
public int read(byte[] b, int off, int len) throws IOException {
return myBase.read(b, off, len);
}
@Override
public int read(byte[] b) throws IOException {
return myBase.read(b);
} }
@Override @Override
public void reset() throws IOException { public void reset() throws IOException {
myBase.reset(); super.reset();
myBase.skip(myStart); super.skip(myStart);
} }
} }