Class

StandardOutputStream


Description

Used for writing data to the output or error streams in console applications.

Methods

Name

Parameters

Returns

Shared

Flush

Operator_Convert

TCPSocket

Write

Data As String

WriteLine

data As String

Method descriptions


StandardOutputStream.Flush

Flush

Immediately sends the contents of internal write buffers to disk or to the output stream.

This function can be useful in point-to-point communication over sockets and similar connections: To optimize for transmission performance, some types of output streams try to collect small pieces of written data into one larger piece for sending instead of sending each piece out individually. By calling Flush, the data collection is stopped and the data is sent without further delay, reducing latency.

When using this on a stream that ends up as a file on disk, it is useful, too: Any short parts of previously written data are written to disk right away, ensuring the data is actually on disk if the application terminates abruptly, e.g. due to a crash.

Avoid calling this method too often. For example, do not call it between successive Write calls because you'll slow down performance without getting much benefit.

A typical use case would look like this:

mySocket.Write("you typed: ")
mySocket.Write(key)
mySocket.Write(".")
mySocket.Flush

StandardOutputStream.Operator_Convert

Operator_Convert As TCPSocket

Used to convert to a TCPSocket. See the Operator Convert method.

StandardOutputStream incorporates a conversion operator so that you can use StdOut and StdErr as TCPSockets. This is useful only for services that are started for you by xinetd on macOS or Linux. Here is an example of how to use this:

Var Outgoing As TCPSocket = StdOut
Var ErrMsg As TCPSocket = StdErr

StandardOutputStream.Write

Write(Data As String)

Writes the passed data to the output stream.

Note that in order to make sure that the data actually ends up on disk or gets sent to the socket it is connected to, the stream must either get closed or the Flush method be called. Otherwise, the data, if small, may end up temporarily in a write buffer before either a certain time has passed or more data is written. This buffering increases performance when writing lots of small pieces of data, but may be causing unwanted delays when another process, e.g. the other end of a socket connection, is waiting for the data. Consider calling the Flush method to reduce latencies that this buffering may cause in such cases.

If Write fails, an IOException will be raised.

This example displays the Save As dialog box and writes the contents of the TextArea1 to a text file.

Var f As FolderItem
Var stream As BinaryStream
f = FolderItem.ShowSaveFileDialog(FileTypes1.Text, "Untitled.txt")
If f<> Nil Then
  stream = BinaryStream.Create(f, True)
  stream.Write(TextArea1.Text)
  stream.Close
End If

StandardOutputStream.WriteLine

WriteLine(data As String)

Writes data to the output stream. WriteLine appends the NewLine character to data.

stdout.writeline ("This is going to the output device.")

Interfaces

The StandardOutputStream class implements the Writeable class interface.

Notes

Since there is only one StandardOutputStream for the system, you do not need to create a StandardOutputStream object to use; you just use StdOut or StdErr for the Error stream.

StandardOutputStream incorporates a conversion operator so that you can use StdOut and StdErr as TCPSockets. This is useful only for services that are started for you by xinetd on macOS or Linux. Here is an example of how to use this:

Var outgoing As TCPSocket = StdOut
Var errMsg As TCPSocket = StdErr

Compatibility

All project types on all supported operating systems.

See also

Object parent class; ConsoleApplication class; Input, Print, StandardInputStream, StdErr, StdIn, StdOut, methods; TargetDesktop constant.