FileWrapper Class Reference

The PermanentFile and TemporaryFile JavaScript classes. Used to represent an actual image file on disk. More...

Public Slots

FileWrappersetPath (String &path)
 Specify absolute path of this image file. Name of file can not be changed if there is an open stream. More...
 
String path ()
 Retrieves the full file path. More...
 
FileWrappersetExtension (String &ext)
 Change extension for file name. Extension won't change if there is an open stream. More...
 
String extension ()
 Retrieve file extension. More...
 
bool exists ()
 Verify if file exists on the disk. More...
 
bool remove ()
 Remove physical file manually. Cannot remove file if there is an open stream. More...
 
void setTextCodec (String &codecName)
 Sets the codec for this file wrapper for the encoding specified by codecName. Common values for codecName include "ISO 8859-1", "UTF-8", and "UTF-16". More...
 
Stream Manipulation
bool isOpen ()
 Check if file is opened. More...
 
bool isClose ()
 Checks if the file is closed. More...
 
bool open (int m=int(FileIOType::WRITE_ONLY))
 Opens the file stream for read/write. More...
 
bool close ()
 Closes the file stream. More...
 
void write (String &text)
 Write string in current stream. More...
 
void writeLine (String &text)
 Write string line in current stream. More...
 
void writeFile (FileWrapper file)
 Write entire contents of the parameter file in the current stream. More...
 
String read ()
 Read entire content of stream. More...
 
String readLine ()
 Read single line of stream. More...
 
File management
bool move (FileWrapper dest)
 Moves the current FileWrapper to a new FileWrapper destination. More...
 
bool copy (FileWrapper dest)
 Copy current FileWrapper to new FileWrapper destination. More...
 

Public Member Functions

 FileWrapper ()
 Create a new FileWrapper. More...
 
 FileWrapper (String path)
 Create a new FileWrapper. More...
 

Detailed Description

The PermanentFile and TemporaryFile JavaScript classes. Used to represent an actual image file on disk.

Files can be instantiated in the scripting environment or retrieved in an SM_InputPortWrapper object.

There are two possible constructors: the PermanentFile or TemporaryFile. The PermanentFile takes the name of a file as an argument.

file = new PermanentFile( "C:\file.txt" );
file.open( IO.WRITE_ONLY ); // open with write only stream
file.writeLine( "Hello World!" ); // write line to file
file.close(); // close file

The TemporaryFile takes an extension as an argument, an returns a temporary file with that extension. The temporary file and its containing directory will be deleted on exit.

file = new TemporaryFile( "txt" );
file.open( IO.WRITE_ONLY ); // open with write only stream
file.writeLine( "Hello World!" ); // write line to file
file.close(); // close file

Constructor & Destructor Documentation

◆ FileWrapper() [1/2]

FileWrapper::FileWrapper ( )

Create a new FileWrapper.

◆ FileWrapper() [2/2]

FileWrapper::FileWrapper ( String  path)

Create a new FileWrapper.

Parameters
pathPath to physical FileWrapper

Member Function Documentation

◆ close

bool FileWrapper::close ( )
slot

Closes the file stream.

Returns
Returns true if successful.

◆ copy

bool FileWrapper::copy ( FileWrapper  dest)
slot

Copy current FileWrapper to new FileWrapper destination.

Parameters
dest: The desired destination of the FileWrapper.
Returns
Returns true if successful.

◆ exists

bool FileWrapper::exists ( )
slot

Verify if file exists on the disk.

Returns
Returns true if the file exists on the disk.

◆ extension

String FileWrapper::extension ( )
slot

Retrieve file extension.

Returns
Returns the file extension String.

◆ isClose

bool FileWrapper::isClose ( )
slot

Checks if the file is closed.

Returns
Returns true if the file is closed.

◆ isOpen

bool FileWrapper::isOpen ( )
slot

Check if file is opened.

Returns
Returns true if the file is open.

◆ move

bool FileWrapper::move ( FileWrapper  dest)
slot

Moves the current FileWrapper to a new FileWrapper destination.

Parameters
dest: The desired destination of the FileWrapper.
Returns
Returns true if successful.

◆ open

bool FileWrapper::open ( int  m = int(FileIOType::WRITE_ONLY))
slot

Opens the file stream for read/write.

Parameters
m: IO stream descriptor.
Returns
Returns true if successful.

◆ path

String FileWrapper::path ( )
slot

Retrieves the full file path.

Returns
Returns the full file path String.

◆ read

String FileWrapper::read ( )
slot

Read entire content of stream.

Returns
Returns the content of the stream as a String.

◆ readLine

String FileWrapper::readLine ( )
slot

Read single line of stream.

Returns
Returns a single line from the stream as a String.

◆ remove

bool FileWrapper::remove ( )
slot

Remove physical file manually. Cannot remove file if there is an open stream.

Returns
Returns true if successful.

◆ setExtension

FileWrapper& FileWrapper::setExtension ( String &  ext)
slot

Change extension for file name. Extension won't change if there is an open stream.

Parameters
ext: Extension String of image file.
Returns
Returns the FileWrapper reference.

◆ setPath

FileWrapper& FileWrapper::setPath ( String &  path)
slot

Specify absolute path of this image file. Name of file can not be changed if there is an open stream.

Parameters
path: Absolute path String of image file.
Returns
Returns the FileWrapper reference.

◆ setTextCodec

void FileWrapper::setTextCodec ( String &  codecName)
slot

Sets the codec for this file wrapper for the encoding specified by codecName. Common values for codecName include "ISO 8859-1", "UTF-8", and "UTF-16".

Parameters
codecName: the codec name

◆ write

void FileWrapper::write ( String &  text)
slot

Write string in current stream.

Parameters
text: Text to write.

◆ writeFile

void FileWrapper::writeFile ( FileWrapper  file)
slot

Write entire contents of the parameter file in the current stream.

Parameters
file: FileWrapper object.

◆ writeLine

void FileWrapper::writeLine ( String &  text)
slot

Write string line in current stream.

Parameters
text: Text to write.