OracleBFile.Read(Byte[], Int32, Int32) 方法

定义

从当前 OracleBFile 流中读取字节序列,并通过读取的字节数推进流中的位置。

public:
 override int Read(cli::array <System::Byte> ^ buffer, int offset, int count);
public override int Read(byte[] buffer, int offset, int count);
override this.Read : byte[] * int * int -> int
Public Overrides Function Read (buffer As Byte(), offset As Integer, count As Integer) As Integer

参数

buffer
Byte[]

字节数组。 此方法返回时,缓冲区包含指定的字节数组,这些offsetoffset + count字节数组的值由从当前源中读取的字节替换。

offset
Int32

从零开始的字节偏移量 buffer ,从中开始存储从当前流中读取的数据。

count
Int32

要从当前流中读取的最大字节数。

返回

读取到缓冲区中的字节总数。 如果当前没有多少个字节可用,则这可能小于请求的字节数;如果已达到文件的末尾,则为零。

例外

其总和 offset 大于 count 缓冲区长度。

buffer是空引用(Visual Basic 中的 Nothing)。

offsetcount 为负数。

与之 BFILE 关联的连接已关闭。

出现 I/O 错误。

在关闭或释放流后调用方法。

注解

该方法 Read 从当前流读取最大字节数 count ,并将其存储在 buffer 开头 offset。 流中的当前位置按读取的字节数进行高级;但是,如果发生异常,流中的当前位置保持不变。 Read 返回读取的字节数。 仅当位置当前位于流末尾时,返回值为零。 Read 在没有任何数据可用的情况下,将阻止数据,直到可以读取至少一个字节的数据。 Read 仅当到达文件的末尾时,才返回 0。 Read 即使尚未到达流的末尾,也可以返回比请求的字节少。

使用或OracleBFile方法访问已关闭ReadSeek的任何尝试都会自动重新打开OracleBFile流。

以下 C# 示例在 Oracle 表中假定此架构:

(col1 number, col2 BFILE)

该示例演示如何使用 ReadSeek 方法访问对象 OracleBFile

byte[] buffer = new byte[100];
OracleDataReader dataReader = command.ExecuteReader();
using (dataReader) {
    if (dataReader.Read()) {
            OracleBFile BFile = dataReader.GetOracleBFile(1);
        using (BFile) {
            BFile.Seek(0, SeekOrigin.Begin);
            BFile.Read(buffer, 0, 100);
        }
    }
}

适用于