Class

NSStream

An abstract class representing a stream. あるストリームを表している抽象クラス。

Declaration 宣言

@interface NSStream : NSObject

Overview 概要

This class’s interface is common to all Cocoa stream classes, including its concrete subclasses NSInputStream and NSOutputStream.

NSStream objects provide an easy way to read and write data to and from a variety of media in a device-independent way. You can create stream objects for data located in memory, in a file, or on a network (using sockets), and you can use stream objects without loading all of the data into memory at once. NSStreamオブジェクトは、多様なメディアへとそしてそれから読み出すおよび書き出す簡単な方法をデバイスから独立した方法で提供します。あなたはストリームオブジェクトの作成が、メモリ中に、ファイル中に、または(ソケットを使って)ネットワーク上に位置するデータに対して可能です、そしてあなたはストリームオブジェクトの使用が、一度にデータの全てをメモリへとロードすることなしに可能です。

By default, NSStream instances that aren’t file-based are non-seekable, one-way streams (although custom seekable subclasses are possible). After you provide or consume data, you can’t retrieve the data from the stream.

Subclassing Notes サブクラス作成の注意

NSStream is an abstract class, incapable of instantiation and intended for you to subclass it. It publishes a programmatic interface that all subclasses must adopt and provide implementations for. それはあるプログラムインターフェイスを公開します、それは全てのサブクラスが採用してそれに対して実装を提供しなければならないものです。 The two Apple-provided concrete subclasses of NSStream, NSInputStream and NSOutputStream, are suitable for most purposes. However, there might be situations when you want a peer subclass to NSInputStream and NSOutputStream. For example, you might want a class that implements a full-duplex (two-way) stream, or a class whose instances are capable of seeking through a stream. 例えば、あなたは全二重(2方向)ストリームを実装するクラスを、またはそれのインスタンスがストリームを端から端までシークする能力があるクラスを望むかもしれません。

Methods to Override メソッドのオーバーライド

All subclasses must fully implement the following methods: 全てのサブクラスは、完全に以下のメソッドを実装しなければなりません:

  • open and close openclose

    Implement open to open the stream for reading or writing and make the stream available to the client directly or, if the stream object is scheduled on a run loop, to the delegate. Implement close to close the stream and remove the stream object from the run loop, if necessary. A closed stream should still be able to accept new properties and report its current properties. openを実装してストリームを読み出しまたは書き出しのために開いてください、そしてそのストリームをクライアントに直接にまたは、もしストリームオブジェクトが実行ループ上で予定されるならば、委任先に利用可能にしてください。closeを実装してストリームを閉じてください、そしてストリームオブジェクトを実行ループから取り除いてください、必要であれば。閉じられたストリームは、依然として新しいプロパティを受け入れ、そしてそれの現在のプロパティを報告可能であるべきです。 Once you close a stream, you can’t reopen it.

  • delegate

    Return and set the delegate. By a default, a stream object must be its own delegate; so a delegate message with an argument of nil should restore this delegate. 委任先を返します、および設定します。初期状態では、ストリームオブジェクトはそれ自身が委任先であるはずです;なのでdelegateメッセージでnilの引数を持つものは、それを委任先として復元すべきです。 Don’t retain the delegate to prevent retain cycles.

    To learn about delegates and delegation, read "Delegation" in Cocoa Fundamentals Guide. 委任先と委任について学ぶために、"Delegation" をCocoa Fundamentals Guideで見てください。

  • scheduleInRunLoop:forMode: and removeFromRunLoop:forMode: scheduleInRunLoop:forMode:removeFromRunLoop:forMode:

    Implement scheduleInRunLoop:forMode: to schedule the stream object on the specified run loop for the specified mode. Implement removeFromRunLoop:forMode: to remove the object from the run loop. See the documentation of the NSRunLoop class for details. Once the stream object for an open stream is scheduled on a run loop, it is the responsibility of the subclass as it processes stream data to send stream:handleEvent: messages to its delegate. scheduleInRunLoop:forMode:を実装することで、ストリームオブジェクトをこの指定された実行ループ上でこの指定されたモードに対して予定してください。removeFromRunLoop:forMode:を実装して、そのオブジェクトを実行ループから取り除いてください。NSRunLoopクラスの文書化を詳細として見てください。一旦ストリームオブジェクトがある開かれたストリームに対してある実行ループ上で予定されるならば、サブクラスは、それがストリームデータを処理するときにstream:handleEvent:メッセージをそれの委任先に送る責任があります。

  • propertyForKey: and setProperty:forKey: propertyForKey:setProperty:forKey:

    Implement these methods to return and set, respectively, the property value for the specified key. これらメソッドを実装することで、指定されたキーに対するプロパティ値をそれぞれ返したり設定したりしてください。 You may add custom properties, but be sure to handle all properties defined by NSStream as well.

  • streamStatus and streamError streamStatusstreamError

    Implement streamStatus to return the current status of the stream as a NSStreamStatus constant; you may define new NSStreamStatus constants, but be sure to handle the system defined constants properly. Implement streamError to return an NSError object representing the current error. You might decide to return a custom NSError object that can provide complete and localized information about the error.

Topics 話題

Creating Streams ストリームを作成する

Configuring Streams ストリームを構成設定する

Using Streams ストリームを使う

Managing Run Loops 実行ループを管理する

Getting Stream Information ストリーム情報を取得する

Constants 定数

Type Methods 型メソッド

Relationships 関係

Inherits From 継承元

See Also 参照

Streams ストリーム