OracleBFile OracleBFile OracleBFile OracleBFile Class

定义

表示托管 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
继承
实现

注解

OracleBFILE数据类型是一种 OracleLOB数据类型,包含最大大小为 4 千兆字节的二进制数据的引用。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. OracleBFILE不同于其他 OracleLOB数据类型,其数据存储在服务器上的物理文件中而不是操作系统中。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.

BFILE数据类型应该用于引用LOB较大的大小,因此不可行,若要在数据库中存储。The 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. 访问驻留在数据库中的效率更高LOBs 如果你需要获取整个对象。It is more efficient to access database-resident LOBs if you need to obtain the entire object.

每个非 NULLOracleBFile对象是与定义的基础物理文件位置的两个实体相关联: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.

之后BFILE是创建的可以检索它的窗体的定位器OracleBFile对象使用ExecuteReaderExecuteScalar方法。After 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使用ReadSeek方法重新打开时OracleBFile自动流式传输。Any 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对象和OracleBFileSeekRead方法。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.

备注

BeginWriteEndWrite,并WriteByte方法,则继承其System.IO.Stream类中,不支持,因为BFILE数据类型是只读的。The 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 Null Null Null

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

属性

CanRead CanRead CanRead CanRead

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

CanSeek CanSeek CanSeek CanSeek

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

CanTimeout CanTimeout CanTimeout CanTimeout

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

(Inherited from Stream)
CanWrite CanWrite CanWrite CanWrite

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

Connection Connection Connection Connection

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

DirectoryName DirectoryName DirectoryName DirectoryName

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

FileExists FileExists FileExists FileExists

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

FileName FileName FileName FileName

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

IsNull IsNull IsNull IsNull

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

Length Length Length Length

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

Position Position Position Position

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

ReadTimeout ReadTimeout ReadTimeout ReadTimeout

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

(Inherited from Stream)
Value Value Value Value

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

WriteTimeout WriteTimeout WriteTimeout WriteTimeout

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

(Inherited from Stream)

方法

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

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

(Inherited from Stream)
BeginWrite(Byte[], Int32, Int32, AsyncCallback, Object) BeginWrite(Byte[], Int32, Int32, AsyncCallback, Object) BeginWrite(Byte[], Int32, Int32, AsyncCallback, Object) BeginWrite(Byte[], Int32, Int32, AsyncCallback, Object)

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

(Inherited from Stream)
Clone() Clone() Clone() Clone()

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

Close() Close() Close() 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.

(Inherited from Stream)
CopyTo(Int64, OracleLob, Int64, Int64) CopyTo(Int64, OracleLob, Int64, Int64) CopyTo(Int64, OracleLob, Int64, Int64) 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) CopyTo(OracleLob) CopyTo(OracleLob) CopyTo(OracleLob)

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

CopyTo(OracleLob, Int64) CopyTo(OracleLob, Int64) CopyTo(OracleLob, Int64) CopyTo(OracleLob, Int64)

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

CopyTo(Stream) CopyTo(Stream) CopyTo(Stream) CopyTo(Stream)

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

(Inherited from Stream)
CopyTo(Stream, Int32) CopyTo(Stream, Int32) CopyTo(Stream, Int32) CopyTo(Stream, Int32)

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

(Inherited from Stream)
CopyToAsync(Stream) CopyToAsync(Stream) CopyToAsync(Stream) CopyToAsync(Stream)

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

(Inherited from Stream)
CopyToAsync(Stream, CancellationToken) CopyToAsync(Stream, CancellationToken) CopyToAsync(Stream, CancellationToken) CopyToAsync(Stream, CancellationToken)

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

(Inherited from Stream)
CopyToAsync(Stream, Int32) CopyToAsync(Stream, Int32) CopyToAsync(Stream, Int32) CopyToAsync(Stream, Int32)

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

(Inherited from Stream)
CopyToAsync(Stream, Int32, CancellationToken) CopyToAsync(Stream, Int32, CancellationToken) CopyToAsync(Stream, Int32, CancellationToken) 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.

(Inherited from Stream)
CreateObjRef(Type) CreateObjRef(Type) CreateObjRef(Type) CreateObjRef(Type)

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

(Inherited from MarshalByRefObject)
CreateWaitHandle() CreateWaitHandle() CreateWaitHandle() CreateWaitHandle()

分配 WaitHandle 对象。Allocates a WaitHandle object.

(Inherited from Stream)
Dispose() Dispose() Dispose() Dispose()

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

Dispose(Boolean) Dispose(Boolean) Dispose(Boolean) Dispose(Boolean)

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

(Inherited from Stream)
DisposeAsync() DisposeAsync() DisposeAsync() DisposeAsync()

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

(Inherited from Stream)
EndRead(IAsyncResult) EndRead(IAsyncResult) EndRead(IAsyncResult) EndRead(IAsyncResult)

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

(Inherited from Stream)
EndWrite(IAsyncResult) EndWrite(IAsyncResult) EndWrite(IAsyncResult) EndWrite(IAsyncResult)

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

(Inherited from Stream)
Equals(Object) Equals(Object) Equals(Object) Equals(Object)

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

(Inherited from Object)
Flush() Flush() Flush() Flush()

目前尚不支持。Not currently supported.

FlushAsync() FlushAsync() FlushAsync() FlushAsync()

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

(Inherited from Stream)
FlushAsync(CancellationToken) FlushAsync(CancellationToken) FlushAsync(CancellationToken) FlushAsync(CancellationToken)

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

(Inherited from Stream)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

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

(Inherited from Object)
GetLifetimeService() GetLifetimeService() GetLifetimeService() GetLifetimeService()

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

(Inherited from MarshalByRefObject)
GetType() GetType() GetType() GetType()

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

(Inherited from Object)
InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService()

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

(Inherited from MarshalByRefObject)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

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

(Inherited from Object)
MemberwiseClone(Boolean) MemberwiseClone(Boolean) MemberwiseClone(Boolean) MemberwiseClone(Boolean)

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

(Inherited from MarshalByRefObject)
ObjectInvariant() ObjectInvariant() ObjectInvariant() ObjectInvariant()

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

(Inherited from Stream)
Read(Byte[], Int32, Int32) Read(Byte[], Int32, Int32) Read(Byte[], Int32, Int32) 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>) Read(Span<Byte>) Read(Span<Byte>) 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.

(Inherited from Stream)
ReadAsync(Byte[], Int32, Int32) ReadAsync(Byte[], Int32, Int32) ReadAsync(Byte[], Int32, Int32) 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.

(Inherited from Stream)
ReadAsync(Byte[], Int32, Int32, CancellationToken) ReadAsync(Byte[], Int32, Int32, CancellationToken) ReadAsync(Byte[], Int32, Int32, CancellationToken) 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.

(Inherited from Stream)
ReadAsync(Memory<Byte>, CancellationToken) ReadAsync(Memory<Byte>, CancellationToken) ReadAsync(Memory<Byte>, CancellationToken) 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.

(Inherited from Stream)
ReadByte() ReadByte() ReadByte() 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.

(Inherited from Stream)
Seek(Int64, SeekOrigin) Seek(Int64, SeekOrigin) Seek(Int64, SeekOrigin) Seek(Int64, SeekOrigin)

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

SetFileName(String, String) SetFileName(String, String) SetFileName(String, String) SetFileName(String, String)

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

SetLength(Int64) SetLength(Int64) SetLength(Int64) SetLength(Int64)

目前尚不支持。Not currently supported.

ToString() ToString() ToString() ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(Inherited from Object)
Write(Byte[], Int32, Int32) Write(Byte[], Int32, Int32) Write(Byte[], Int32, Int32) Write(Byte[], Int32, Int32)

目前尚不支持。Not currently supported.

Write(ReadOnlySpan<Byte>) Write(ReadOnlySpan<Byte>) Write(ReadOnlySpan<Byte>) 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.

(Inherited from Stream)
WriteAsync(Byte[], Int32, Int32) WriteAsync(Byte[], Int32, Int32) WriteAsync(Byte[], Int32, Int32) 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.

(Inherited from Stream)
WriteAsync(Byte[], Int32, Int32, CancellationToken) WriteAsync(Byte[], Int32, Int32, CancellationToken) WriteAsync(Byte[], Int32, Int32, CancellationToken) 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.

(Inherited from Stream)
WriteAsync(ReadOnlyMemory<Byte>, CancellationToken) WriteAsync(ReadOnlyMemory<Byte>, CancellationToken) WriteAsync(ReadOnlyMemory<Byte>, CancellationToken) 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.

(Inherited from Stream)
WriteByte(Byte) WriteByte(Byte) WriteByte(Byte) WriteByte(Byte)

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

(Inherited from Stream)

显式界面实现

IDisposable.Dispose() IDisposable.Dispose() IDisposable.Dispose() IDisposable.Dispose()

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

(Inherited from Stream)

适用于