loci.formats
Class RAFile

java.lang.Object
  extended by loci.formats.RAFile
All Implemented Interfaces:
DataInput, DataOutput, IRandomAccess

public class RAFile
extends Object
implements IRandomAccess

A wrapper for RandomAccessFile that implements the IRandomAccess interface.

Source code:
Trac, SVN

Author:
Curtis Rueden ctrueden at wisc.edu
See Also:
IRandomAccess, RandomAccessFile

Field Summary
protected  RandomAccessFile raf
          The random access file object backing this RAFile.
 
Constructor Summary
RAFile(File file, String mode)
          Creates a random access file stream to read from, and optionally to write to, the file specified by the File argument.
RAFile(String name, String mode)
          Creates a random access file stream to read from, and optionally to write to, a file with the specified name.
 
Method Summary
 void close()
          Closes this random access file stream and releases any system resources associated with the stream.
 long getFilePointer()
          Returns the current offset in this file.
 RandomAccessFile getRandomAccessFile()
          Gets the random access file object backing this RAFile.
 long length()
          Returns the length of this file.
 int read()
          Reads a byte of data from this file.
 int read(byte[] b)
          Reads up to b.length bytes of data from this file into an array of bytes.
 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()
           
 String readLine()
           
 long readLong()
           
 short readShort()
           
 int readUnsignedByte()
           
 int readUnsignedShort()
           
 String readUTF()
           
 void seek(long pos)
          Sets the file-pointer offset, measured from the beginning of this file, at which the next read or write occurs.
 void setLength(long newLength)
          Sets the length of this file.
 int skipBytes(int n)
           
 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 writeUTF(String str)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

raf

protected RandomAccessFile raf
The random access file object backing this RAFile.

Constructor Detail

RAFile

public RAFile(File file,
              String mode)
       throws FileNotFoundException
Creates a random access file stream to read from, and optionally to write to, the file specified by the File argument.

Throws:
FileNotFoundException

RAFile

public RAFile(String name,
              String mode)
       throws FileNotFoundException
Creates a random access file stream to read from, and optionally to write to, a file with the specified name.

Throws:
FileNotFoundException
Method Detail

getRandomAccessFile

public RandomAccessFile getRandomAccessFile()
Gets the random access file object backing this RAFile.


close

public void close()
           throws IOException
Description copied from interface: IRandomAccess
Closes this random access file stream and releases any system resources associated with the stream.

Specified by:
close in interface IRandomAccess
Throws:
IOException

getFilePointer

public long getFilePointer()
                    throws IOException
Description copied from interface: IRandomAccess
Returns the current offset in this file.

Specified by:
getFilePointer in interface IRandomAccess
Throws:
IOException

length

public long length()
            throws IOException
Description copied from interface: IRandomAccess
Returns the length of this file.

Specified by:
length in interface IRandomAccess
Throws:
IOException

read

public int read()
         throws IOException
Description copied from interface: IRandomAccess
Reads a byte of data from this file.

Specified by:
read in interface IRandomAccess
Throws:
IOException

read

public int read(byte[] b)
         throws IOException
Description copied from interface: IRandomAccess
Reads up to b.length bytes of data from this file into an array of bytes.

Specified by:
read in interface IRandomAccess
Throws:
IOException

read

public int read(byte[] b,
                int off,
                int len)
         throws IOException
Description copied from interface: IRandomAccess
Reads up to len bytes of data from this file into an array of bytes.

Specified by:
read in interface IRandomAccess
Throws:
IOException

seek

public void seek(long pos)
          throws IOException
Description copied from interface: IRandomAccess
Sets the file-pointer offset, measured from the beginning of this file, at which the next read or write occurs.

Specified by:
seek in interface IRandomAccess
Throws:
IOException

setLength

public void setLength(long newLength)
               throws IOException
Description copied from interface: IRandomAccess
Sets the length of this file.

Specified by:
setLength in interface IRandomAccess
Throws:
IOException

readBoolean

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

readByte

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

readChar

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

readDouble

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

readFloat

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

readFully

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

readFully

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

readInt

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

readLine

public String readLine()
                throws IOException
Specified by:
readLine in interface DataInput
Throws:
IOException

readLong

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

readShort

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

readUnsignedByte

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

readUnsignedShort

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

readUTF

public String readUTF()
               throws IOException
Specified by:
readUTF in interface DataInput
Throws:
IOException

skipBytes

public int skipBytes(int n)
              throws IOException
Specified by:
skipBytes in interface DataInput
Throws:
IOException

write

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

write

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

write

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

writeBoolean

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

writeByte

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

writeBytes

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

writeChar

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

writeChars

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

writeDouble

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

writeFloat

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

writeInt

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

writeLong

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

writeShort

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

writeUTF

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