public class VirtualRandomAccessFile extends java.lang.Object implements StorageRandomAccessFile
BlockedByteArray
.
If the file is opened in read-only mode and the caller invokes one of the
write methods, it will fail with a NullPointerException
.
Modifier and Type | Field and Description |
---|---|
private boolean |
_readOnly
whether the file is read-only
|
private BlockedByteArrayInputStream |
bIn
Stream used to read from the source entry.
|
private BlockedByteArrayOutputStream |
bOut
Stream used to write into the source entry.
|
private java.io.DataInputStream |
dIs
Data input stream on top of the source input stream.
|
private java.io.DataOutputStream |
dOs
Data output stream on top of the source output stream.
|
private DataStoreEntry |
entry
The source entry.
|
private long |
fp
Current position / file pointer.
|
Constructor and Description |
---|
VirtualRandomAccessFile(DataStoreEntry entry,
boolean readOnly)
Creates a new virtual random access file.
|
Modifier and Type | Method and Description |
---|---|
VirtualRandomAccessFile |
clone()
Clone this file abstraction
|
void |
close()
Closes this file.
|
long |
getFilePointer()
Get the current offset in this file.
|
long |
length()
Gets the length of this file.
|
int |
read(byte[] b,
int off,
int len)
Reads up to
len bytes of data from this file into an
array of bytes. |
boolean |
readBoolean() |
byte |
readByte() |
char |
readChar() |
double |
readDouble() |
float |
readFloat() |
void |
readFully(byte[] b) |
void |
readFully(byte[] b,
int off,
int len) |
int |
readInt() |
java.lang.String |
readLine() |
long |
readLong() |
short |
readShort() |
int |
readUnsignedByte() |
int |
readUnsignedShort() |
java.lang.String |
readUTF() |
void |
seek(long newFilePointer)
Set the file pointer.
|
void |
setLength(long newLength)
Sets the length of this file, either extending or truncating it.
|
int |
skipBytes(int n) |
void |
sync()
Force any changes out to the persistent store.
|
void |
write(byte[] b) |
void |
write(byte[] b,
int off,
int len) |
void |
write(int b) |
void |
writeBoolean(boolean v) |
void |
writeByte(int v) |
void |
writeBytes(java.lang.String s) |
void |
writeChar(int v) |
void |
writeChars(java.lang.String s) |
void |
writeDouble(double v) |
void |
writeFloat(float v) |
void |
writeInt(int v) |
void |
writeLong(long v) |
void |
writeShort(int v) |
void |
writeUTF(java.lang.String s) |
private final DataStoreEntry entry
private final boolean _readOnly
private long fp
private final BlockedByteArrayInputStream bIn
private final java.io.DataInputStream dIs
private final BlockedByteArrayOutputStream bOut
null
if the
file is opened in read-only mode.private final java.io.DataOutputStream dOs
null
if the file is opened in read-only mode.public VirtualRandomAccessFile(DataStoreEntry entry, boolean readOnly) throws java.io.FileNotFoundException
entry
- the source entryreadOnly
- if the file should be opened read-only or notjava.io.FileNotFoundException
- if the denoted path is a directory, or
the denoted file has been marked read-only and the file is opened
for writingpublic VirtualRandomAccessFile clone()
StorageRandomAccessFile
clone
in interface StorageRandomAccessFile
clone
in class java.lang.Object
public void close() throws java.io.IOException
StorageRandomAccessFile
close
in interface StorageRandomAccessFile
java.io.IOException
- - if an I/O error occurs.public long getFilePointer()
StorageRandomAccessFile
getFilePointer
in interface StorageRandomAccessFile
public long length()
StorageRandomAccessFile
length
in interface StorageRandomAccessFile
public void seek(long newFilePointer) throws java.io.IOException
StorageRandomAccessFile
seek
in interface StorageRandomAccessFile
newFilePointer
- the new file pointer, measured in bytes from the beginning of the file.java.io.IOException
- - if newFilePointer is less than 0 or an I/O error occurs.public void setLength(long newLength)
StorageRandomAccessFile
If the file is extended then the contents of the extension are not defined.
If the file is truncated and the file pointer is greater than the new length then the file pointer is set to the new length.
setLength
in interface StorageRandomAccessFile
newLength
- The new file length.public void sync()
StorageRandomAccessFile
sync
in interface StorageRandomAccessFile
public int read(byte[] b, int off, int len) throws java.io.IOException
StorageRandomAccessFile
len
bytes of data from this file into an
array of bytes. This method blocks until at least one byte of input
is available.
read
in interface StorageRandomAccessFile
b
- the buffer into which the data is read.off
- the start offset in array b
at which the data is written.len
- the maximum number of bytes read.-1
if there is no more data because the end of
the file has been reached.java.io.IOException
- If the first byte cannot be read for any reason
other than end of file, or if the random access file has been closed, or
if some other I/O error occurs.public void readFully(byte[] b) throws java.io.IOException
readFully
in interface java.io.DataInput
java.io.IOException
public void readFully(byte[] b, int off, int len) throws java.io.IOException
readFully
in interface java.io.DataInput
java.io.IOException
public int skipBytes(int n)
skipBytes
in interface java.io.DataInput
public boolean readBoolean() throws java.io.IOException
readBoolean
in interface java.io.DataInput
java.io.IOException
public byte readByte() throws java.io.IOException
readByte
in interface java.io.DataInput
java.io.IOException
public int readUnsignedByte() throws java.io.IOException
readUnsignedByte
in interface java.io.DataInput
java.io.IOException
public short readShort() throws java.io.IOException
readShort
in interface java.io.DataInput
java.io.IOException
public int readUnsignedShort() throws java.io.IOException
readUnsignedShort
in interface java.io.DataInput
java.io.IOException
public char readChar() throws java.io.IOException
readChar
in interface java.io.DataInput
java.io.IOException
public int readInt() throws java.io.IOException
readInt
in interface java.io.DataInput
java.io.IOException
public long readLong() throws java.io.IOException
readLong
in interface java.io.DataInput
java.io.IOException
public float readFloat() throws java.io.IOException
readFloat
in interface java.io.DataInput
java.io.IOException
public double readDouble() throws java.io.IOException
readDouble
in interface java.io.DataInput
java.io.IOException
public java.lang.String readLine() throws java.io.IOException
readLine
in interface java.io.DataInput
java.io.IOException
public java.lang.String readUTF() throws java.io.IOException
readUTF
in interface java.io.DataInput
java.io.IOException
public void write(int b) throws java.io.IOException
write
in interface java.io.DataOutput
java.io.IOException
public void write(byte[] b) throws java.io.IOException
write
in interface java.io.DataOutput
java.io.IOException
public void write(byte[] b, int off, int len) throws java.io.IOException
write
in interface java.io.DataOutput
java.io.IOException
public void writeBoolean(boolean v) throws java.io.IOException
writeBoolean
in interface java.io.DataOutput
java.io.IOException
public void writeByte(int v) throws java.io.IOException
writeByte
in interface java.io.DataOutput
java.io.IOException
public void writeShort(int v) throws java.io.IOException
writeShort
in interface java.io.DataOutput
java.io.IOException
public void writeChar(int v) throws java.io.IOException
writeChar
in interface java.io.DataOutput
java.io.IOException
public void writeInt(int v) throws java.io.IOException
writeInt
in interface java.io.DataOutput
java.io.IOException
public void writeLong(long v) throws java.io.IOException
writeLong
in interface java.io.DataOutput
java.io.IOException
public void writeFloat(float v) throws java.io.IOException
writeFloat
in interface java.io.DataOutput
java.io.IOException
public void writeDouble(double v) throws java.io.IOException
writeDouble
in interface java.io.DataOutput
java.io.IOException
public void writeBytes(java.lang.String s) throws java.io.IOException
writeBytes
in interface java.io.DataOutput
java.io.IOException
public void writeChars(java.lang.String s) throws java.io.IOException
writeChars
in interface java.io.DataOutput
java.io.IOException
public void writeUTF(java.lang.String s) throws java.io.IOException
writeUTF
in interface java.io.DataOutput
java.io.IOException
Apache Derby V10.13 Internals - Copyright © 2004,2016 The Apache Software Foundation. All Rights Reserved.