Previous: , Up: Classes   [Index]


WriteFileStream

WriteFileStream Class

Class WriteFileStream provides objects and methods for writing to files, including the application’s stdout and stderr output channels.

Because the way UNIX and Linux file stream modes work, a WriteFileStream opens file non-destructively; that is, for reading and writing, which means that programs can actually perform both reads and writes from a WriteFileStream.

All of the methods for reading files are defined in ReadFileStream class, however. See ReadFileStream. It’s safer to handle existing files when they are opened for reading; i.e., as a ReadFileStream object.

That means openOn won’t truncate an existing file. To start with a new file, use deleteFile (class FileStream). See FileStream.

In that case, and also any time that openOn doesn’t find a file with that path name, it creates the file first.


  writeFile deleteFile "my/file/path";
  writeFile openOn "my/file/path";

To append to an existing file, use seekToEnd (also in FileStream class). See FileStream.


  writeFile openOn "my/file/path";
  writeFile seekToEnd;
  writeFile writeStream appendLine;
  writeFile closeStream;

Instance Variables

None

Class Variables

stdoutStream

The stdoutStream object contains the application’s standard output channel.

stderrStream

The stderrStream object contains the application’s standard error channel.

Instance Methods

new (stream1, stream2, stream3, ...;)

Creates one or more new WriteFileStream objects with the names given in the argument list; e.g.,


WriteFileStream new stream1, stream2, stream3;

openOn (String path_name)

Open file path and set the receiver’s value to the file output stream. The file is created if it does not exist. Raises a systemErrnoException if an error occurs.

printOn (char *fmt, ...)

Format and print the method’s arguments to the receiver, which must be a WriteFileStream object that has been opened with openOn.

value

Returns the receiver’s value instance variable.

writeChar char

Writes char to the receiver’s output file stream.

writeFormat (char *fmt, ...)

Writes its arguments to the receiver using format fmt.

writeStream string

Write string to the receiver’s output file stream.

writeVec (Vector vector_object)

Write the contents of vector_object to the receiver stream. The length of the data written is determined by vector_object’s length instance variable. This allows the method to write binary data that may contain NULLs and other non-human readable characters. See Vector.


Previous: , Up: Classes   [Index]