|
OpenTop 1.5 | |||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | Cross-Platform C++ | ||||||
| SUMMARY: CONSTRUCTOR | METHOD | DETAIL: CONSTRUCTOR | METHOD | |||||||
#include "ot/io/RandomAccessFile.h"

This class also implements the interfaces defined by the DataInput and DataOutput classes which provide the capability to read and write integer and string data in a cross-platform compatible manner.
When a RandomAccessFile is created, a connection is established with an open file in the file system. The open file is represented internally using a FileDescriptor which ensures that the file is closed when the RandomAccessFile is destroyed. The file can also be closed using the close() method.
The following example opens a file in read-only mode and reads a 4-byte long integer from the 11th-14th bytes:-
try
{
RefPtr<RandomAccessFile> rpFile =
new RandomAccessFile("random.txt", RandomAccessFile::Read);
rpFile->seek(10); // set offset for next i/o operation
long val = rpFile->readLong(); // read 4-byte long integer from file
}
catch(IOException& e)
{
cerr << e.toString() << endl;
}
| Constructor/Destructor Summary | |
RandomAccessFile(const File& file, Mode mode)Constructs a RandomAccessFile by opening a connection to the file with the abstract pathname denoted by file. | |
RandomAccessFile(const String& name, Mode mode)Constructs a RandomAccessFile by opening a connection to the file with the abstract pathname denoted by name. | |
| Method Summary | |
void |
close()Closes the random access file. |
RefPtr< FileDescriptor > |
getFD() constReturns a FileDescriptor for the open file connected to this file. |
Int64Type |
getFilePointer() constReturns the current value of the file pointer for this file. |
bool |
isClosed()Tests if this file has been closed. |
Int64Type |
length() constReturns the current length of the file. |
long |
read(Byte* pBuffer, size_t bufLen)Reads up to bufLen bytes into the supplied buffer. |
virtual void |
readFully(Byte* pBuffer, size_t bufLen)Reads exactly bufLen bytes from the current position in the file. |
void |
seek(Int64Type pos)Sets the file pointer for this file to the given position, which is an offset (in bytes) from the start of the file. |
void |
setLength(Int64Type newLength)Sets the length of this file, either by extending or truncating it. |
virtual size_t |
skipBytes(size_t n)Repositions the file pointer forward n bytes. |
virtual void |
write(const Byte* pBuffer, size_t bufLen)Writes an array of bytes at the current file position. |
| Methods inherited from class ot::io::DataInput |
readBoolean(), readByte(), readInt64(), readLong(), readShort(), readUnsignedInt64(), readUnsignedLong(), readUnsignedShort(), readUTF() |
| Methods inherited from class ot::io::DataOutput |
writeBoolean(bool), writeByte(Byte), writeInt64(Int64Type), writeLong(long), writeShort(short), writeUnsignedInt64(UInt64Type), writeUnsignedLong(unsigned long), writeUnsignedShort(unsigned short), writeUTF(const String&) |
| Methods inherited from class ot::ManagedObject |
addRef(), getRefCount(), onFinalRelease(), operator=(const ManagedObject&), release() |
| Enumerations |
enum { |
EndOfFile = -1} |
/* End of file reached when read() called */ |
enum Mode { |
Read = 1, |
/* Open the file for reading only */ |
|
Read_Write = 3, |
/* Open the file for reading and writing. The file will be created if it doesn't already exist */ |
|
Read_Write_Sync = 7} |
/* As for Read_Write, but write operations additionally flush the file contents to the underlying device */ |
| Constructor/Destructor Detail |
RandomAccessFile(const File& file,
Mode mode)
If the file does not currently exist on the file system then a file with the abstract pathname will be created if writable access is requested (mode is Read_Write or Read_Write_Sync). If Read access is requested and the file does not exist a FileNotFoundException will be thrown.
file - mode - FileNotFoundException - IOException - RandomAccessFile(const String& name,
Mode mode)
If the file does not currently exist on the file system then a file with the abstract pathname will be created if writable access is requested (mode is Read_Write or Read_Write_Sync). If Read access is requested and the file does not exist a FileNotFoundException will be thrown.
name - mode - FileNotFoundException - IOException - | Method Detail |
void close()
IOException - RefPtr< FileDescriptor > getFD() const
Int64Type getFilePointer() const
IOException - bool isClosed()
Int64Type length() const
IOException - long read(Byte* pBuffer,
size_t bufLen)
pBuffer - bufLen - IllegalArgumentException - NullPointerException - IOException - virtual void readFully(Byte* pBuffer,
size_t bufLen)
pBuffer - bufLen - EOFException - IllegalArgumentException - NullPointerException - IOException - void seek(Int64Type pos)
pos - IOException - void setLength(Int64Type newLength)
If the current length of the file is less than newLength then the file will be extended. On some platforms (mainly UNIX), the contents of the extended portion of the file will be initialized to zeros. On others (notably Windows), the contents of the extended portion of the file is undefined.
newLength - IOException - virtual size_t skipBytes(size_t n)
IOException - virtual void write(const Byte* pBuffer,
size_t bufLen)
pBuffer - bufLen - NullPointerException - IOException -
|
OpenTop 1.5 | |||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | Cross-Platform C++ | ||||||
| SUMMARY: CONSTRUCTOR | METHOD | DETAIL: CONSTRUCTOR | METHOD | |||||||