You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by th...@apache.org on 2011/12/08 15:43:40 UTC
svn commit: r1211914 -
/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/fs/FilePathDisk.java
Author: thomasm
Date: Thu Dec 8 14:43:40 2011
New Revision: 1211914
URL: http://svn.apache.org/viewvc?rev=1211914&view=rev
Log:
File system optimization: remember the position
Modified:
jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/fs/FilePathDisk.java
Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/fs/FilePathDisk.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/fs/FilePathDisk.java?rev=1211914&r1=1211913&r2=1211914&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/fs/FilePathDisk.java (original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/fs/FilePathDisk.java Thu Dec 8 14:43:40 2011
@@ -349,6 +349,8 @@ class FileDisk extends FileBase {
private final RandomAccessFile file;
private final String name;
+ private long pos;
+
FileDisk(String fileName, String mode) throws FileNotFoundException {
this.file = new RandomAccessFile(fileName, mode);
this.name = fileName;
@@ -362,6 +364,7 @@ class FileDisk extends FileBase {
if (newLength < file.length()) {
// some implementations actually only support truncate
file.setLength(newLength);
+ pos = Math.min(pos, newLength);
}
return this;
}
@@ -375,7 +378,7 @@ class FileDisk extends FileBase {
}
public long position() throws IOException {
- return file.getFilePointer();
+ return pos;
}
public long size() throws IOException {
@@ -385,13 +388,17 @@ class FileDisk extends FileBase {
public int read(ByteBuffer dst) throws IOException {
int len = file.read(dst.array(), dst.position(), dst.remaining());
if (len > 0) {
+ pos += len;
dst.position(dst.position() + len);
}
return len;
}
public FileChannel position(long pos) throws IOException {
- file.seek(pos);
+ if (this.pos != pos) {
+ file.seek(pos);
+ this.pos = pos;
+ }
return this;
}
@@ -399,6 +406,7 @@ class FileDisk extends FileBase {
int len = src.remaining();
file.write(src.array(), src.position(), len);
src.position(src.position() + len);
+ pos += len;
return len;
}