InputStream

public protocol InputStream : class

Input stream for reading from an underlying source.

Implementation notes:

The delegate should be notified, when new data comes available or the stream is closed.

If the stream implementation relies on an underlying stream, the delegate of the underlying stream should be set to this stream.

The delegate of this stream implementation should then be notified about delegate notifications from the underlying stream.

  • True, if the stream is open and data can be read.

    False, if the stream is closed and data cannot be read. Any calls to the read function will fail with an error.

    If the state of the stream changes, the delegate is notified by a call of the didClose-Method.

    Declaration

    Swift

    var open:Bool
  • Delegate for state change notifications.

    Reports, if new data is available or if the stream was closed.

    Declaration

    Swift

    var delegate: InputStreamDelegate?
  • Read data from the stream.

    The length of the returned array has a maximum length of maxByteCount.

    If an error occurred, an IOError will be thrown.

    The thrown IOError may be IOError.WouldBlock, IOError.Again or IOError.Interrupted. This occurs, if no data is available and the read-operation should be tried again. To avoid IOError.WouldBlock or IOError.Again, use the delegate to receive notifications about incoming data or use blocking I/O.

    Throws

    An IOError if the read operation failed.

    Declaration

    Swift

    func read(_ maxByteCount: Int) throws -> [CChar]

    Parameters

    maxByteCount

    Maximum number of bytes to read.

    Return Value

    An array of bytes which were read as CChar (Int8)

  • readLine(_:) Default implementation

    Reads data from the stream until a line break is encountered.

    If an error occurred, an IOError will be thrown.

    The thrown IOError may be IOError.WouldBlock, IOError.Again or IOError.Interrupted. This occurs, if no data is available and the read-operation should be tried again. To avoid IOError.WouldBlock or IOError.Again, use the delegate to receive notifications about incoming data or use blocking I/O.

    Default Implementation

    Reads data from the stream until a line break is encountered.

    If an error occurred, an IOError will be thrown.

    The thrown IOError may be IOError.WouldBlock, IOError.Again or IOError.Interrupted. This occurs, if no data is available and the read-operation should be tried again. To avoid IOError.WouldBlock or IOError.Again, use the delegate to receive notifications about incoming data or use blocking I/O.

    Declaration

    Swift

    func readLine(_ encoding: String.Encoding) throws -> String?

    Return Value

    A string containing a single line read from the stream

  • Closes the input stream and any associated ressources.

    Any subsequent attempts to read from this stream should fail.

    If the stream reads from a socket, the socket should be notified of this operation so it can be closed automatically if both streams are closed.

    Declaration

    Swift

    func close()