OracleBFile OracleBFile OracleBFile OracleBFile Class

Definition

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
Inheritance
Implements

Remarks

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. 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. Note that the BFILE data type provides read-only access to data. Therefore, write-oriented methods inherited from the Stream class are not supported.

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. 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.

The BFILE data type should be used for referencing LOBs that are large in size, and therefore, not practical to store in the database. There is client, server, and communication overhead for using a BFILE data type compared to the LOB data type. It is more efficient to access a BFILE if you only need to obtain a small amount of data. It is more efficient to access database-resident LOBs if you need to obtain the entire object.

Each non-NULL OracleBFile object is associated with two entities that define the location of the underlying physical file:

  • An Oracle DIRECTORY object, which is a database alias for a directory in the file system, and

  • The file name of the underlying physical file, which is located in the directory associated with the DIRECTORY object.

After a BFILE is created, you can retrieve its locator in the form of an OracleBFile object using the ExecuteReader or ExecuteScalar methods.

To obtain an OracleBFile object, call the GetOracleBFile method.

The physical file that an OracleBFile object is associated with does not need to exist until you attempt to access it. An application can bind an OracleBFile to a nonexistent file, create the physical file in the expected location, and then call Read.

Any attempt to access a closed OracleBFile using the Read or Seek methods reopens an OracleBFile stream automatically.

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. 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;
}

For more information about creating and using an Oracle BFILE, see the appropriate topic in your Oracle documentation.

Note

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.

Fields

Null Null Null Null

Represents a null OracleBFile object that is not bound to a physical file.

Properties

CanRead CanRead CanRead CanRead

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

Gets the OracleConnection used by this instance of the OracleBFile.

DirectoryName DirectoryName DirectoryName DirectoryName

Gets the name of the DIRECTORY object, with which an OracleBFile object is associated.

FileExists FileExists FileExists FileExists

Gets a value indicating whether a physical file containing BFILE data exists in the operating system.

FileName FileName FileName FileName

Gets the name of the BFILE without the path.

IsNull IsNull IsNull IsNull

Gets a value that indicates whether the OracleBFile is a Null stream.

Length Length Length Length

Gets a value that returns the length in bytes of the physical file with which the OracleBFile object is associated.

Position Position Position Position

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

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)

Methods

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. (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. (Consider using WriteAsync(Byte[], Int32, Int32) instead.)

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

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)

Copies 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)

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)

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

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)

Releases the unmanaged resources used by the Stream and optionally releases the managed resources.

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

Waits for the pending asynchronous read to complete. (Consider using ReadAsync(Byte[], Int32, Int32) instead.)

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

Ends an asynchronous write operation. (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()

Gets 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()

Creates a shallow copy of the current Object.

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

Creates a shallow copy of the current MarshalByRefObject object.

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

Provides support for a Contract.

(Inherited from Stream)
Read(Byte[], Int32, Int32) Read(Byte[], Int32, Int32) Read(Byte[], Int32, Int32) Read(Byte[], Int32, Int32)

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

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)

Sets the position on the current OracleBFile stream.

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

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>) 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) 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)

Explicit Interface Implementations

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

Releases all resources used by the Stream.

(Inherited from Stream)

Applies to