org.apache.commons.vfs
Class RACRandomAccessFile

java.lang.Object
  extended by java.io.RandomAccessFile
      extended by org.apache.commons.vfs.RACRandomAccessFile
All Implemented Interfaces:
Closeable, DataInput, DataOutput, RandomAccessContent

public class RACRandomAccessFile
extends RandomAccessFile
implements RandomAccessContent

Encapsulates a RandomAccessContent instance, allowing it to be used as a RandomAccessFile instance.

Version:
1.1, $LastChangedRevision: 1163 $, $LastChangedDate: 2006-12-13 03:18:57 +0000 (Qua, 13 Dez 2006) $
Author:
Elifarley Callado Coelho Cruz

Field Summary
protected  byte[] singleByteBuf
           
 
Constructor Summary
RACRandomAccessFile(RandomAccessContent rac)
           
 
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.
 long length()
          Returns the length of this file.
 int read()
           
 int read(byte[] b)
           
 int read(byte[] b, int off, int len)
           
 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)
           
 int skipBytes(int n)
           
 void write(byte[] b)
           
 void write(byte[] b, int off, int len)
           
 void write(int b)
           
 
Methods inherited from class java.io.RandomAccessFile
getChannel, getFD, readBoolean, readByte, readChar, readDouble, readFloat, readFully, readFully, readInt, readLine, readLong, readShort, readUnsignedByte, readUnsignedShort, readUTF, writeBoolean, writeByte, writeBytes, writeChar, writeChars, writeDouble, writeFloat, writeInt, writeLong, writeShort, writeUTF
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.io.DataOutput
writeBoolean, writeByte, writeBytes, writeChar, writeChars, writeDouble, writeFloat, writeInt, writeLong, writeShort, writeUTF
 
Methods inherited from interface java.io.DataInput
readBoolean, readByte, readChar, readDouble, readFloat, readFully, readFully, readInt, readLine, readLong, readShort, readUnsignedByte, readUnsignedShort, readUTF
 

Field Detail

singleByteBuf

protected final byte[] singleByteBuf
Constructor Detail

RACRandomAccessFile

public RACRandomAccessFile(RandomAccessContent rac)
                    throws IOException
Throws:
IOException
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
Overrides:
getFilePointer in class RandomAccessFile
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
Overrides:
seek in class RandomAccessFile
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.

skipBytes

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

length

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

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

setLength

public void setLength(long newLength)
               throws IOException
Overrides:
setLength in class RandomAccessFile
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
Returns:
the InputStream.
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 Closeable
Specified by:
close in interface RandomAccessContent
Overrides:
close in class RandomAccessFile
Throws:
IOException - if an I/O error occurs.

read

public final int read(byte[] b)
               throws IOException
Overrides:
read in class RandomAccessFile
Throws:
IOException
See Also:
RandomAccessFile.read(byte[])

read

public final int read()
               throws IOException
Overrides:
read in class RandomAccessFile
Throws:
IOException
See Also:
RandomAccessFile.read()

read

public int read(byte[] b,
                int off,
                int len)
         throws IOException
Overrides:
read in class RandomAccessFile
Throws:
IOException

write

public final void write(int b)
                 throws IOException
Specified by:
write in interface DataOutput
Overrides:
write in class RandomAccessFile
Throws:
IOException
See Also:
RandomAccessFile.write(int)

write

public final void write(byte[] b)
                 throws IOException
Specified by:
write in interface DataOutput
Overrides:
write in class RandomAccessFile
Throws:
IOException
See Also:
RandomAccessFile.write(byte[])

write

public void write(byte[] b,
                  int off,
                  int len)
           throws IOException
Specified by:
write in interface DataOutput
Overrides:
write in class RandomAccessFile
Throws:
IOException
See Also:
RandomAccessFile.write(byte[],int,int)


Copyright © 2002-2011 Apache Software Foundation. All Rights Reserved.