org.apache.commons.vfs2.provider.ram
Class RamFileRandomAccessContent

java.lang.Object
  extended by org.apache.commons.vfs2.provider.ram.RamFileRandomAccessContent
All Implemented Interfaces:
java.io.DataInput, java.io.DataOutput, RandomAccessContent

public class RamFileRandomAccessContent
extends java.lang.Object
implements RandomAccessContent

RAM File Random Access Content.

Author:
Commons VFS team

Field Summary
protected  int filePointer
          File Pointer
 
Constructor Summary
RamFileRandomAccessContent(RamFileObject file, RandomAccessMode mode)
           
 
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.
 java.io.InputStream getInputStream()
          Get the input stream.
 long length()
          Returns the length of this file.
 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 pos)
          Sets the file-pointer offset, measured from the beginning of this file, at which the next read or write occurs.
 int skipBytes(int n)
           
static byte[] toBytes(long n, byte[] b)
          Build a 8-byte array from a long.
static long toLong(byte[] b)
          Build a long from first 8 bytes of the array.
static short toShort(byte[] b)
          Build a short from first 2 bytes of the array.
static int toUnsignedShort(byte[] b)
          Build a short from first 2 bytes of the array.
 void write(byte[] b)
           
 void write(byte[] b, int off, int len)
           
 void write(int b)
           
 void writeBoolean(boolean v)
           
 void writeByte(int i)
           
 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, toString, wait, wait, wait
 

Field Detail

filePointer

protected int filePointer
File Pointer

Constructor Detail

RamFileRandomAccessContent

public RamFileRandomAccessContent(RamFileObject file,
                                  RandomAccessMode mode)
Parameters:
file - The file to access.
mode - The access mode.
Method Detail

getFilePointer

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

Specified by:
getFilePointer in interface RandomAccessContent
Returns:
the offset from the beginning of the file, in bytes, at which the next read or write occurs.
Throws:
java.io.IOException - if an I/O error occurs.

seek

public void seek(long pos)
          throws java.io.IOException
Description copied from interface: RandomAccessContent
Sets the file-pointer offset, measured from the beginning of this file, at which the next read or write occurs. The offset may be set beyond the end of the file. Setting the offset beyond the end of the file does not change the file length. The file length will change only by writing after the offset has been set beyond the end of the file.
Notice: If you use RandomAccessContent.getInputStream() you have to reget the InputStream after calling RandomAccessContent.seek(long)

Specified by:
seek in interface RandomAccessContent
Parameters:
pos - the offset position, measured in bytes from the beginning of the file, at which to set the file pointer.
Throws:
java.io.IOException - if pos is less than 0 or if an I/O error occurs.

length

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

Specified by:
length in interface RandomAccessContent
Returns:
the length of this file, measured in bytes.
Throws:
java.io.IOException - if an I/O error occurs.

close

public void close()
           throws java.io.IOException
Description copied from interface: RandomAccessContent
Closes this random access file stream and releases any system resources associated with the stream. A closed random access file cannot perform input or output operations and cannot be reopened.

If this file has an associated channel then the channel is closed as well.

Specified by:
close in interface RandomAccessContent
Throws:
java.io.IOException - if an I/O error occurs.

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

readInt

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

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

readBoolean

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

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

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(byte[] b,
                  int off,
                  int len)
           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

writeByte

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

toLong

public static long toLong(byte[] b)
Build a long from first 8 bytes of the array.

Parameters:
b - The byte[] to convert.
Returns:
A long.

toBytes

public static byte[] toBytes(long n,
                             byte[] b)
Build a 8-byte array from a long. No check is performed on the array length.

Parameters:
n - The number to convert.
b - The array to fill.
Returns:
A byte[].

toShort

public static short toShort(byte[] b)
Build a short from first 2 bytes of the array.

Parameters:
b - The byte[] to convert.
Returns:
A short.

toUnsignedShort

public static int toUnsignedShort(byte[] b)
Build a short from first 2 bytes of the array.

Parameters:
b - The byte[] to convert.
Returns:
A short.

write

public void write(int b)
           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

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

readLine

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

getInputStream

public java.io.InputStream getInputStream()
                                   throws java.io.IOException
Description copied from interface: RandomAccessContent
Get the input stream.
Notice: If you use RandomAccessContent.seek(long) you have to reget the InputStream

Specified by:
getInputStream in interface RandomAccessContent
Returns:
the InputStream.
Throws:
java.io.IOException - if an I/O error occurs.