com.mobixess.jodb.core.io.buffers
Class RandomAccessFileTransactionBuffer

java.lang.Object
  extended by com.mobixess.jodb.core.io.buffers.RandomAccessFileTransactionBuffer
All Implemented Interfaces:
IRandomAccessDataBuffer, java.io.DataInput, java.io.DataOutput

public class RandomAccessFileTransactionBuffer
extends java.lang.Object
implements IRandomAccessDataBuffer


Method Summary
 void close()
           
 void delete()
           
 java.nio.channels.ByteChannel getChannel()
           
 long getCursorOffset()
           
 long length()
           
 void read(byte[] b, int off, int len)
           
 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 resetToEnd()
           
 void resetToStart()
           
 void seek(long pos)
           
 void setLength(long newLength)
           
 long skip(long n)
           
 int skipBytes(int n)
           
 java.lang.String toString()
           
 long transferFrom(java.nio.channels.ReadableByteChannel src, long position, long count)
          Transfers bytes into this channel's file from the given readable byte channel.
 long transferTo(long position, long count, java.nio.channels.WritableByteChannel target)
          Transfers bytes from this channel's file to the given writable byte channel.
 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 str)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

close

public void close()
           throws java.io.IOException
Specified by:
close in interface IRandomAccessDataBuffer
Parameters:
file -
raFile -
Throws:
java.io.IOException

delete

public void delete()
            throws java.io.IOException
Specified by:
delete in interface IRandomAccessDataBuffer
Throws:
java.io.IOException

getChannel

public java.nio.channels.ByteChannel getChannel()
Specified by:
getChannel in interface IRandomAccessDataBuffer

getCursorOffset

public long getCursorOffset()
                     throws java.io.IOException
Specified by:
getCursorOffset in interface IRandomAccessDataBuffer
Throws:
java.io.IOException

length

public long length()
            throws java.io.IOException
Specified by:
length in interface IRandomAccessDataBuffer
Throws:
java.io.IOException

seek

public void seek(long pos)
          throws java.io.IOException
Specified by:
seek in interface IRandomAccessDataBuffer
Throws:
java.io.IOException

setLength

public void setLength(long newLength)
               throws java.io.IOException
Specified by:
setLength in interface IRandomAccessDataBuffer
Throws:
java.io.IOException

transferFrom

public long transferFrom(java.nio.channels.ReadableByteChannel src,
                         long position,
                         long count)
                  throws java.io.IOException
Transfers bytes into this channel's file from the given readable byte channel.

An attempt is made to read up to count bytes from the source channel and write them to this channel's file starting at the given position. An invocation of this method may or may not transfer all of the requested bytes; whether or not it does so depends upon the natures and states of the channels. Fewer than the requested number of bytes will be transferred if the source channel has fewer than count bytes remaining, or if the source channel is non-blocking and has fewer than count bytes immediately available in its input buffer.

This method does not modify this channel's position. If the given position is greater than the file's current size then no bytes are transferred. If the source channel has a position then bytes are read starting at that position and then the position is incremented by the number of bytes read.

This method is potentially much more efficient than a simple loop that reads from the source channel and writes to this channel. Many operating systems can transfer bytes directly from the source channel into the filesystem cache without actually copying them.

Specified by:
transferFrom in interface IRandomAccessDataBuffer
Parameters:
src - The source channel
position - The position within the file at which the transfer is to begin; must be non-negative
count - The maximum number of bytes to be transferred; must be non-negative
Returns:
The number of bytes, possibly zero, that were actually transferred
Throws:
java.lang.IllegalArgumentException - If the preconditions on the parameters do not hold
java.nio.channels.NonReadableChannelException - If the source channel was not opened for reading
java.nio.channels.NonWritableChannelException - If this channel was not opened for writing
java.nio.channels.ClosedChannelException - If either this channel or the source channel is closed
java.nio.channels.AsynchronousCloseException - If another thread closes either channel while the transfer is in progress
java.nio.channels.ClosedByInterruptException - If another thread interrupts the current thread while the transfer is in progress, thereby closing both channels and setting the current thread's interrupt status
java.io.IOException - If some other I/O error occurs

transferTo

public long transferTo(long position,
                       long count,
                       java.nio.channels.WritableByteChannel target)
                throws java.io.IOException
Transfers bytes from this channel's file to the given writable byte channel.

An attempt is made to read up to count bytes starting at the given position in this channel's file and write them to the target channel. An invocation of this method may or may not transfer all of the requested bytes; whether or not it does so depends upon the natures and states of the channels. Fewer than the requested number of bytes are transferred if this channel's file contains fewer than count bytes starting at the given position, or if the target channel is non-blocking and it has fewer than count bytes free in its output buffer.

This method does not modify this channel's position. If the given position is greater than the file's current size then no bytes are transferred. If the target channel has a position then bytes are written starting at that position and then the position is incremented by the number of bytes written.

This method is potentially much more efficient than a simple loop that reads from this channel and writes to the target channel. Many operating systems can transfer bytes directly from the filesystem cache to the target channel without actually copying them.

Specified by:
transferTo in interface IRandomAccessDataBuffer
Parameters:
position - The position within the file at which the transfer is to begin; must be non-negative
count - The maximum number of bytes to be transferred; must be non-negative
target - The target channel
Returns:
The number of bytes, possibly zero, that were actually transferred
Throws:
java.lang.IllegalArgumentException - If the preconditions on the parameters do not hold
java.nio.channels.NonReadableChannelException - If this channel was not opened for reading
java.nio.channels.NonWritableChannelException - If the target channel was not opened for writing
java.nio.channels.ClosedChannelException - If either this channel or the target channel is closed
java.nio.channels.AsynchronousCloseException - If another thread closes either channel while the transfer is in progress
java.nio.channels.ClosedByInterruptException - If another thread interrupts the current thread while the transfer is in progress, thereby closing both channels and setting the current thread's interrupt status
java.io.IOException - If some other I/O error occurs

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

readChar

public char readChar()
              throws java.io.IOException
Specified by:
readChar 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

readFloat

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

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

readInt

public int readInt()
            throws java.io.IOException
Specified by:
readInt 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

readLong

public long readLong()
              throws java.io.IOException
Specified by:
readLong 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

readUTF

public java.lang.String readUTF()
                         throws java.io.IOException
Specified by:
readUTF 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

readUnsignedShort

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

skipBytes

public int skipBytes(int n)
              throws java.io.IOException
Specified by:
skipBytes 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

writeBytes

public void writeBytes(java.lang.String s)
                throws java.io.IOException
Specified by:
writeBytes 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

writeChars

public void writeChars(java.lang.String s)
                throws java.io.IOException
Specified by:
writeChars 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

writeFloat

public void writeFloat(float v)
                throws java.io.IOException
Specified by:
writeFloat 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

writeShort

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

writeUTF

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

resetToStart

public void resetToStart()
                  throws java.io.IOException
Specified by:
resetToStart in interface IRandomAccessDataBuffer
Throws:
java.io.IOException

read

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

resetToEnd

public void resetToEnd()
                throws java.io.IOException
Specified by:
resetToEnd in interface IRandomAccessDataBuffer
Throws:
java.io.IOException

skip

public long skip(long n)
          throws java.io.IOException
Specified by:
skip in interface IRandomAccessDataBuffer
Throws:
java.io.IOException

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


Copyright © Mobixess Inc. All Rights Reserved.