OutputStream
A stream that provides write-only stream functionality.
Declaration
class OutputStreamMentioned in
Overview
OutputStream is “toll-free bridged” with its Core Foundation counterpart, CFWriteStream. For more information on toll-free bridging, see Toll-Free Bridging.
Subclassing Notes
NSOutputStream is a concrete subclass of NSStream that lets you write data to a stream. Although NSOutputStream is probably sufficient for most situations requiring this capability, you can create a subclass of NSOutputStream if you want more specialized behavior (for example, you want to record statistics on the data in a stream).
Methods to Override
To create a subclass of NSOutputStream you may have to implement initializers for the type of stream data supported and suitably reimplement existing initializers. You must also provide complete implementations of the following methods:
From the current write pointer, take up to the number of bytes specified in the maxLength: parameter from the client-supplied buffer (first parameter) and put them onto the stream. The buffer must be of the size specified by the second parameter. To prepare for the next operation, offset the write pointer by the number of bytes written. Return a signed integer based on the outcome of the current operation:
If the write operation is successful, return the actual number of bytes put onto the stream.
If the stream is of a fixed length and has reached its capacity, return
0.If there was an error writing to the stream, return
-1.
Return true if the stream can currently accept more data, false if it cannot. If you want to be semantically compatible with NSOutputStream, return true if a write must be attempted to determine if space is available.