Package org.apache.derby.impl.io.vfmem
Class VirtualRandomAccessFile
java.lang.Object
org.apache.derby.impl.io.vfmem.VirtualRandomAccessFile
- All Implemented Interfaces:
DataInput
,DataOutput
,StorageRandomAccessFile
A random access file capable of reading and writing from/into a virtual file
whose data is represented by a
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
.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final boolean
whether the file is read-onlyprivate final BlockedByteArrayInputStream
Stream used to read from the source entry.private final BlockedByteArrayOutputStream
Stream used to write into the source entry.private final DataInputStream
Data input stream on top of the source input stream.private final DataOutputStream
Data output stream on top of the source output stream.private final DataStoreEntry
The source entry.private long
Current position / file pointer. -
Constructor Summary
ConstructorsConstructorDescriptionVirtualRandomAccessFile
(DataStoreEntry entry, boolean readOnly) Creates a new virtual random access file. -
Method Summary
Modifier and TypeMethodDescriptionclone()
Clone this file abstractionvoid
close()
Closes this file.long
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 tolen
bytes of data from this file into an array of bytes.boolean
byte
readByte()
char
readChar()
double
float
void
readFully
(byte[] b) void
readFully
(byte[] b, int off, int len) int
readInt()
readLine()
long
readLong()
short
int
int
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
(String s) void
writeChar
(int v) void
writeChars
(String s) void
writeDouble
(double v) void
writeFloat
(float v) void
writeInt
(int v) void
writeLong
(long v) void
writeShort
(int v) void
-
Field Details
-
entry
The source entry. -
_readOnly
private final boolean _readOnlywhether the file is read-only -
fp
private long fpCurrent position / file pointer. -
bIn
Stream used to read from the source entry. -
dIs
Data input stream on top of the source input stream. -
bOut
Stream used to write into the source entry. Will benull
if the file is opened in read-only mode. -
dOs
Data output stream on top of the source output stream. Will benull
if the file is opened in read-only mode.
-
-
Constructor Details
-
VirtualRandomAccessFile
Creates a new virtual random access file.- Parameters:
entry
- the source entryreadOnly
- if the file should be opened read-only or not- Throws:
FileNotFoundException
- if the denoted path is a directory, or the denoted file has been marked read-only and the file is opened for writing
-
-
Method Details
-
clone
Description copied from interface:StorageRandomAccessFile
Clone this file abstraction- Specified by:
clone
in interfaceStorageRandomAccessFile
- Overrides:
clone
in classObject
-
close
Description copied from interface:StorageRandomAccessFile
Closes this file.- Specified by:
close
in interfaceStorageRandomAccessFile
- Throws:
IOException
- - if an I/O error occurs.
-
getFilePointer
public long getFilePointer()Description copied from interface:StorageRandomAccessFile
Get the current offset in this file.- Specified by:
getFilePointer
in interfaceStorageRandomAccessFile
- Returns:
- the current file pointer.
-
length
public long length()Description copied from interface:StorageRandomAccessFile
Gets the length of this file.- Specified by:
length
in interfaceStorageRandomAccessFile
- Returns:
- the number of bytes this file.
-
seek
Description copied from interface:StorageRandomAccessFile
Set the file pointer. It may be moved beyond the end of the file, but this does not change the length of the file. The length of the file is not changed until data is actually written..- Specified by:
seek
in interfaceStorageRandomAccessFile
- Parameters:
newFilePointer
- the new file pointer, measured in bytes from the beginning of the file.- Throws:
IOException
- - if newFilePointer is less than 0 or an I/O error occurs.
-
setLength
public void setLength(long newLength) Description copied from interface:StorageRandomAccessFile
Sets the length of this file, either extending or truncating it.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.
- Specified by:
setLength
in interfaceStorageRandomAccessFile
- Parameters:
newLength
- The new file length.
-
sync
public void sync()Description copied from interface:StorageRandomAccessFile
Force any changes out to the persistent store. If the database is to be transient, that is, if the database does not survive a restart, then the sync method implementation need not do anything.- Specified by:
sync
in interfaceStorageRandomAccessFile
-
read
Description copied from interface:StorageRandomAccessFile
Reads up tolen
bytes of data from this file into an array of bytes. This method blocks until at least one byte of input is available.- Specified by:
read
in interfaceStorageRandomAccessFile
- Parameters:
b
- the buffer into which the data is read.off
- the start offset in arrayb
at which the data is written.len
- the maximum number of bytes read.- Returns:
- the total number of bytes read into the buffer, or
-1
if there is no more data because the end of the file has been reached. - Throws:
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.
-
readFully
- Specified by:
readFully
in interfaceDataInput
- Throws:
IOException
-
readFully
- Specified by:
readFully
in interfaceDataInput
- Throws:
IOException
-
skipBytes
public int skipBytes(int n) -
readBoolean
- Specified by:
readBoolean
in interfaceDataInput
- Throws:
IOException
-
readByte
- Specified by:
readByte
in interfaceDataInput
- Throws:
IOException
-
readUnsignedByte
- Specified by:
readUnsignedByte
in interfaceDataInput
- Throws:
IOException
-
readShort
- Specified by:
readShort
in interfaceDataInput
- Throws:
IOException
-
readUnsignedShort
- Specified by:
readUnsignedShort
in interfaceDataInput
- Throws:
IOException
-
readChar
- Specified by:
readChar
in interfaceDataInput
- Throws:
IOException
-
readInt
- Specified by:
readInt
in interfaceDataInput
- Throws:
IOException
-
readLong
- Specified by:
readLong
in interfaceDataInput
- Throws:
IOException
-
readFloat
- Specified by:
readFloat
in interfaceDataInput
- Throws:
IOException
-
readDouble
- Specified by:
readDouble
in interfaceDataInput
- Throws:
IOException
-
readLine
- Specified by:
readLine
in interfaceDataInput
- Throws:
IOException
-
readUTF
- Specified by:
readUTF
in interfaceDataInput
- Throws:
IOException
-
write
- Specified by:
write
in interfaceDataOutput
- Throws:
IOException
-
write
- Specified by:
write
in interfaceDataOutput
- Throws:
IOException
-
write
- Specified by:
write
in interfaceDataOutput
- Throws:
IOException
-
writeBoolean
- Specified by:
writeBoolean
in interfaceDataOutput
- Throws:
IOException
-
writeByte
- Specified by:
writeByte
in interfaceDataOutput
- Throws:
IOException
-
writeShort
- Specified by:
writeShort
in interfaceDataOutput
- Throws:
IOException
-
writeChar
- Specified by:
writeChar
in interfaceDataOutput
- Throws:
IOException
-
writeInt
- Specified by:
writeInt
in interfaceDataOutput
- Throws:
IOException
-
writeLong
- Specified by:
writeLong
in interfaceDataOutput
- Throws:
IOException
-
writeFloat
- Specified by:
writeFloat
in interfaceDataOutput
- Throws:
IOException
-
writeDouble
- Specified by:
writeDouble
in interfaceDataOutput
- Throws:
IOException
-
writeBytes
- Specified by:
writeBytes
in interfaceDataOutput
- Throws:
IOException
-
writeChars
- Specified by:
writeChars
in interfaceDataOutput
- Throws:
IOException
-
writeUTF
- Specified by:
writeUTF
in interfaceDataOutput
- Throws:
IOException
-