Class

# StandardOutputStream

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

## Description

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

## Methods

<div class="rst-class">

table-centered_column_4

</div>

| Name                                                      | Parameters                              | Returns                                | Shared |
|-----------------------------------------------------------|-----------------------------------------|----------------------------------------|--------|
| `Flush<standardoutputstream.flush>`                       |                                         |                                        |        |
| `Operator_Convert<standardoutputstream.operator_convert>` |                                         | `TCPSocket</api/networking/tcpsocket>` |        |
| `Write<standardoutputstream.write>`                       | msg As `String</api/data_types/string>` |                                        |        |
| `WriteLine<standardoutputstream.writeline>`               | msg As `String</api/data_types/string>` |                                        |        |

## Method descriptions

<div id="standardoutputstream.flush">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

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:
>
> ``` xojo
> mySocket.Write("you typed: ")
> mySocket.Write(key)
> mySocket.Write(".")
> mySocket.Flush
> ```

<div id="standardoutputstream.operator_convert">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

StandardOutputStream.Operator_Convert

**Operator_Convert** As `TCPSocket</api/networking/tcpsocket>`

> Used to convert to a `TCPSocket</api/networking/tcpsocket>`. See the `Operator Convert</api/language/operators/operator_overloads/operator_convert>` method.
>
> <span class="title-ref">StandardOutputStream</span> incorporates a conversion operator so that you can use `StdOut</api/console/stdout>` and `StdErr</api/console/stderr>` as `TCPSockets</api/networking/tcpsocket>`. 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:
>
> ``` xojo
> Var Outgoing As TCPSocket = StdOut
> Var ErrMsg As TCPSocket = StdErr
> ```

<div id="standardoutputstream.write">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

StandardOutputStream.Write

**Write**(msg As `String</api/data_types/string>`)

> Writes the passed data (*msg*) 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<writeable.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<writeable.flush>` method to reduce latencies that this buffering may cause in such cases.
>
> If Write fails, an `IOException</api/exceptions/ioexception>` will be raised.
>
> This example displays the Save As dialog box and writes the contents of the TextArea1 to a text file.
>
> ``` xojo
> 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
> ```

<div id="standardoutputstream.writeline">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

StandardOutputStream.WriteLine

**WriteLine**(msg As `String</api/data_types/string>`)

> Writes the passeed data (*msg*) to the output stream. WriteLine appends the NewLine character to *msg*.
>
> ``` xojo
> stdout.writeline ("This is going to the output device.")
> ```

## Interfaces

This class implements the `Writeable</api/files/writeable>` class interface.

## Notes

Since there is only one <span class="title-ref">StandardOutputStream</span> for the system, you do not need to create a <span class="title-ref">StandardOutputStream</span> object to use; you just use `StdOut</api/console/stdout>` or `StdErr</api/console/stderr>` for the Error stream.

<span class="title-ref">StandardOutputStream</span> incorporates a conversion operator so that you can use `StdOut</api/console/stdout>` and `StdErr</api/console/stderr>` as `TCPSockets</api/networking/tcpsocket>`. 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:

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

## Compatibility

|                       |              |
|-----------------------|--------------|
| **Project Types**     | Console, Web |
| **Operating Systems** | All          |

<div class="seealso">

`Object</api/data_types/additional_types/object>` parent class; `ConsoleApplication</api/console/consoleapplication>` class; `Input</api/console/input>`, `Print</api/console/print>`, `StandardInputStream</api/console/standardinputstream>`, `StdErr</api/console/stderr>`, `StdIn</api/console/stdin>`, `StdOut</api/console/stdout>`, methods; `TargetConsole</api/compiler_directives/targetconsole>` constant.

</div>
