Merge "Adds the lazy seek"
This commit is contained in:
commit
d95ffe7014
|
@ -89,6 +89,8 @@ class SwiftNativeInputStream extends FSInputStream {
|
||||||
*/
|
*/
|
||||||
private long rangeOffset = 0;
|
private long rangeOffset = 0;
|
||||||
|
|
||||||
|
private long nextReadPosition = 0;
|
||||||
|
|
||||||
public SwiftNativeInputStream(SwiftNativeFileSystemStore storeNative,
|
public SwiftNativeInputStream(SwiftNativeFileSystemStore storeNative,
|
||||||
FileSystem.Statistics statistics, Path path, long bufferSize)
|
FileSystem.Statistics statistics, Path path, long bufferSize)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
|
@ -138,6 +140,7 @@ class SwiftNativeInputStream extends FSInputStream {
|
||||||
verifyOpen();
|
verifyOpen();
|
||||||
int result = -1;
|
int result = -1;
|
||||||
try {
|
try {
|
||||||
|
seekStream();
|
||||||
result = httpStream.read();
|
result = httpStream.read();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
String msg = "IOException while reading " + path
|
String msg = "IOException while reading " + path
|
||||||
|
@ -297,6 +300,13 @@ class SwiftNativeInputStream extends FSInputStream {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public synchronized void seek(long targetPos) throws IOException {
|
public synchronized void seek(long targetPos) throws IOException {
|
||||||
|
if (targetPos < 0) {
|
||||||
|
throw new IOException("Negative Seek offset not supported");
|
||||||
|
}
|
||||||
|
nextReadPosition = targetPos;
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void realSeek(long targetPos) throws IOException {
|
||||||
if (targetPos < 0) {
|
if (targetPos < 0) {
|
||||||
throw new IOException("Negative Seek offset not supported");
|
throw new IOException("Negative Seek offset not supported");
|
||||||
}
|
}
|
||||||
|
@ -344,6 +354,18 @@ class SwiftNativeInputStream extends FSInputStream {
|
||||||
fillBuffer(targetPos);
|
fillBuffer(targetPos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lazy seek.
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
private void seekStream() throws IOException {
|
||||||
|
if (httpStream != null && nextReadPosition == pos) {
|
||||||
|
// already at specified position
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
realSeek(nextReadPosition);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fill the buffer from the target position
|
* Fill the buffer from the target position
|
||||||
* If the target position == current position, the
|
* If the target position == current position, the
|
||||||
|
|
Loading…
Reference in New Issue