org.apache.derby.impl.io.vfmem
Class VirtualRandomAccessFile

java.lang.Object
  extended by org.apache.derby.impl.io.vfmem.VirtualRandomAccessFile
All Implemented Interfaces:
java.io.DataInput, java.io.DataOutput, StorageRandomAccessFile

public class VirtualRandomAccessFile
extends java.lang.Object
implements 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
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 Summary
VirtualRandomAccessFile(DataStoreEntry entry, boolean readOnly)
          Creates a new virtual random access file.
 
Method Summary
 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(boolean metaData)
          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)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

entry

private final DataStoreEntry entry
The source entry.


fp

private long fp
Current position / file pointer.


bIn

private BlockedByteArrayInputStream bIn
Stream used to read from the source entry.


dIs

private java.io.DataInputStream dIs
Data input stream on top of the source input stream.


bOut

private BlockedByteArrayOutputStream bOut
Stream used to write into the source entry. Will be null if the file is opened in read-only mode.


dOs

private java.io.DataOutputStream dOs
Data output stream on top of the source output stream. Will be null if the file is opened in read-only mode.

Constructor Detail

VirtualRandomAccessFile

public VirtualRandomAccessFile(DataStoreEntry entry,
                               boolean readOnly)
                        throws java.io.FileNotFoundException
Creates a new virtual random access file.

Parameters:
entry - the source entry
readOnly - if the file should be opened read-only or not
Throws:
java.io.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 Detail

close

public void close()
           throws java.io.IOException
Description copied from interface: StorageRandomAccessFile
Closes this file.

Specified by:
close in interface StorageRandomAccessFile
Throws:
java.io.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 interface StorageRandomAccessFile
Returns:
the current file pointer.

length

public long length()
Description copied from interface: StorageRandomAccessFile
Gets the length of this file.

Specified by:
length in interface StorageRandomAccessFile
Returns:
the number of bytes this file.

seek

public void seek(long newFilePointer)
          throws java.io.IOException
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 interface StorageRandomAccessFile
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

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 interface StorageRandomAccessFile
Parameters:
newLength - The new file length.

sync

public void sync(boolean metaData)
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 interface StorageRandomAccessFile
Parameters:
metaData - If true then this method must force both changes to the file's contents and metadata to be written to storage; if false, it need only force file content changes to be written. The implementation is allowed to ignore this parameter and always force out metadata changes.

read

public int read(byte[] b,
                int off,
                int len)
         throws java.io.IOException
Description copied from interface: StorageRandomAccessFile
Reads up to len 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 interface StorageRandomAccessFile
Parameters:
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.
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:
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.

readFully

public void readFully(byte[] b)
               throws java.io.IOException
Specified by:
readFully in interface java.io.DataInput
Throws:
java.io.IOException

readFully

public void readFully(byte[] b,
                      int off,
                      int len)
               throws java.io.IOException
Specified by:
readFully in interface java.io.DataInput
Throws:
java.io.IOException

skipBytes

public int skipBytes(int n)
Specified by:
skipBytes in interface java.io.DataInput

readBoolean

public boolean readBoolean()
                    throws java.io.IOException
Specified by:
readBoolean in interface java.io.DataInput
Throws:
java.io.IOException

readByte

public byte readByte()
              throws java.io.IOException
Specified by:
readByte in interface java.io.DataInput
Throws:
java.io.IOException

readUnsignedByte

public int readUnsignedByte()
                     throws java.io.IOException
Specified by:
readUnsignedByte in interface java.io.DataInput
Throws:
java.io.IOException

readShort

public short readShort()
                throws java.io.IOException
Specified by:
readShort in interface java.io.DataInput
Throws:
java.io.IOException

readUnsignedShort

public int readUnsignedShort()
                      throws java.io.IOException
Specified by:
readUnsignedShort in interface java.io.DataInput
Throws:
java.io.IOException

readChar

public char readChar()
              throws java.io.IOException
Specified by:
readChar in interface java.io.DataInput
Throws:
java.io.IOException

readInt

public int readInt()
            throws java.io.IOException
Specified by:
readInt in interface java.io.DataInput
Throws:
java.io.IOException

readLong

public long readLong()
              throws java.io.IOException
Specified by:
readLong in interface java.io.DataInput
Throws:
java.io.IOException

readFloat

public float readFloat()
                throws java.io.IOException
Specified by:
readFloat in interface java.io.DataInput
Throws:
java.io.IOException

readDouble

public double readDouble()
                  throws java.io.IOException
Specified by:
readDouble in interface java.io.DataInput
Throws:
java.io.IOException

readLine

public java.lang.String readLine()
                          throws java.io.IOException
Specified by:
readLine in interface java.io.DataInput
Throws:
java.io.IOException

readUTF

public java.lang.String readUTF()
                         throws java.io.IOException
Specified by:
readUTF in interface java.io.DataInput
Throws:
java.io.IOException

write

public void write(int b)
           throws java.io.IOException
Specified by:
write in interface java.io.DataOutput
Throws:
java.io.IOException

write

public void write(byte[] b)
           throws java.io.IOException
Specified by:
write in interface java.io.DataOutput
Throws:
java.io.IOException

write

public void write(byte[] b,
                  int off,
                  int len)
           throws java.io.IOException
Specified by:
write in interface java.io.DataOutput
Throws:
java.io.IOException

writeBoolean

public void writeBoolean(boolean v)
                  throws java.io.IOException
Specified by:
writeBoolean in interface java.io.DataOutput
Throws:
java.io.IOException

writeByte

public void writeByte(int v)
               throws java.io.IOException
Specified by:
writeByte in interface java.io.DataOutput
Throws:
java.io.IOException

writeShort

public void writeShort(int v)
                throws java.io.IOException
Specified by:
writeShort in interface java.io.DataOutput
Throws:
java.io.IOException

writeChar

public void writeChar(int v)
               throws java.io.IOException
Specified by:
writeChar in interface java.io.DataOutput
Throws:
java.io.IOException

writeInt

public void writeInt(int v)
              throws java.io.IOException
Specified by:
writeInt in interface java.io.DataOutput
Throws:
java.io.IOException

writeLong

public void writeLong(long v)
               throws java.io.IOException
Specified by:
writeLong in interface java.io.DataOutput
Throws:
java.io.IOException

writeFloat

public void writeFloat(float v)
                throws java.io.IOException
Specified by:
writeFloat in interface java.io.DataOutput
Throws:
java.io.IOException

writeDouble

public void writeDouble(double v)
                 throws java.io.IOException
Specified by:
writeDouble in interface java.io.DataOutput
Throws:
java.io.IOException

writeBytes

public void writeBytes(java.lang.String s)
                throws java.io.IOException
Specified by:
writeBytes in interface java.io.DataOutput
Throws:
java.io.IOException

writeChars

public void writeChars(java.lang.String s)
                throws java.io.IOException
Specified by:
writeChars in interface java.io.DataOutput
Throws:
java.io.IOException

writeUTF

public void writeUTF(java.lang.String s)
              throws java.io.IOException
Specified by:
writeUTF in interface java.io.DataOutput
Throws:
java.io.IOException

Built on Thu 2010-12-23 20:49:13+0000, from revision ???

Apache Derby V10.6 Internals - Copyright © 2004,2007 The Apache Software Foundation. All Rights Reserved.