提交 1feb1949 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Use IOUtils.skipFully()

上级 5185d722
package org.h2.store; package org.h2.store;
import java.io.EOFException;
import java.io.FilterInputStream; import java.io.FilterInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import org.h2.util.IOUtils;
public final class RangeInputStream extends FilterInputStream { public final class RangeInputStream extends FilterInputStream {
private long limit; private long limit;
public RangeInputStream(InputStream in, long offset, long limit) throws IOException { public RangeInputStream(InputStream in, long offset, long limit) throws IOException {
super(in); super(in);
this.limit = limit; this.limit = limit;
while (offset > 0) { IOUtils.skipFully(in, offset);
long skip = in.skip(offset);
if (skip <= 0) {
int b = read();
if (b < 0)
throw new EOFException();
offset--;
} else {
offset -= skip;
}
}
} }
@Override @Override
......
package org.h2.store; package org.h2.store;
import java.io.EOFException;
import java.io.IOException; import java.io.IOException;
import java.io.Reader; import java.io.Reader;
import org.h2.util.IOUtils;
public final class RangeReader extends Reader { public final class RangeReader extends Reader {
private final Reader r; private final Reader r;
...@@ -12,17 +13,7 @@ public final class RangeReader extends Reader { ...@@ -12,17 +13,7 @@ public final class RangeReader extends Reader {
public RangeReader(Reader r, long offset, long limit) throws IOException { public RangeReader(Reader r, long offset, long limit) throws IOException {
this.r = r; this.r = r;
this.limit = limit; this.limit = limit;
while (offset > 0) { IOUtils.skipFully(r, offset);
long skip = r.skip(offset);
if (skip <= 0) {
int ch = read();
if (ch < 0)
throw new EOFException();
offset--;
} else {
offset -= skip;
}
}
} }
@Override @Override
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论