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

java.lang.Object
  extended byorg.apache.commons.vfs.provider.ram.RamFileRandomAccessContent
All Implemented Interfaces:
DataInput, DataOutput, RandomAccessContent

public class RamFileRandomAccessContent
extends Object
implements RandomAccessContent

RAM File Random Access Content


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.
 InputStream getInputStream()
          get the input stream
Notice: If you use seek(long) you have to reget the InputStream
 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()
           
 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.
 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(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

filePointer

protected int filePointer
File Pointer

Constructor Detail

RamFileRandomAccessContent

public RamFileRandomAccessContent(RamFileObject file,
                                  RandomAccessMode mode)
Parameters:
mode -
Method Detail

getFilePointer

public long getFilePointer()
                    throws 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:
IOException - if an I/O error occurs.

seek

public void seek(long pos)
          throws 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:
IOException - if pos is less than 0 or if an I/O error occurs.

length

public long length()
            throws 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:
IOException - if an I/O error occurs.

close

public void close()
           throws 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:
IOException - if an I/O error occurs.

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

readInt

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

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

readBoolean

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

skipBytes

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

readUTF

public String readUTF()
               throws IOException
Specified by:
readUTF in interface DataInput
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(byte[] b)
           throws IOException
Specified by:
write in interface DataOutput
Throws:
IOException

writeByte

public void writeByte(int i)
               throws IOException
Specified by:
writeByte in interface DataOutput
Throws:
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 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

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

readLine

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

getInputStream

public InputStream getInputStream()
                           throws 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
Throws:
IOException


Copyright © 2002-2006 The Apache Software Foundation. All Rights Reserved.