Class

# StandardInputStream

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

## Description

Used for reading text input in a `ConsoleApplication</api/console/consoleapplication>`.

## Methods

<div class="rst-class">

table-centered_column_4

</div>

| Name                                                     | Parameters                                                                                                                               | Returns                                | Shared |
|----------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------|--------|
| `EndOfFile<standardinputstream.endoffile>`               |                                                                                                                                          | `Boolean</api/data_types/boolean>`     |        |
| `Operator_Convert<standardinputstream.operator_convert>` |                                                                                                                                          | `TCPSocket</api/networking/tcpsocket>` |        |
| `Read<standardinputstream.read>`                         | Count As `Integer</api/data_types/integer>`, encoding As `TextEncoding</api/text/encoding_text/textencoding>` = `Nil</api/language/nil>` | `String</api/data_types/string>`       |        |
| `ReadAll<standardinputstream.readall>`                   | encoding As `TextEncoding</api/text/encoding_text/textencoding>` = `Nil</api/language/nil>`                                              | `String</api/data_types/string>`       |        |
| `ReadLine<standardinputstream.readline>`                 |                                                                                                                                          | `String</api/data_types/string>`       |        |

## Method descriptions

<div id="standardinputstream.endoffile">

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

</div>

<div class="rst-class">

forsearch

</div>

StandardInputStream.EndOfFile

**EndOfFile** As `Boolean</api/data_types/boolean>`

> Returns `True</api/language/true>` when there's no more data left to read.
>
> This code reads the rows and columns of data from a tab-delimited text file into a `ListBox</api/user_interface/desktop/desktoplistbox>`:
>
> ``` xojo
> Var f As FolderItem
> Var textInput As TextInputStream
> Var rowFromFile, oneCell As String
>
> f = FolderItem.ShowOpenFileDialog("text/plain") ' defined as a FileType
> If f <> Nil Then
>   textInput = TextInputStream.Open(f)
>   textInput.Encoding = Encodings.UTF8
>
>   Do
>     rowFromFile = textInput.ReadLine
>     Var values() As String = rowFromFile.ToArray(String.Chr(9))
>     ListBox1.ColumnCount = values.Count
>     ListBox1.AddRow("")
>     Var col As Integer
>     For Each value As String In values
>       ListBox1.CellTextAt(ListBox1.LastAddedRowIndex, col) = value
>       col = col + 1
>     End For
>   Loop Until textInput.EndOfFile
>
>   textInput.Close
> End If
> ```
>
> This example reads each pair of bytes from a file and writes them in reverse order to a new file. The user chooses the source file using the Open-file dialog box and saves the new file using the Save as dialog box. The EOF property is used to terminate the `Do...Loop</api/language/loops/do...loop>`.
>
> ``` xojo
> Var readFile As FolderItem = FolderItem.ShowOpenFileDialog("text")
> If readFile <> Nil Then
>   Var ReadStream As BinaryStream = BinaryStream.Open(readFile, False)
>   ReadStream.LittleEndian = True
>   Var writeFile As FolderItem = FolderItem.ShowSaveFileDialog("", "")
>   If writeFile <> Nil Then
>     Var writeStream As BinaryStream = BinaryStream.Create(writeFile, True)
>     writeStream.LittleEndian = True
>     Do Until ReadStream.EndOfFile
>       writeStream.WriteInt8(ReadStream.ReadInt8)
>     Loop
>     writeStream = Nil
>   End If
>   readStream = Nil
> End If
> ```

<div id="standardinputstream.operator_convert">

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

</div>

<div class="rst-class">

forsearch

</div>

StandardInputStream.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">StandardInputStream</span> incorporates a conversion operator so that you can use `StdIn</api/console/stdin>` as a `TCPSocket</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 Incoming As TCPSocket = Stdin
> ```

<div id="standardinputstream.read">

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

</div>

<div class="rst-class">

forsearch

</div>

StandardInputStream.Read

**Read**(Count As `Integer</api/data_types/integer>`, encoding As `TextEncoding</api/text/encoding_text/textencoding>` = `Nil</api/language/nil>`) As `String</api/data_types/string>`

> Reads *Count* bytes from the input stream and returns a `String</api/data_types/string>`.
>
> If provided, the optional parameter *encoding* specifies the text encoding to be defined for the `String</api/data_types/string>` to be read.
>
> If *Count* is higher than the amount of bytes currently available in the stream, all available bytes will be returned. Therefore, make sure to always consider the case that you get less than you requested. To see if you received all requested bytes, check the returned string's `String<string.bytes>` property (avoid using `Length<binarystream.length>` as it may give a different number if the encoding is not nil).
>
> If not enough memory is available, you get back an empty string.
>
> This example reads the first 1000 bytes from a `BinaryStream</api/files/binarystream>`.
>
> ``` xojo
> Var readFile As FolderItem = FolderItem.ShowOpenFileDialog("text/plain")
> If readFile <> Nil Then
>   Var ReadStream As BinaryStream = BinaryStream.Open(readFile, False)
>   ReadStream.LittleEndian = True
>   TextArea1.Text = ReadStream.Read(1000, Encodings.UTF8)
> End If
> ```

<div id="standardinputstream.readall">

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

</div>

<div class="rst-class">

forsearch

</div>

StandardInputStream.ReadAll

**ReadAll**(encoding As `TextEncoding</api/text/encoding_text/textencoding>` = `Nil</api/language/nil>`) As `String</api/data_types/string>`

> Reads all available data from the input stream without waiting for the user to press the Return or Enter key.
>
> On macOS and Linux, ReadAll only reads the first 1024 bytes of data. You should continue reading until EOF to be sure you get all the data. ReadAll is a non-blocking operation.
>
> ``` xojo
> Var s As String
> s = StdIn.ReadAll
> ```

<div id="standardinputstream.readline">

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

</div>

<div class="rst-class">

forsearch

</div>

StandardInputStream.ReadLine

**ReadLine** As `String</api/data_types/string>`

> Reads from the input stream until the user presses the Return or Enter key. ReadLine does not include the Newline character as part of the returned `String</api/data_types/string>`.
>
> ``` xojo
> Var s As String
> s = StdIn.ReadLine
> ```

## Interfaces

This class implements the `Readable</api/files/readable>` class interface.

## Notes

Since there is only one <span class="title-ref">StandardInputStream</span> for the system, you do not need to create a <span class="title-ref">StandardInputStream</span> object to use; you just use `StdIn</api/console/stdin>`.

<span class="title-ref">StandardInputStream</span> incorporates a conversion operator so that you can use `StdIn</api/console/stdin>` as a `TCPSocket</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 Incoming As TCPSocket = Stdin
```

## Compatibility

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

<div class="seealso">

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

</div>
