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:
parent
f16565bfb1
commit
d25952b58c
1 changed files with 6 additions and 32 deletions
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue