Package org.apache.derby.io
Interface StorageRandomAccessFile
-
- All Superinterfaces:
java.io.DataInput,java.io.DataOutput
- All Known Implementing Classes:
DirRandomAccessFile,VirtualRandomAccessFile
public interface StorageRandomAccessFile extends java.io.DataInput, java.io.DataOutputThis interface abstracts an object that implements reading and writing on a random access file. It extends DataInput and DataOutput, so it implicitly contains all the methods of those interfaces. Any method in this interface that also appears in the java.io.RandomAccessFile class should behave as the java.io.RandomAccessFile method does.Each StorageRandomAccessFile has an associated file pointer, a byte offset in the file. All reading and writing takes place at the file pointer offset and advances it.
An implementation of StorageRandomAccessFile need not be thread safe. The database engine single-threads access to each StorageRandomAccessFile instance. Two threads will not access the same StorageRandomAccessFile instance at the same time.
- See Also:
- java.io.RandomAccessFile
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description StorageRandomAccessFileclone()Clone this file abstractionvoidclose()Closes this file.longgetFilePointer()Get 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.voidseek(long newFilePointer)Set the file pointer.voidsetLength(long newLength)Sets the length of this file, either extending or truncating it.voidsync()Force any changes out to the persistent store.
-
-
-
Method Detail
-
close
void close() throws java.io.IOExceptionCloses this file.- Throws:
java.io.IOException- - if an I/O error occurs.
-
getFilePointer
long getFilePointer() throws java.io.IOExceptionGet the current offset in this file.- Returns:
- the current file pointer.
- Throws:
java.io.IOException- - if an I/O error occurs.
-
length
long length() throws java.io.IOExceptionGets the length of this file.- Returns:
- the number of bytes this file.
- Throws:
java.io.IOException- - if an I/O error occurs.
-
seek
void seek(long newFilePointer) throws java.io.IOException
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..- Parameters:
newFilePointer- the new file pointer, measured in bytes from the beginning of the file.- Throws:
java.io.IOException- - if newFilePointer is less than 0 or an I/O error occurs.
-
setLength
void setLength(long newLength) throws java.io.IOExceptionSets 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.
- Parameters:
newLength- The new file length.- Throws:
java.io.IOException- If an I/O error occurs.
-
sync
void sync() throws java.io.IOException
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.- Throws:
java.io.SyncFailedException- if a possibly recoverable error occurs.java.io.IOException- If an IO error occurs.
-
read
int read(byte[] b, int off, int len) throws java.io.IOExceptionReads up tolenbytes of data from this file into an array of bytes. This method blocks until at least one byte of input is available.- 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:
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.java.lang.NullPointerException- Ifbisnull.java.lang.IndexOutOfBoundsException- Ifoffis negative,lenis negative, orlenis greater thanb.length - off
-
clone
StorageRandomAccessFile clone()
Clone this file abstraction
-
-