0% found this document useful (0 votes)
8 views

complete-reference-vb_net_60

Uploaded by

khalid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

complete-reference-vb_net_60

Uploaded by

khalid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

NetworkStream

If you always read and write for sizes greater than the internal buffer size, then BufferedStream might not
even allocate the internal buffer. BufferedStream also buffers reads and writes in a shared buffer. Usually,
you do a series of reads or writes, but rarely alternate between reading and writing.

The following method example demonstrates the creation of a BufferedStream object bridged to the earlier
declared standard FileStream object:

Public Sub AddNoises(ByVal source As String, _


ByVal noiseword As String)
Dim fStream As New FileStream(source, FileMode.OpenOrCreate, _
FileAccess.Write)
Dim bStream As New BufferedStream(fStream)
'Create a 'StreamWriter' to write the data into the file.
Dim sWriter As New StreamWriter(bStream)
sWriter.WriteLine(noiseword)
' Update the 'StreamWriter'.
sWriter.Flush()
' Close the 'StreamWriter' and FileStream.
sWriter.Close()
fStream.Close()
End Sub

NetworkStream

A NetworkStream object provides the underlying stream of data for network access. NetworkStream
implements the standard .NET Framework stream mechanism to send and receive data through network
sockets. It also supports both synchronous and asynchronous access to the network data stream.

CryptoStream

The CLR also uses a streams model for reading and writing encrypted data. This service is provided by the
CryptoStream object. Any cryptographic objects that implement CryptoStream can be chained together
with any objects that implement Stream, so the streamed output from one object can be bridged into the input
of another object. The intermediate result (the output from the first object) does not need to be stored
separately.

MemoryStream

MemoryStream is no different from the previously mentioned streams except that volatile memory is used as
the so−called backing store rather than a disk or network sockets. This class encapsulates data stored as an
unsigned byte array that gets initialized upon the instantiation of the MemoryStream object. However, the
array can also be created empty. The encapsulated data in the object is thus directly accessible in memory.
Memory streams can reduce the need for temporary buffers and files in an application, which can improve
performance by an order of magnitude.

GetBuffer

To create a MemoryStream object with a publicly visible buffer, simply call the default constructor. A
stream can be declared resizable, which resizes the array, but in that respect, multiple calls to GetBuffer
might not return the same array. You can also use the Capacity property, which retrieves or changes the
number of bytes allocated to the stream. This ensures consistent results. GetBuffer also works when the
MemoryStream is closed.

544

You might also like