com.phoenix_int.aserver.types
Class PHXRawFile

java.lang.Object
  extended by com.phoenix_int.aserver.types.PHXSimpleType
      extended by com.phoenix_int.aserver.types.PHXRawFile
All Implemented Interfaces:
IPHXType, IPHXType2, IPHXUnits

public class PHXRawFile
extends PHXSimpleType
implements IPHXType2

The Phoenix type for Files. This class has the following properties:


Constructor Summary
PHXRawFile()
           
PHXRawFile(java.lang.String fileName)
           
PHXRawFile(java.lang.String baseName, java.lang.String name)
           
 
Method Summary
 void addMonitor(PHXFileMonitor fm)
          PHXFileMonitor is used to monitor changes to a file as it is being created as in the UNIX 'tail -f' command.
 void backupFile()
          Backup the file on disk.
 void backupFile(java.lang.String fileName)
          Backup the file on disk.
 void deleteFile()
          deletes the file from disk
 void deleteFile(java.lang.String fileName)
          deletes the file from disk
 void fromFile()
          loads the file from disk
 void fromFile(java.lang.String filename)
          Sets the filename and then reads from disk.
 void fromString(java.lang.String value)
          converts a String representation to the internal value
 void fromString2(PHXStringBuffer newContents)
           
 java.lang.String getBaseName()
          gets the base name of the file
 java.lang.String getContents()
          retrieves the contents of the file
 java.lang.String getFileExtension()
          Returns the extension of the file that this object represents
 boolean getIsBinary()
          Tells whether or not the the file is binary.
 java.lang.String getMimeType()
           
 java.lang.String getName()
          retrieves the name of the file
 java.lang.String getNameCoded()
          retrieves the name of the file in coded form (without $variables replaced)
 java.lang.String getURL()
          Tells whether the file is meant to be transferred by proxy
 java.io.InputStream getValueStream()
           
 long getValueStreamLen()
           
 boolean hasChanged()
          checks to see if the file has changed since the last time getContents() was called
 void markAsRead()
          call this function after you manually get the contents of the file.
 void readFile()
          loads the file from disk
 void readFile(boolean useDFT)
          loads the file from disk
 void readFile(java.lang.String filename)
          Sets the filename and then reads from disk.
 void removeMonitor(PHXFileMonitor fm)
          Removes a file monitor from our list
 void setBaseName(java.lang.String v)
          sets the base name of the file
 void setContents(java.lang.String contents)
          sets the contents of the file.
 void setFileExtension(java.lang.String extension)
          Sets the extension of the file that this object represents.
 void setIsBinary(boolean m)
          Forces this file to be binary or not.
 void setMetaData(PHXRawFile metaData)
           
 void setMimeType(java.lang.String m)
           
 void setName(java.lang.String v)
          sets the name of the file
 void setNeedWrite(boolean needWrite)
           
 void setStringReplacer(PHXStringReplacer r)
          specifies a PHXStringReplacer object for use in forming the full file name.
 void setURL(java.lang.String url)
          sets whether the file is meant to be transferred by proxy or not
 boolean synched()
          Is this file variable's value consistent with the actual file on disk?
 void toFile()
          writes the file to disk
 void toFile(java.lang.String fileName)
          sets the filename and then writes the file to disk.
 java.lang.String toString()
          converts the variable to a string
 PHXStringBuffer toString2()
           
 void writeFile()
          writes the file to disk
 void writeFile(java.lang.String fileName)
          sets the filename and then writes the file to disk.
 
Methods inherited from class com.phoenix_int.aserver.types.PHXSimpleType
addPropertyChangeListener, getDescription, getEnumTokens, getHasChanged, getUnits, removePropertyChangeListener, setDescription, setHasChanged, setUnits
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PHXRawFile

public PHXRawFile()

PHXRawFile

public PHXRawFile(java.lang.String fileName)

PHXRawFile

public PHXRawFile(java.lang.String baseName,
                  java.lang.String name)
Method Detail

getName

public java.lang.String getName()
retrieves the name of the file

Returns:
the name of the file

addMonitor

public void addMonitor(PHXFileMonitor fm)
PHXFileMonitor is used to monitor changes to a file as it is being created as in the UNIX 'tail -f' command. Unfortunately in Windows, this creates a file lock which prevents deleting the file. Therefore, we keep a list of all the monitors currently monitoring us, and we signal them anytime that our filename or base name changes so they can stop monitoring.


removeMonitor

public void removeMonitor(PHXFileMonitor fm)
Removes a file monitor from our list


synched

public boolean synched()
Is this file variable's value consistent with the actual file on disk?


setNeedWrite

public void setNeedWrite(boolean needWrite)

setURL

public void setURL(java.lang.String url)
sets whether the file is meant to be transferred by proxy or not

Parameters:
b - is the file to be sent by proxy?

getNameCoded

public java.lang.String getNameCoded()
retrieves the name of the file in coded form (without $variables replaced)

Returns:
the name of the file in coded form

getFileExtension

public java.lang.String getFileExtension()
Returns the extension of the file that this object represents


setFileExtension

public void setFileExtension(java.lang.String extension)
                      throws java.io.IOException
Sets the extension of the file that this object represents.

It is preferred that you use setName() and let the system automatically figure out the extension based on what you pass in. Then, you can use readFile() and writeFile() without passing filenames to those calls. This allows for progress monitoring to work correctly in all cases.

Throws:
java.io.IOException

setName

public void setName(java.lang.String v)
             throws java.io.IOException
sets the name of the file

Parameters:
v - the name
Throws:
java.io.IOException

setBaseName

public void setBaseName(java.lang.String v)
                 throws java.io.IOException
sets the base name of the file

Parameters:
v - the name
Throws:
java.io.IOException

getBaseName

public java.lang.String getBaseName()
gets the base name of the file

Returns:
the name

setStringReplacer

public void setStringReplacer(PHXStringReplacer r)
specifies a PHXStringReplacer object for use in forming the full file name.

Parameters:
r - the string replacer object

getIsBinary

public boolean getIsBinary()
Tells whether or not the the file is binary. Simply switches on whether or not the mime type starts with text.


getURL

public java.lang.String getURL()
Tells whether the file is meant to be transferred by proxy


setIsBinary

public void setIsBinary(boolean m)
Forces this file to be binary or not. If this causes the mode to change, will set the mime type to text/plain or application/octet-stream as appropriate.


getMimeType

public java.lang.String getMimeType()

setMimeType

public void setMimeType(java.lang.String m)

setContents

public void setContents(java.lang.String contents)
                 throws java.io.IOException
sets the contents of the file. The actual file is not modified until the writeFile() method is issued. Remember that when dealing with text files, setContents handles Java style strings, which must be in bare LF, or Unix style newline format. In binary format, setContents should be the base64 encoded data.

Parameters:
contents - the contents of the file
Throws:
java.io.IOException

getContents

public java.lang.String getContents()
                             throws java.io.IOException
retrieves the contents of the file

Returns:
the contents of the file
Throws:
java.io.IOException

fromFile

public void fromFile(java.lang.String filename)
              throws java.io.IOException
Sets the filename and then reads from disk. It is preferred that you use setName() when you create a PHXRawFile and then use readFile() without passing a filename to it. This allows progress monitoring to work correctly in all cases.

Throws:
java.io.IOException - thrown if the file can't be loaded.

readFile

public void readFile(java.lang.String filename)
              throws java.io.IOException
Sets the filename and then reads from disk. It is preferred that you use setName() when you create a PHXRawFile and then use readFile() without passing a filename to it. This allows progress monitoring to work correctly in all cases.

Throws:
java.io.IOException - thrown if the file can't be loaded.

fromFile

public void fromFile()
              throws java.io.IOException
loads the file from disk

Throws:
java.io.IOException - thrown if the file can't be loaded.

readFile

public void readFile(boolean useDFT)
              throws java.io.IOException
loads the file from disk

Parameters:
useDFT - If true, the file won't really be read but instead its existence will be verified and a flag set.
Throws:
java.io.IOException - thrown if the file can't be loaded.

deleteFile

public void deleteFile(java.lang.String fileName)
                throws java.io.IOException
deletes the file from disk

Parameters:
the - file to delete
Throws:
java.io.IOException

deleteFile

public void deleteFile()
deletes the file from disk


backupFile

public void backupFile(java.lang.String fileName)
                throws java.io.IOException
Backup the file on disk. File is at the same location with ".bac" appended to the end. If a file by that name already exists, it is deleted prior to moving.

Parameters:
the - file to backup
Throws:
java.io.IOException

backupFile

public void backupFile()
Backup the file on disk. File is at the same location with ".bac" appended to the end. If a file by that name already exists, it is deleted prior to moving.


readFile

public void readFile()
              throws java.io.IOException
loads the file from disk

Throws:
java.io.IOException - thrown if the file can't be loaded.

markAsRead

public void markAsRead()
call this function after you manually get the contents of the file. The function records it's name and timestamp for use with the hasChanged() function


hasChanged

public boolean hasChanged()
checks to see if the file has changed since the last time getContents() was called

Returns:
true if the timestamp of the file is new, or if the file name has changed

toFile

public void toFile(java.lang.String fileName)
            throws java.io.IOException
sets the filename and then writes the file to disk. It is preferred that you use setName() when you create a PHXRawFile and then use writeFile() without passing a filename to it. This allows progress monitoring to work correctly in all cases.

Throws:
java.io.IOException - thrown if the file can't be written.

writeFile

public void writeFile(java.lang.String fileName)
               throws java.io.IOException
sets the filename and then writes the file to disk. It is preferred that you use setName() when you create a PHXRawFile and then use writeFile() without passing a filename to it. This allows progress monitoring to work correctly in all cases.

Throws:
java.io.IOException - thrown if the file can't be written.

toFile

public void toFile()
            throws java.io.IOException
writes the file to disk

Throws:
java.io.IOException - thrown if the file can't be written.

writeFile

public void writeFile()
               throws java.io.IOException
writes the file to disk

Throws:
java.io.IOException - thrown if the file can't be written.

getValueStreamLen

public long getValueStreamLen()
                       throws java.io.IOException
Throws:
java.io.IOException

getValueStream

public java.io.InputStream getValueStream()
                                   throws java.io.IOException
Throws:
java.io.IOException

toString2

public PHXStringBuffer toString2()
                          throws java.io.IOException
Specified by:
toString2 in interface IPHXType2
Throws:
java.io.IOException

fromString2

public void fromString2(PHXStringBuffer newContents)
                 throws java.io.IOException,
                        PHXGetByUrlException
Specified by:
fromString2 in interface IPHXType2
Throws:
java.io.IOException
PHXGetByUrlException

toString

public java.lang.String toString()
converts the variable to a string

Specified by:
toString in interface IPHXType
Overrides:
toString in class java.lang.Object
Returns:
a String representation of the variable

fromString

public void fromString(java.lang.String value)
converts a String representation to the internal value

Specified by:
fromString in interface IPHXType
Parameters:
value - the value to convert

setMetaData

public void setMetaData(PHXRawFile metaData)