BufferedStream 构造函数

定义

初始化 BufferedStream 类的新实例。Initializes a new instance of the BufferedStream class.

重载

BufferedStream(Stream)

使用默认的缓冲区大小 4096 字节初始化 BufferedStream 类的新实例。Initializes a new instance of the BufferedStream class with a default buffer size of 4096 bytes.

BufferedStream(Stream, Int32)

使用指定的缓冲区大小初始化 BufferedStream 类的新实例。Initializes a new instance of the BufferedStream class with the specified buffer size.

BufferedStream(Stream)

使用默认的缓冲区大小 4096 字节初始化 BufferedStream 类的新实例。Initializes a new instance of the BufferedStream class with a default buffer size of 4096 bytes.

public:
 BufferedStream(System::IO::Stream ^ stream);
public BufferedStream (System.IO.Stream stream);
new System.IO.BufferedStream : System.IO.Stream -> System.IO.BufferedStream

参数

stream
Stream

当前流。The current stream.

异常

streamnullstream is null.

注解

第一次使用此构造函数初始化 BufferedStream 对象时,将分配共享的读/写缓冲区。A shared read/write buffer is allocated the first time a BufferedStream object is initialized with this constructor. 如果所有读取和写入都大于或等于 bufferSize,则不会使用共享缓冲区。The shared buffer is not used if all reads and writes are greater than or equal to bufferSize.

另请参阅

BufferedStream(Stream, Int32)

使用指定的缓冲区大小初始化 BufferedStream 类的新实例。Initializes a new instance of the BufferedStream class with the specified buffer size.

public:
 BufferedStream(System::IO::Stream ^ stream, int bufferSize);
public BufferedStream (System.IO.Stream stream, int bufferSize);
new System.IO.BufferedStream : System.IO.Stream * int -> System.IO.BufferedStream

参数

stream
Stream

当前流。The current stream.

bufferSize
Int32

缓冲区大小(以字节为单位)。The buffer size in bytes.

异常

streamnullstream is null.

bufferSize 为负数。bufferSize is negative.

示例

此代码示例是为 BufferedStream 类提供的更大示例的一部分。This code example is part of a larger example provided for the BufferedStream class.

// Create a NetworkStream that owns clientSocket and 
// then create a BufferedStream on top of the NetworkStream.
NetworkStream^ netStream = gcnew NetworkStream( clientSocket,true );
BufferedStream^ bufStream = gcnew BufferedStream( netStream,streamBufferSize );

// Create a NetworkStream that owns clientSocket and
// then create a BufferedStream on top of the NetworkStream.
// Both streams are disposed when execution exits the
// using statement.
using(Stream
    netStream = new NetworkStream(clientSocket, true),
    bufStream =
          new BufferedStream(netStream, streamBufferSize))
' Create a NetworkStream that owns clientSocket and then 
' create a BufferedStream on top of the NetworkStream.
Dim netStream As New NetworkStream(clientSocket, True)
Dim bufStream As New _
    BufferedStream(netStream, streamBufferSize)

注解

第一次使用此构造函数初始化 BufferedStream 对象时,将分配共享的读/写缓冲区。A shared read/write buffer is allocated the first time a BufferedStream object is initialized with this constructor. 如果所有读取和写入都大于或等于 bufferSize,则不会使用共享缓冲区。The shared buffer is not used if all reads and writes are greater than or equal to bufferSize.

另请参阅

适用于