mirror of
https://github.com/corda/corda.git
synced 2025-01-09 06:23:04 +00:00
RandomAccessFile now correctly reports lengths for growing files.
This commit is contained in:
parent
90dc552463
commit
216b9a05ea
@ -12,25 +12,25 @@ package java.io;
|
|||||||
|
|
||||||
public class RandomAccessFile {
|
public class RandomAccessFile {
|
||||||
private long peer;
|
private long peer;
|
||||||
private long length;
|
private File file;
|
||||||
private long position = 0;
|
private long position = 0;
|
||||||
|
|
||||||
public RandomAccessFile(String name, String mode)
|
public RandomAccessFile(String name, String mode)
|
||||||
throws FileNotFoundException
|
throws FileNotFoundException
|
||||||
{
|
{
|
||||||
if (! mode.equals("r")) throw new IllegalArgumentException();
|
if (! mode.equals("r")) throw new IllegalArgumentException();
|
||||||
|
file = new File(name);
|
||||||
|
|
||||||
long[] result = new long[2];
|
long[] result = new long[2];
|
||||||
open(name, result);
|
open(name, result);
|
||||||
peer = result[0];
|
peer = result[0];
|
||||||
length = result[1];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static native void open(String name, long[] result)
|
private static native void open(String name, long[] result)
|
||||||
throws FileNotFoundException;
|
throws FileNotFoundException;
|
||||||
|
|
||||||
public long length() throws IOException {
|
public long length() throws IOException {
|
||||||
return length;
|
return file.length();
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getFilePointer() throws IOException {
|
public long getFilePointer() throws IOException {
|
||||||
@ -38,7 +38,7 @@ public class RandomAccessFile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void seek(long position) throws IOException {
|
public void seek(long position) throws IOException {
|
||||||
if (position < 0 || position > length) throw new IOException();
|
if (position < 0 || position > length()) throw new IOException();
|
||||||
|
|
||||||
this.position = position;
|
this.position = position;
|
||||||
}
|
}
|
||||||
@ -50,7 +50,7 @@ public class RandomAccessFile {
|
|||||||
|
|
||||||
if (length == 0) return;
|
if (length == 0) return;
|
||||||
|
|
||||||
if (position + length > this.length) throw new EOFException();
|
if (position + length > this.length()) throw new EOFException();
|
||||||
|
|
||||||
if (offset < 0 || offset + length > buffer.length)
|
if (offset < 0 || offset + length > buffer.length)
|
||||||
throw new ArrayIndexOutOfBoundsException();
|
throw new ArrayIndexOutOfBoundsException();
|
||||||
|
Loading…
Reference in New Issue
Block a user