com.isti.util
Class FileDataMonitor

java.lang.Object
  extended by com.isti.util.ErrorMessageMgr
      extended by com.isti.util.FileDataMonitor
All Implemented Interfaces:
ErrorMsgMgrIntf

public class FileDataMonitor
extends ErrorMessageMgr

Class FileDataMonitor reads in the data from a file and then monitors the file for changes. The last-modified date on the file is used to detect when its data has changed. The file may be specified as a local pathname or as a remote URL. The file is accessed via a separate thread (using a timeout) to prevent the possibility of having the calling thread held up because of an indefinite I/O block.


Field Summary
static byte[] ERROR_ARRAY
          Empty array used to indicate error.
static byte[] NO_FILE_ARRAY
           
 
Constructor Summary
FileDataMonitor(java.lang.String fNameStr)
          Creates a file-data-monitor object.
FileDataMonitor(java.lang.String fNameStr, boolean allowMissingFlag)
          Creates a file-data-monitor object.
 
Method Summary
 byte[] checkReadFileData(int timeOutMs, long maxReadBytesLimit)
          Checks if the file has been modified and returns its contents if so.
 byte[] checkReadFileData(int timeOutMs, long maxReadBytesLimit, boolean forceFileReadFlag)
          Checks if the file has been modified and returns its contents if so.
 java.net.URL getFileAccessUrlObj()
          Returns the URL used to access the file in the last call to the 'checkReadFileData()' method.
 long getFileLastModifiedTimeMs()
          Returns the last-modified time for the file in the last call to the 'checkReadFileData()' method.
 java.lang.String getFileNameString()
          Returns the name of the file being monitored.
 long getPrevFileLastModTimeMs()
          Returns the previous last-modified time for the file in the last call to the 'checkReadFileData()' method.
 
Methods inherited from class com.isti.util.ErrorMessageMgr
clearErrorMessageString, clearFetchedErrorMessage, enterErrorMessageString, getErrorMessageFlag, getErrorMessageString, getUnfetchedMessageFlag, setErrorMessageString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ERROR_ARRAY

public static final byte[] ERROR_ARRAY
Empty array used to indicate error.


NO_FILE_ARRAY

public static final byte[] NO_FILE_ARRAY
Constructor Detail

FileDataMonitor

public FileDataMonitor(java.lang.String fNameStr,
                       boolean allowMissingFlag)
Creates a file-data-monitor object.

Parameters:
fNameStr - name of file to be read and monitored.
allowMissingFlag - true to allow the file to be missing (and not generate an error); false to generate an error when the file is missing (the default).

FileDataMonitor

public FileDataMonitor(java.lang.String fNameStr)
Creates a file-data-monitor object.

Parameters:
fNameStr - name of file to be read and monitored.
Method Detail

checkReadFileData

public byte[] checkReadFileData(int timeOutMs,
                                long maxReadBytesLimit,
                                boolean forceFileReadFlag)
Checks if the file has been modified and returns its contents if so. The first time this method is called the file data will be returned.

Parameters:
timeOutMs - timeout value for file access, or 0 for infinite.
maxReadBytesLimit - maximum number of bytes to read from file, or 0 for no limit.
forceFileReadFlag - true to force reading of file data; false to only read file data if file-modified time changed.
Returns:
A byte array containing the file data, 'null' if the file has not been modified, 'NO_FILE_ARRAY' if the file was not found (and the 'allowMissingFlag' constructor parameter was set to 'true), or 'ERROR_ARRAY' if an error occurred (in which case the 'getErrorMessageString()' method may be used to fetch the error message).

checkReadFileData

public byte[] checkReadFileData(int timeOutMs,
                                long maxReadBytesLimit)
Checks if the file has been modified and returns its contents if so. The first time this method is called the file data will be returned.

Parameters:
timeOutMs - timeout value for file access, or 0 for infinite.
maxReadBytesLimit - maximum number of bytes to read from file, or 0 for no limit.
Returns:
A byte array containing the file data, 'null' if the file has not been modified, 'NO_FILE_ARRAY' if the file was not found (and the 'allowMissingFlag' constructor parameter was set to 'true), or 'ERROR_ARRAY' if an error occurred (in which case the 'getErrorMessageString()' method may be used to fetch the error message).

getFileNameString

public java.lang.String getFileNameString()
Returns the name of the file being monitored.

Returns:
The file name string.

getFileAccessUrlObj

public java.net.URL getFileAccessUrlObj()
Returns the URL used to access the file in the last call to the 'checkReadFileData()' method.

Returns:
The URL used to access the file in the last call to the 'checkReadFileData()' method, or null if none available.

getFileLastModifiedTimeMs

public long getFileLastModifiedTimeMs()
Returns the last-modified time for the file in the last call to the 'checkReadFileData()' method.

Returns:
The last-modified time for the file in the last call to the 'checkReadFileData()' method, or 0 if not available.

getPrevFileLastModTimeMs

public long getPrevFileLastModTimeMs()
Returns the previous last-modified time for the file in the last call to the 'checkReadFileData()' method.

Returns:
The previous last-modified time for the file in the last call to the 'checkReadFileData()' method, or 0 if not available.