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 booleanwhether the file is read-onlyprivate final BlockedByteArrayInputStreamStream used to read from the source entry.private final BlockedByteArrayOutputStreamStream used to write into the source entry.private final DataInputStreamData input stream on top of the source input stream.private final DataOutputStreamData output stream on top of the source output stream.private final DataStoreEntryThe source entry.private longCurrent 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 abstractionvoidclose()Closes this file.longGet the current offset in this file.longlength()Gets the length of this file.intread(byte[] b, int off, int len) Reads up tolenbytes of data from this file into an array of bytes.booleanbytereadByte()charreadChar()doublefloatvoidreadFully(byte[] b) voidreadFully(byte[] b, int off, int len) intreadInt()readLine()longreadLong()shortintintreadUTF()voidseek(long newFilePointer) Set the file pointer.voidsetLength(long newLength) Sets the length of this file, either extending or truncating it.intskipBytes(int n) voidsync()Force any changes out to the persistent store.voidwrite(byte[] b) voidwrite(byte[] b, int off, int len) voidwrite(int b) voidwriteBoolean(boolean v) voidwriteByte(int v) voidwriteBytes(String s) voidwriteChar(int v) voidwriteChars(String s) voidwriteDouble(double v) voidwriteFloat(float v) voidwriteInt(int v) voidwriteLong(long v) voidwriteShort(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 benullif the file is opened in read-only mode. -
dOs
Data output stream on top of the source output stream. Will benullif 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:StorageRandomAccessFileClone this file abstraction- Specified by:
clonein interfaceStorageRandomAccessFile- Overrides:
clonein classObject
-
close
Description copied from interface:StorageRandomAccessFileCloses this file.- Specified by:
closein interfaceStorageRandomAccessFile- Throws:
IOException- - if an I/O error occurs.
-
getFilePointer
public long getFilePointer()Description copied from interface:StorageRandomAccessFileGet the current offset in this file.- Specified by:
getFilePointerin interfaceStorageRandomAccessFile- Returns:
- the current file pointer.
-
length
public long length()Description copied from interface:StorageRandomAccessFileGets the length of this file.- Specified by:
lengthin interfaceStorageRandomAccessFile- Returns:
- the number of bytes this file.
-
seek
Description copied from interface:StorageRandomAccessFileSet 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:
seekin 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:StorageRandomAccessFileSets 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:
setLengthin interfaceStorageRandomAccessFile- Parameters:
newLength- The new file length.
-
sync
public void sync()Description copied from interface:StorageRandomAccessFileForce 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:
syncin interfaceStorageRandomAccessFile
-
read
Description copied from interface:StorageRandomAccessFileReads up tolenbytes of data from this file into an array of bytes. This method blocks until at least one byte of input is available.- Specified by:
readin interfaceStorageRandomAccessFile- Parameters:
b- the buffer into which the data is read.off- the start offset in arraybat which the data is written.len- the maximum number of bytes read.- Returns:
- the total number of bytes read into the buffer, or
-1if 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:
readFullyin interfaceDataInput- Throws:
IOException
-
readFully
- Specified by:
readFullyin interfaceDataInput- Throws:
IOException
-
skipBytes
-
readBoolean
- Specified by:
readBooleanin interfaceDataInput- Throws:
IOException
-
readByte
- Specified by:
readBytein interfaceDataInput- Throws:
IOException
-
readUnsignedByte
- Specified by:
readUnsignedBytein interfaceDataInput- Throws:
IOException
-
readShort
- Specified by:
readShortin interfaceDataInput- Throws:
IOException
-
readUnsignedShort
- Specified by:
readUnsignedShortin interfaceDataInput- Throws:
IOException
-
readChar
- Specified by:
readCharin interfaceDataInput- Throws:
IOException
-
readInt
- Specified by:
readIntin interfaceDataInput- Throws:
IOException
-
readLong
- Specified by:
readLongin interfaceDataInput- Throws:
IOException
-
readFloat
- Specified by:
readFloatin interfaceDataInput- Throws:
IOException
-
readDouble
- Specified by:
readDoublein interfaceDataInput- Throws:
IOException
-
readLine
- Specified by:
readLinein interfaceDataInput- Throws:
IOException
-
readUTF
- Specified by:
readUTFin interfaceDataInput- Throws:
IOException
-
write
- Specified by:
writein interfaceDataOutput- Throws:
IOException
-
write
- Specified by:
writein interfaceDataOutput- Throws:
IOException
-
write
- Specified by:
writein interfaceDataOutput- Throws:
IOException
-
writeBoolean
- Specified by:
writeBooleanin interfaceDataOutput- Throws:
IOException
-
writeByte
- Specified by:
writeBytein interfaceDataOutput- Throws:
IOException
-
writeShort
- Specified by:
writeShortin interfaceDataOutput- Throws:
IOException
-
writeChar
- Specified by:
writeCharin interfaceDataOutput- Throws:
IOException
-
writeInt
- Specified by:
writeIntin interfaceDataOutput- Throws:
IOException
-
writeLong
- Specified by:
writeLongin interfaceDataOutput- Throws:
IOException
-
writeFloat
- Specified by:
writeFloatin interfaceDataOutput- Throws:
IOException
-
writeDouble
- Specified by:
writeDoublein interfaceDataOutput- Throws:
IOException
-
writeBytes
- Specified by:
writeBytesin interfaceDataOutput- Throws:
IOException
-
writeChars
- Specified by:
writeCharsin interfaceDataOutput- Throws:
IOException
-
writeUTF
- Specified by:
writeUTFin interfaceDataOutput- Throws:
IOException
-