OutputStream
public protocol OutputStream
Output stream for writing to an underlying target.
Implementation notes:
Only the function write(data: UnsafePointer<Void>, lengthInBytes byteCount: Int) throws
should be implemented. Other write
/writeln
functions should not be implemented
as they are already implemented as an extension which will call the
write(data: UnsafePointer<Void>, lengthInBytes byteCount: Int) throws
function.
-
True, if the stream is open and data can be written.
False, if the stream is closed and data cannot be written. Any calls of the write-function will fail and an IOError will be thrown.
If the state of the stream changes, the delegate is notified by a call of the
didClose
-Method.Declaration
Swift
var open:Bool
-
write(_:)
Default implementationWrites the given data into the underlying ressource.
The error may be .WouldBlock or .Again, which indicates that the read operation failed because no data is available and non-blocking I/O is used. In this case, the write operation has to be repeated.
Throws
An IOError indicating that the operation failed.
Default Implementation
Writes the given data into the underlying ressource.
The error may be .WouldBlock or .Again, which indicates that the read operation failed because no data is available and non-blocking I/O is used. In this case, the write operation has to be repeated.
Throws
An IOError indicating that the operation failed.
Writes the given StreamWritable-object into the underlying target.
The error may be .WouldBlock or .Again, which indicates that the read operation failed because no data is available and non-blocking I/O is used. In this case, the write operation has to be repeated.
Throws
An IOError indicating that the operation failed.
Declaration
Swift
func write(_ data: Data) throws
Parameters
data
Data which should be written.
-
write(_:encoding:)
Default implementationWrites the given string encoded by the given encoding into the underlying ressource.
The error may be .WouldBlock or .Again, which indicates that the read operation failed because no data is available and non-blocking I/O is used. In this case, the write operation has to be repeated.
Throws
An IOError indicating that the operation failed.
Default Implementation
Writes the data at the given pointer into the underlying target. The byteCount specifies that
The error may be .WouldBlock or .Again, which indicates that the read operation failed because no data is available and non-blocking I/O is used. In this case, the write operation has to be repeated.
Throws
An IOError indicating that the operation failed.
Declaration
Swift
func write(_ string: String, encoding: String.Encoding) throws
Parameters
string
String which should be written
encoding
Encoding to be used to convert the string to bytes. By default the string will be encoded using UTF-8 encoding.
-
Writes the data at the given pointer into the underlying target. The byteCount specifies that
The error may be .WouldBlock or .Again, which indicates that the read operation failed because no data is available and non-blocking I/O is used. In this case, the write operation has to be repeated.
Throws
An IOError indicating that the operation failed.
Declaration
Swift
func write(_ data: UnsafeRawPointer, lengthInBytes byteCount: Int) throws
Parameters
data
Pointer to the data to be written
byteCount
Number of bytes to be written
-
Writes the given StreamWritable-object into the underlying target.
The error may be .WouldBlock or .Again, which indicates that the read operation failed because no data is available and non-blocking I/O is used. In this case, the write operation has to be repeated.
Throws
An IOError indicating that the operation failed.
Declaration
Swift
func write(_ streamWritable: StreamWritable) throws
Parameters
streamWritable
The object to be written.
-
writeln(_:encoding:)
Default implementationWrites the given string followed by a newline encoded by the given encoding into the underlying ressource.
The error may be .WouldBlock or .Again, which indicates that the read operation failed because no data is available and non-blocking I/O is used. In this case, the write operation has to be repeated.
Throws
An IOError indicating that the operation failed.
Default Implementation
Writes the given string followed by a newline encoded by the given encoding into the underlying ressource.
The error may be .WouldBlock or .Again, which indicates that the read operation failed because no data is available and non-blocking I/O is used. In this case, the write operation has to be repeated.
Throws
An IOError indicating that the operation failed.
Declaration
Swift
func writeln(_ string: String, encoding: String.Encoding) throws
Parameters
string
String which should be written. If no string is specified, only a newline will be written.
encoding
Encoding to be used to convert the string to bytes. By default the string will be encoded using UTF-8 encoding.
-
Closes the stream and releases any associated ressources.
Subsequent calls to the write-function should fail with an IOError.
If the stream writes into 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()