Mac Guides | Samples

MonoMac.Foundation.NSInputStream Class

A read-only input NSStream.

See Also: NSInputStream


[MonoMac.Foundation.Register("NSInputStream", true)]
public class NSInputStream : NSStream


Subclassing NSInputStream.

NSInputStream is a concrete subclass of NSStream you can use to give read-only access to stream data. For most cases this is sufficient, however if you want more control over the data, you can subclass NSInputStream. If you subclass NSInputStream you must provide an implementation of the following methods:

Providing a toll-free bridged NSInputStream subclass.

The methods required to provide a toll-free bridged NSInputStream subclass are considered private API, and may cause Apple to reject your app from the App Store.

An simple NSInputStream subclass will not work for all API that takes an NSInputStream. This is the case with NSMutableUrlRequest for instance, which actually expects an instance of a CFReadStream object. For this to work our NSInputStream subclass needs to be toll-free bridged to CFReadStream. This is done by overriding the following methods:

You must call also NSInputStream.Notify((valuetype MonoMac.CoreFoundation.CFStreamEventType) to inform the client when you have data available (or when you have any other relevant event), otherwise your input stream won't be read from.


Namespace: MonoMac.Foundation
Assembly: XamMac (in XamMac.dll)
Assembly Versions:

The members of MonoMac.Foundation.NSInputStream are listed below.

See Also: NSStream

Public Constructors

Default constructor that initializes a new instance of this class with no parameters.
A constructor that initializes the object from the data stored in the unarchiver object.
Constructor to call on derived classes when the derived class has an [Export] constructor.
A constructor used when creating managed representations of unmanaged objects; Called by the runtime.

Public Properties

ClassHandleIntPtr. The handle for this class.

Public Methods

FromData(NSData) : NSInputStream
FromFile(String) : NSInputStream
FromUrl(NSUrl) : NSInputStream
HasBytesAvailable() : Boolean
Returna a boolean value indicating whether the stream has bytes available to be read.
Notifies consumers of events in the stream.
Read(Byte[], UInt32) : Int32
Reads data from the stream into the provided buffer.
Read(IntPtr, UInt32) : Int32
Reads data from the stream into the provided buffer. You should not call this method directly, you should call NSInputStream.Read(byte[],uint) instead. This method is for NSInputStream subclasses to implement.
ScheduleInCFRunLoop(CFRunLoop, NSString)
Schedules the stream in a RunLoop.
UnscheduleInCFRunLoop(CFRunLoop, NSString)
Unschedules the stream from a RunLoop.

Protected Methods

Releases the resourced used by the NSInputStream object.
GetBuffer(out IntPtr, out UInt32) : Boolean
This method can return a pointer to a buffer the caller can read data from.
SetCFClientFlags(CFStreamEventType, IntPtr, IntPtr) : Boolean
Adds a client for the stream. This method is not supposed to be called by managed code, it will be called by consumers of the straem. When overriding it make sure to call the base implementation.