Developing Windows Clients |
Supports sequential access to binary data sources such as binary files.
Attributes
Container Property
StreamEncoding Property
CallerEncoding Property
Methods
Close Method
Read Method
Write Method
This object provides sequential access to binary (byte-oriented) data streams. Binary files are the most common source for such streams.
While the most common use of this interface is the tranfer of files in binary formats, the interface is also useful for the transfer of text data in cases where you need to bypass the standard text transcoding. For text, one common case is the transfer of single-byte encoded HTML containing the "meta charset" tag. In such a case, transferring the HTML by using a character-oriented data type (such as the Unicode strings common for many client environments), would invalidate the "meta charset" tag.
When you are bypassing standard transcoding, this interface also supports optional non-standard transcoding based on the values specified in StreamEncoding and CallerEncoding. If StreamEncoding and CallerEncoding are the same, no transcoding is performed. They default to the same value.
The main differences between the BinaryStream and the TextStream are: the BinaryStream can recode text based on provided encodings of the source and destination, while the TextStream automatically determines the system code page of the source and destination and recodes based on that; the BinaryStream uses an array of bytes, while the TextStream uses an array of character strings or a single character string; the BinaryStream has no concept of lines and therefore does not truncate lines and does nothing with line separators.
The containing object for this stream.
Type: Object
Description
The containing object for this stream. If, for example, the stream was created from a Fileref, then this attribute will reference that Fileref.
Example
Usage
The encoding of the data as it exists in the stream, before reading or after writing.
Type: String
Description
Example
Usage
The encoding of the data desired by the caller in a read, or supplied by the caller in a write.
Type: String
Description
Example
Usage
Closes the stream.
Description
Frees resources associated with the stream. You should close a stream when you are finished with it. Streams are also closed when their container is closed. Deassigning a Fileref, for example, closes its streams.
Closing the stream releases any locks held by the stream. If, for example, the stream is being used to write a file and the SAS System obtained an exclusive-use lock on the file, that lock is released when the stream is closed.
Usage
Parameters: None
Example
See Also
Reads the requested number of bytes from the current position in the stream.
Description
The current position in the stream is updated to reflect the number of bytes read. Subsequent calls to read will continue at the point the previous call stopped.
Usage
The stream must have been previously opened with StreamOpenModeForReading or StreamOpenModeForUpdating.
Parameters
Name | Direction | Type | Description |
---|---|---|---|
requestedLength | in | Long | An upper bound on the number of characters to be returned by this request. This should not be excessively large since SAS allocates a buffer based on this size. |
binaryData | out | Byte(index) | This is the array of data that was read from the stream. This parameter returns a zero-sized array when end of stream is reached. |
Example
' Read data from a SAS binary stream, and write it out to ' a local file using the Scripting.TextStream object Dim obFileService As SAS.FileService Dim obFileref As SAS.Fileref Dim assignedName As String Dim obLocalFileSystem As New Scripting.FileSystemObject Dim obLocalTextStream As Scripting.TextStream Dim obRemoteBinaryStream As SAS.BinaryStream Dim fileText As String Dim endOfFile As Boolean Dim binaryData() As Byte Set obFileService = obSAS.FileService ' Create a temporary fileref to the selected file fullPathName = obFileService.FullName(ListView1.SelectedItem.Text, currentPath) Set obFileref = obFileService.AssignFileref("", "DISK", fullPathName, "", assignedName) Set obRemoteBinaryStream = obFileref.OpenBinaryStream(SASForReading) Set obLocalTextStream = obLocalFileSystem.CreateTextFile("c:\temp\readFile.txt", True, False) While (Not endOfFile) obRemoteBinaryStream.Read 16500, binaryData For Each b In binaryData fileText = fileText + Chr(b) Next obLocalTextStream.Write (fileText) endOfFile = (UBound(binaryData) >= 0) Wend obRemoteBinaryStream.Close
See Also
Writes bytes to the stream.
Description
Bytes are written starting at the current position in the stream. After the write operation is performed, the stream's current position is updated to reflect the bytes just written.
Usage
The stream must have been previously opened with StreamOpenModeForWriting or StreamOpenModeForUpdating.
Parameters
Name | Direction | Type | Description |
---|---|---|---|
binaryData | in | Byte(index) | The bytes to be written. |
Example
See Also
Developing Windows Clients |