in commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http/HttpRandomAccessContent.java [62:115]
protected DataInputStream getDataInputStream() throws IOException {
if (dataInputStream != null) {
return dataInputStream;
}
final GetMethod getMethod = new GetMethod();
fileObject.setupMethod(getMethod);
getMethod.setRequestHeader("Range", "bytes=" + filePointer + "-");
final int status = fileSystem.getClient().executeMethod(getMethod);
if (status != HttpURLConnection.HTTP_PARTIAL && status != HttpURLConnection.HTTP_OK) {
throw new FileSystemException("vfs.provider.http/get-range.error", fileObject.getName(),
Long.valueOf(filePointer), Integer.valueOf(status));
}
monitorInputStream = new HttpFileObject.HttpInputStream(getMethod);
// If the range request was ignored
if (status == HttpURLConnection.HTTP_OK) {
final long skipped = monitorInputStream.skip(filePointer);
if (skipped != filePointer) {
throw new FileSystemException("vfs.provider.http/get-range.error", fileObject.getName(),
Long.valueOf(filePointer), Integer.valueOf(status));
}
}
dataInputStream = new DataInputStream(new FilterInputStream(monitorInputStream) {
@Override
public int read() throws IOException {
final int ret = super.read();
if (ret > -1) {
filePointer++;
}
return ret;
}
@Override
public int read(final byte[] b) throws IOException {
final int ret = super.read(b);
if (ret > -1) {
filePointer += ret;
}
return ret;
}
@Override
public int read(final byte[] b, final int off, final int len) throws IOException {
final int ret = super.read(b, off, len);
if (ret > -1) {
filePointer += ret;
}
return ret;
}
});
return dataInputStream;
}