|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.amx.duet.tools.io.FileManager
The FileManager class was created in order to simulate NetLinx file processing. It allows you to open multiple files and manipulate each one individualy until the user chooses to finish processing data by closing each file separately.
Files are processed using the file handle retrieved during a call to FileOpen(). Once the file handle is obtained it can be used in subsequent read, write and close operations.
How to use the FileManager:
String str = "Hello World!"; long lRet = FileManager.FILE_OK; FileManager mngr = FileManager.getInstance(); long handle = mngr.FileOpen("/user/mydir/myfile.txt", FileManager.IOFLAG_NEW); lRet = mngr.FileWrite(handle, str, str.length()); if (lRet != FileManager.FILE_OK) error("Error [" + lRet + "] occurred while writing to file"); ObjectRef rBuffer = new ObjectRef(""); long len = str.length(); lRet = mngr.FileRead(handle, rBuffer, len); if (lRet == FileManager.FILE_OK) diag("rBuffer = " + rBuffer.toString()); lRet = mngr.FileClose(handle);
Field Summary | |
static int |
FILE_ALREADY_CLOSE
|
static int |
FILE_BUFFER_TOO_SMALL
|
static int |
FILE_DIRECTORY_EXISTS
|
static int |
FILE_DIRECTORY_NOT_LOADED
|
static int |
FILE_DISK_ERROR
|
static int |
FILE_DISK_FULL
|
static int |
FILE_END_OF_FILE
|
static int |
FILE_INVALID_DIRECTORY
|
static int |
FILE_INVALID_FILENAME
|
static int |
FILE_INVALID_HANDLE
|
static int |
FILE_INVALID_IOFLAG
|
static int |
FILE_INVALID_PARAMETER
|
static int |
FILE_NAME_EXISTS
|
static int |
FILE_OK
|
static int |
IOFLAG_APPEND
|
static int |
IOFLAG_NEW
|
static int |
IOFLAG_READ
|
Method Summary | |
long |
FileClose(long lFileHandle)
Closes a file opened with FileOpen(). |
long |
FileOpen(java.lang.String sFilePath,
long lIOFlag)
Opens a file for reading or writing. |
long |
FileRead(long lFileHandle,
ObjectRef rStrBuffer,
long lBufLen)
Reads a block of data from the specified file. |
long |
FileReadLine(long lFileHandle,
ObjectRef rStrBuffer,
long lBufLen)
Reads a line of data from the specified file. |
long |
FileSeek(long lFileHandle,
long lPos)
Sets the file pointer to the specified position. |
long |
FileSize(long lFileHandle)
Retrieves the size of a file on disk. |
long |
FileWrite(long lFileHandle,
java.lang.String sBuffer,
long lBufLen)
Writes a block of data to the specified file. |
long |
FileWriteLine(long lFileHandle,
java.lang.String sBuffer,
long lLineLen)
Writes a line of data to the specified file. |
static FileManager |
getInstance()
Get a single instance of this class |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final int FILE_OK
public static final int FILE_INVALID_HANDLE
public static final int FILE_INVALID_FILENAME
public static final int FILE_INVALID_IOFLAG
public static final int FILE_INVALID_DIRECTORY
public static final int FILE_DISK_ERROR
public static final int FILE_INVALID_PARAMETER
public static final int FILE_ALREADY_CLOSE
public static final int FILE_NAME_EXISTS
public static final int FILE_END_OF_FILE
public static final int FILE_BUFFER_TOO_SMALL
public static final int FILE_DISK_FULL
public static final int FILE_DIRECTORY_NOT_LOADED
public static final int FILE_DIRECTORY_EXISTS
public static final int IOFLAG_READ
public static final int IOFLAG_NEW
public static final int IOFLAG_APPEND
Method Detail |
public static FileManager getInstance()
public long FileOpen(java.lang.String sFilePath, long lIOFlag)
If the file is opened successfully, it must be closed (after all reading or writing is completed) by calling FileClose(). If files are not closed, subsequent file open operations may fail due to the limited number of file handles available.
sFilePath
- String containing the path to the file to be opened.lIOFlag
- public long FileClose(long lFileHandle)
lFileHandle
- handle to the file returned by FileOpen().
public long FileRead(long lFileHandle, ObjectRef rStrBuffer, long lBufLen)
lFileHandle
- handle to the file returned by FileOpen().rStrBuffer
- Must be of type String. Buffer to hold the data to be read.
Create rStrBuffer with a valueOf(String) Example:
ObjectRef rStrBuffer = new ObjectRef("") or rStrBuffer.valueOf("")
lBufLen
- maximum number of bytes to read.
public long FileReadLine(long lFileHandle, ObjectRef rStrBuffer, long lBufLen)
This function reads from the current location of the file pointer up to the next carriage
return or to the end-of-file (EOF), whichever comes first. A complete line will not be read
if the buffer length is exceeded before a carriage return (or EOF) is encountered. The bytes
are read from the file identified by lFileHandle and are stored in rStrBuffer. The
Create rStrBuffer with a valueOf(String) Example:
lFileHandle
- handle to the file returned by FileOpen().rStrBuffer
- Must be of type String. Buffer to hold the data to be read.
ObjectRef rStrBuffer = new ObjectRef("") or rStrBuffer.valueOf("")lBufLen
- maximum number of bytes to read.
public long FileSeek(long lFileHandle, long lPos)
After FileSeek() is successfully called, subsequent read or write operations begin at the byte number specified by lPos.
lFileHandle
- handle to the file returned by FileOpen().lPos
- The byte position to set the file pointer (0 = beginning of file, -1 = end of file)
public long FileWrite(long lFileHandle, java.lang.String sBuffer, long lBufLen)
The data will overwrite or append to the current contents of the file depending on the current position of the file pointer.
lFileHandle
- handle to the file returned by FileOpen().sBuffer
- buffer containing the data to write.lBufLen
- number of bytes to write.
public long FileWriteLine(long lFileHandle, java.lang.String sBuffer, long lLineLen)
A
lFileHandle
- handle to the file returned by FileOpen().sBuffer
- buffer containing the data to write.lLineLen
- number of bytes to write.
public long FileSize(long lFileHandle)
lFileHandle
- handle to the file returned by FileOpen().
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |