OracleBFile 类

定义

表示托管 OracleBFile 对象,该对象的设计旨在与 Oracle BFILE 数据类型配合使用。Represents a managed OracleBFile object designed to work with the Oracle BFILE data type. 此类不能被继承。This class cannot be inherited.

public ref class OracleBFile sealed : System::IO::Stream, ICloneable, System::Data::SqlTypes::INullable
public sealed class OracleBFile : System.IO.Stream, ICloneable, System.Data.SqlTypes.INullable
type OracleBFile = class
    inherit Stream
    interface ICloneable
    interface INullable
    interface IDisposable
Public NotInheritable Class OracleBFile
Inherits Stream
Implements ICloneable, INullable
继承
实现

注解

Oracle BFILE数据类型是一种 oracle LOB数据类型,包含对二进制数据的引用,其最大大小为 4 gb。The Oracle BFILE data type is an Oracle LOB data type that contains a reference to binary data with a maximum size of 4 gigabytes. Oracle BFILE与其他 oracle LOB数据类型的不同之处在于,它的数据存储在操作系统而不是服务器上的物理文件中。An Oracle BFILE differs from other Oracle LOB data types in that its data is stored in a physical file in the operating system instead of on the server. 请注意, BFILE数据类型提供对数据的只读访问。Note that the BFILE data type provides read-only access to data. 因此,不支持从Stream类继承的面向编写的方法。Therefore, write-oriented methods inherited from the Stream class are not supported.

BFILE数据类型的其他特征与LOB数据类型区分开来是:Other characteristics of a BFILE data type that distinguish it from a LOB data type are that it:

  • 包含非结构化数据。Contains unstructured data.

  • 支持服务器端分块。Supports server-side chunking.

  • 使用引用复制语义。Uses reference copy semantics. 例如,如果在上BFILE执行复制操作,则BFILE仅复制定位符(对文件的引用)。For example, if you perform a copy operation on a BFILE, only the BFILE locator (which is a reference to the file) is copied. 而不会复制文件中的数据。The data in the file is not copied.

数据类型应用于引用LOB大小较大的,因此,在数据库中存储不切合实际。 BFILEThe BFILE data type should be used for referencing LOBs that are large in size, and therefore, not practical to store in the database. BFILE LOB数据类型相比,使用数据类型存在客户端、服务器和通信开销。There is client, server, and communication overhead for using a BFILE data type compared to the LOB data type. BFILE如果只需要获取少量的数据,则访问更有效。It is more efficient to access a BFILE if you only need to obtain a small amount of data. 如果需要获取整个对象,则可以更LOB高效地访问数据库驻留。It is more efficient to access database-resident LOBs if you need to obtain the entire object.

每个非 NULL OracleBFile对象都与定义基础物理文件位置的两个实体相关联:Each non-NULL OracleBFile object is associated with two entities that define the location of the underlying physical file:

  • 一个 Oracle DIRECTORY 对象,它是文件系统中一个目录的数据库别名,以及An Oracle DIRECTORY object, which is a database alias for a directory in the file system, and

  • 基础物理文件的文件名,它位于与 DIRECTORY 对象关联的目录中。The file name of the underlying physical file, which is located in the directory associated with the DIRECTORY object.

创建后,可以使用OracleBFile ExecuteReaderExecuteScalar方法检索对象的形式的定位符。 BFILEAfter a BFILE is created, you can retrieve its locator in the form of an OracleBFile object using the ExecuteReader or ExecuteScalar methods.

若要获取OracleBFile对象,请GetOracleBFile调用方法。To obtain an OracleBFile object, call the GetOracleBFile method.

OracleBFile对象关联的物理文件在您尝试访问它之前无需存在。The physical file that an OracleBFile object is associated with does not need to exist until you attempt to access it. 应用程序可以将绑定OracleBFile到不存在的文件,在预期位置创建物理文件,然后调用。 ReadAn application can bind an OracleBFile to a nonexistent file, create the physical file in the expected location, and then call Read.

OracleBFile OracleBFile使用或方法Seek访问已关闭的任何尝试都会自动重新打开流。 ReadAny attempt to access a closed OracleBFile using the Read or Seek methods reopens an OracleBFile stream automatically.

下面C#的示例演示如何BFILE在 Oracle 表中创建,然后以OracleBFile对象的形式检索它。The following C# example demonstrates how you can create a BFILE in an Oracle table, and then retrieve it in the form of an OracleBFile object. 该示例演示如何OracleDataReader使用对象OracleBFile Seek以及和Read方法。The example demonstrates the use of the OracleDataReader object and the OracleBFileSeek and Read methods.

private void GetOracleBFile(string connectionString)
{
    //Create and open the connection.
    using (OracleConnection connection = new OracleConnection(connectionString))
    {
        connection.Open();

        //Create and execute the commands.
        OracleCommand command = connection.CreateCommand();
        command.CommandText = "CREATE OR REPLACE DIRECTORY TestDir AS 'c:\\bfiles'";
        command.ExecuteNonQuery();
        command.CommandText = "CREATE TABLE TestTable(col1 number, col2 BFILE)";
        command.ExecuteNonQuery();
        command.CommandText = "INSERT INTO TestTable VALUES ('2', BFILENAME('TESTDIR', 'File.jpg'))";
        command.ExecuteNonQuery();
        command.CommandText = "SELECT * FROM TestTable";

        //Read the BFile data.
        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);
                }
            }
        }
    }
    return;
}

有关创建和使用 oracle BFILE的详细信息,请参阅 oracle 文档中的相应主题。For more information about creating and using an Oracle BFILE, see the appropriate topic in your Oracle documentation.

备注

由于BeginWrite EndWrite WriteByte System.IO.Stream数据类型是只读的,因此不支持从类继承的、和方法。 BFILEThe BeginWrite, EndWrite, and WriteByte methods, which are inherited from the System.IO.Stream class, are not supported because the BFILE data type is read-only.

字段

Null

表示空 OracleBFile 对象,该对象没有绑定到物理文件。Represents a null OracleBFile object that is not bound to a physical file.

属性

CanRead

获取一个值,该值指示 BFILE 流是否可读。Gets a value indicating whether the BFILE stream can be read.

CanSeek

获取一个值,该值指示能否执行向前和向后查找操作。Gets a value indicating whether forward-seek and backward-seek operations can be performed.

CanTimeout

获取一个值,该值确定当前流是否可以超时。Gets a value that determines whether the current stream can time out.

(继承自 Stream)
CanWrite

获取一个值,该值指示对象是否支持写入。Gets a value indicating whether the object supports writing.

Connection

获取由该 OracleConnection 实例使用的 OracleBFileGets the OracleConnection used by this instance of the OracleBFile.

DirectoryName

获取与 OracleBFile 对象相关联的 DIRECTORY 对象的名称。Gets the name of the DIRECTORY object, with which an OracleBFile object is associated.

FileExists

获取一个值,该值指示操作系统中是否存在包含 BFILE 数据的物理文件。Gets a value indicating whether a physical file containing BFILE data exists in the operating system.

FileName

获取 BFILE 的名称(不带路径)。Gets the name of the BFILE without the path.

IsNull

获取一个值,该值指示 OracleBFile 是否为一个 Null 流。Gets a value that indicates whether the OracleBFile is a Null stream.

Length

获取一个值,该值返回与 OracleBFile 对象关联的物理文件的长度(以字节为单位)。Gets a value that returns the length in bytes of the physical file with which the OracleBFile object is associated.

Position

获取 OracleBFile 流中的当前读取位置。Gets the current read position in the OracleBFile stream.

ReadTimeout

获取或设置一个值(以毫秒为单位),该值确定流在超时前尝试读取多长时间。Gets or sets a value, in milliseconds, that determines how long the stream will attempt to read before timing out.

(继承自 Stream)
Value

获取 Array 类型的 Byte(它包含 OracleBFile 数据)。Gets an Array of type Byte that contains the OracleBFile data.

WriteTimeout

获取或设置一个值(以毫秒为单位),该值确定流在超时前尝试写入多长时间。Gets or sets a value, in milliseconds, that determines how long the stream will attempt to write before timing out.

(继承自 Stream)

方法

BeginRead(Byte[], Int32, Int32, AsyncCallback, Object)

开始异步读操作。Begins an asynchronous read operation. (请考虑改用 ReadAsync(Byte[], Int32, Int32)。)(Consider using ReadAsync(Byte[], Int32, Int32) instead.)

(继承自 Stream)
BeginWrite(Byte[], Int32, Int32, AsyncCallback, Object)

开始异步写操作。Begins an asynchronous write operation. (请考虑改用 WriteAsync(Byte[], Int32, Int32)。)(Consider using WriteAsync(Byte[], Int32, Int32) instead.)

(继承自 Stream)
Clone()

创建此 OracleBFile 对象的副本,该副本所关联的物理文件与原始对象所关联的相同。Creates a copy of this OracleBFile object associated with the same physical file as the original.

Close()

关闭当前流并释放与之关联的所有资源(如套接字和文件句柄)。Closes the current stream and releases any resources (such as sockets and file handles) associated with the current stream. 不直接调用此方法,而应确保流得以正确释放。Instead of calling this method, ensure that the stream is properly disposed.

(继承自 Stream)
CopyTo(Int64, OracleLob, Int64, Int64)

通过指定数据数量、源偏移量和目标偏移量,从此 OracleBFile 复制到目标 OracleLobCopies from this OracleBFile to a destination OracleLob with the specified amount of data, the source offset, and the destination offset.

CopyTo(OracleLob)

将此 OracleBFile 的全部内容复制到目标 OracleLob 的开始位置。Copies the entire contents of this OracleBFile to the beginning of a destination OracleLob.

CopyTo(OracleLob, Int64)

将此 OracleBFile 的全部内容复制到目标 OracleLob 中指定的偏移位置。Copies the entire contents of this OracleBFile to a destination OracleLob at the specified offset.

CopyTo(Stream)

从当前流中读取字节并将其写入到另一流中。Reads the bytes from the current stream and writes them to another stream.

(继承自 Stream)
CopyTo(Stream, Int32)

使用指定的缓冲区大小,从当前流中读取字节并将其写入到另一流中。Reads the bytes from the current stream and writes them to another stream, using a specified buffer size.

(继承自 Stream)
CopyToAsync(Stream)

从当前流中异步读取字节并将其写入到另一个流中。Asynchronously reads the bytes from the current stream and writes them to another stream.

(继承自 Stream)
CopyToAsync(Stream, CancellationToken)

通过指定的取消令牌,从当前流中异步读取字节并将其写入到另一个流中。Asynchronously reads the bytes from the current stream and writes them to another stream, using a specified cancellation token.

(继承自 Stream)
CopyToAsync(Stream, Int32)

使用指定的缓冲区大小,从当前流中异步读取字节并将其写入到另一流中。Asynchronously reads the bytes from the current stream and writes them to another stream, using a specified buffer size.

(继承自 Stream)
CopyToAsync(Stream, Int32, CancellationToken)

使用指定的缓冲区大小和取消令牌,从当前流中异步读取字节并将其写入到另一个流中。Asynchronously reads the bytes from the current stream and writes them to another stream, using a specified buffer size and cancellation token.

(继承自 Stream)
CreateObjRef(Type)

创建一个对象,该对象包含生成用于与远程对象进行通信的代理所需的全部相关信息。Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(继承自 MarshalByRefObject)
CreateWaitHandle()

分配 WaitHandle 对象。Allocates a WaitHandle object.

(继承自 Stream)
Dispose()

释放此对象使用的所有资源。Releases all the resources that are used by this object.

Dispose(Boolean)

释放由 Stream 占用的非托管资源,还可以另外再释放托管资源。Releases the unmanaged resources used by the Stream and optionally releases the managed resources.

(继承自 Stream)
DisposeAsync()

异步释放 Stream 使用的非托管资源。Asynchronously releases the unmanaged resources used by the Stream.

(继承自 Stream)
EndRead(IAsyncResult)

等待挂起的异步读取完成。Waits for the pending asynchronous read to complete. (请考虑改用 ReadAsync(Byte[], Int32, Int32)。)(Consider using ReadAsync(Byte[], Int32, Int32) instead.)

(继承自 Stream)
EndWrite(IAsyncResult)

结束异步写操作。Ends an asynchronous write operation. (请考虑改用 WriteAsync(Byte[], Int32, Int32)。)(Consider using WriteAsync(Byte[], Int32, Int32) instead.)

(继承自 Stream)
Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
Flush()

目前尚不支持。Not currently supported.

FlushAsync()

异步清除此流的所有缓冲区并导致所有缓冲数据都写入基础设备中。Asynchronously clears all buffers for this stream and causes any buffered data to be written to the underlying device.

(继承自 Stream)
FlushAsync(CancellationToken)

异步清理这个流的所有缓冲区,并使所有缓冲数据写入基础设备,并且监控取消请求。Asynchronously clears all buffers for this stream, causes any buffered data to be written to the underlying device, and monitors cancellation requests.

(继承自 Stream)
GetHashCode()

用作默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetLifetimeService()

检索控制此实例的生存期策略的当前生存期服务对象。Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(继承自 MarshalByRefObject)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
InitializeLifetimeService()

获取生存期服务对象来控制此实例的生存期策略。Obtains a lifetime service object to control the lifetime policy for this instance.

(继承自 MarshalByRefObject)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
MemberwiseClone(Boolean)

创建当前 MarshalByRefObject 对象的浅表副本。Creates a shallow copy of the current MarshalByRefObject object.

(继承自 MarshalByRefObject)
ObjectInvariant()

提供对 Contract 的支持。Provides support for a Contract.

(继承自 Stream)
Read(Byte[], Int32, Int32)

从当前 OracleBFile 流中读取字节序列,并在该流中按照读取的字节数提升位置。Reads a sequence of bytes from the current OracleBFile stream and advances the position within the stream by the number of bytes read.

Read(Span<Byte>)

当在派生类中重写时,从当前流读取字节序列,并将此流中的位置提升读取的字节数。When overridden in a derived class, reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read.

(继承自 Stream)
ReadAsync(Byte[], Int32, Int32)

从当前流异步读取字节序列,并将流中的位置提升读取的字节数。Asynchronously reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read.

(继承自 Stream)
ReadAsync(Byte[], Int32, Int32, CancellationToken)

从当前流异步读取字节的序列,将流中的位置提升读取的字节数,并监视取消请求。Asynchronously reads a sequence of bytes from the current stream, advances the position within the stream by the number of bytes read, and monitors cancellation requests.

(继承自 Stream)
ReadAsync(Memory<Byte>, CancellationToken)

从当前流异步读取字节的序列,将流中的位置提升读取的字节数,并监视取消请求。Asynchronously reads a sequence of bytes from the current stream, advances the position within the stream by the number of bytes read, and monitors cancellation requests.

(继承自 Stream)
ReadByte()

从流中读取一个字节,并将流内的位置向前提升一个字节,或者如果已到达流结尾,则返回 -1。Reads a byte from the stream and advances the position within the stream by one byte, or returns -1 if at the end of the stream.

(继承自 Stream)
Seek(Int64, SeekOrigin)

在当前 OracleBFile 流上设置位置。Sets the position on the current OracleBFile stream.

SetFileName(String, String)

OracleBFile 对象绑定到操作系统中的其他文件。Binds the OracleBFile object to a different file in the operating system.

SetLength(Int64)

目前尚不支持。Not currently supported.

ToString()

返回一个表示当前对象的 string。Returns a string that represents the current object.

(继承自 Object)
Write(Byte[], Int32, Int32)

目前尚不支持。Not currently supported.

Write(ReadOnlySpan<Byte>)

当在派生类中重写时,向当前流中写入字节序列,并将此流中的当前位置提升写入的字节数。When overridden in a derived class, writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written.

(继承自 Stream)
WriteAsync(Byte[], Int32, Int32)

将字节序列异步写入当前流,并将流的当前位置提升写入的字节数。Asynchronously writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written.

(继承自 Stream)
WriteAsync(Byte[], Int32, Int32, CancellationToken)

将字节的序列异步写入当前流,将该流中的当前位置向前移动写入的字节数,并监视取消请求。Asynchronously writes a sequence of bytes to the current stream, advances the current position within this stream by the number of bytes written, and monitors cancellation requests.

(继承自 Stream)
WriteAsync(ReadOnlyMemory<Byte>, CancellationToken)

将字节的序列异步写入当前流,将该流中的当前位置向前移动写入的字节数,并监视取消请求。Asynchronously writes a sequence of bytes to the current stream, advances the current position within this stream by the number of bytes written, and monitors cancellation requests.

(继承自 Stream)
WriteByte(Byte)

将一个字节写入流内的当前位置,并将流内的位置向前提升一个字节。Writes a byte to the current position in the stream and advances the position within the stream by one byte.

(继承自 Stream)

显式界面实现

IDisposable.Dispose()

释放由 Stream 使用的所有资源。Releases all resources used by the Stream.

(继承自 Stream)

适用于