Skip Headers

Oracle® Data Provider for .NET Developer's Guide
Release 9.2.0.4

Part Number B10961-01
Go To Table Of Contents
Contents
Go To Index
Index

Go to previous page Go to beginning of chapter Go to next page

Oracle.DataAccess.Types Namespace (ODP.NET Types), 14 of 19


OracleBFile Class

An OracleBFile is an object that has a reference to BFILE data. It provides methods for performing operations on BFiles.


Note:

OracleBFile is supported for applications running against Oracle8.x and higher.


Class Inheritance

Object

  MarshalByRefObject

    Stream

      OracleBFile

Declaration
// C#
public sealed class OracleBFile : Stream, ICloneable
Thread Safety

All public static methods are thread-safe, although instance methods do not guarantee thread safety.

Remarks

OracleBFile is supported for applications running against Oracle8.x and higher.

Example
[C#]
  ...
  // assume:
  // 1. A valid connection is made
  // 2. contains a file c:\MyDir\MyFile.txt
  OracleBFile oraBFile = new OracleBFile(con, "c:\\MyDir", "MyFile.txt");

  // Open the oraBFile
  oraBFile.Open();

  // Read some data
  ...
  int byteRead = oraBFile.Read(buffer, bufferOffset, amountToBeRead);

  // Search for the 2nd occurrence of a byte pattern '123'
  // from oraBFile starting at offset 1
  byte[] pattern = new byte[3] { 1,2,3 };
  int positionFound = oraBFile.Search(pattern, 1, 2);

  // Close the BFile
  oraBFile.CloseFile();
  ...
Requirements

Namespace: Oracle.DataAccess.Types

Assembly: Oracle.DataAccess.dll

See Also:

OracleBFile Members

OracleBFile members are listed in the following tables:

OracleBFile Constructors

OracleBFile constructors are listed in Table 5-147.

Table 5-147 OracleBFile Constructors
Constructor Description

OracleBFile Constructors

Creates an instance of the OracleBFile class (Overloaded)

OracleBFile Static Fields

OracleBFile static fields are listed in Table 5-148.

Table 5-148 OracleBFile Static Fields  
Field Description

MaxSize

The static field holds the maximum number of bytes a BFILE can hold, which is 4,294,967,295 (2^32 - 1) bytes

OracleBFile Static Methods

OracleBFile static methods are listed in Table 5-149.

Table 5-149 OracleBFile Static Methods  
Methods Description

Equals

Inherited from Object (Overloaded)

OracleBFile Instance Properties

OracleBFile instance properties are listed in Table 5-150.

Table 5-150 OracleBFile Instance Properties  
Properties Description

CanRead

Indicates whether the LOB stream can be read

CanSeek

Indicates whether forward and backward seek operations can be performed

CanWrite

Indicates whether the LOB object supports writing

Connection

Indicates the connection used to read from a BFILE

DirectoryName

Indicates the directory alias of the BFILE

FileExists

Indicates whether or not the specified BFILE exists

FileName

Indicates the name of the BFILE

IsEmpty

Indicates whether the BFILE is empty or not

IsOpen

Indicates whether the BFILE has been opened by this instance or not

Length

Indicates the size of the BFILE data in bytes

Position

Indicates the current read position in the LOB stream

Value

Returns the data, starting from the first byte in BFILE, as a byte array

OracleBFile Instance Methods

OracleBFile instance methods are listed in Table 5-151.

Table 5-151 OracleBFile Instance Methods  
Methods Description

BeginRead

Inherited from Stream

BeginWrite

Not Supported

Clone

Creates a copy of an OracleBFile object

Close

Closes the current stream and releases any resources associated with the stream

CloseFile

Closes the BFILE referenced by the current BFILE instance

Compare

Compares data referenced by the two OracleBFiles

CreateObjRef

Inherited from MarshalByRefObject

CopyTo

Copies data as specified (Overloaded)

Dispose

Releases resources allocated by this object

EndRead

Inherited from Stream

EndWrite

Not Supported

Equals

Inherited from Object (Overloaded)

Flush

Not Supported

GetHashCode

Inherited from Object

GetLifetimeService

Inherited from MarshalByRefObject

GetType

Inherited from Object

InitializeLifetimeService

Inherited from MarshalByRefObject

IsEqual

Compares the LOB references

OpenFile

Opens the BFILE specified by the FileName and DirectoryName

Read

Reads a specified amount of bytes from the OracleBFile instance and populates the buffer

ReadByte

Inherited from Stream

Search

Searches for a binary pattern in the current instance of an OracleBFile

Seek

Sets the position on the current LOB stream

SetLength

Not Supported

ToString

Inherited from Object

Write

Not Supported

WriteByte

Not Supported

See Also:

OracleBFile Constructors

OracleBFile constructors create new instances of the OracleBFile class.

Overload List:

OracleBFile(OracleConnection)

This constructor creates an instance of the OracleBFile class with an OracleConnection object.

Declaration
// C#
public OracleBFile(OracleConnection con);
Parameters
Exceptions

InvalidOperationException - The OracleConnection is not open or has been closed during the lifetime of the object.

Remarks

The connection must be opened explicitly by the application. OracleBFile does not open the connection implicitly.

See Also:

OracleBFile(OracleConnection, string, string)

This constructor creates an instance of the OracleBFile class with an OracleConnection object, the location of the BFILE, and the name of the BFILE.

Declaration
// C#
public OracleBFile(OracleConnection con, string directoryName, string fileName);
Parameters
Exceptions

InvalidOperationException - The OracleConnection is not open or has been closed during the lifetime of the object.

Remarks

The OracleConnection must be opened explicitly by the application. OracleBFile does not open the connection implicitly.

To initialize a BFILE column using an OracleBFile instance as an input parameter of a SQL INSERT statement, directoryName and fileName must be properly set.

See Also:

OracleBFile Static Fields

OracleBFile static fields are listed in Table 5-152.

Table 5-152 OracleBFile Static Fields  
Field Description

MaxSize

The static field holds the maximum number of bytes a BFILE can hold, which is 4,294,967,295 (2^32 - 1) bytes

See Also:

MaxSize

This static field holds the maximum number of bytes a BFILE can hold, which is 4,294,967,295 (2^32 - 1) bytes.

Declaration
// C#
public static readonly Int64 MaxSize = 4294967295;
Remarks

This field is useful in code that checks whether the operation exceeds the maximum length allowed.

See Also:

OracleBFile Static Methods

OracleBFile static methods are listed in Table 5-153.

Table 5-153 OracleBFile Static Methods  
Methods Description

Equals

Inherited from Object (Overloaded)

See Also:

OracleBFile Instance Properties

OracleBFile instance properties are listed in Table 5-154.

Table 5-154 OracleBFile Instance Properties  
Properties Description

CanRead

Indicates whether the LOB stream can be read

CanSeek

Indicates whether forward and backward seek operations can be performed

CanWrite

Indicates whether the LOB object supports writing

Connection

Indicates the connection used to read from a BFILE

DirectoryName

Indicates the directory alias of the BFILE

FileExists

Indicates whether or not the specified BFILE exists

FileName

Indicates the name of the BFILE

IsEmpty

Indicates whether the BFILE is empty or not

IsOpen

Indicates whether the BFILE has been opened by this instance or not

Length

Indicates the size of the BFILE data in bytes

Position

Indicates the current read position in the LOB stream

Value

Returns the data, starting from the first byte in BFILE, as a byte array

See Also:

CanRead

Overrides Stream

This instance property indicates whether the LOB stream can be read.

Declaration
// C#
public override bool CanRead{get;}
Property Value

If the LOB stream can be read, returns true; otherwise, returns false.

See Also:

CanSeek

Overrides Stream

This instance property indicates whether forward and backward seek operations can be performed.

Declaration
// C#
public override bool CanSeek{get;}
Property Value

If forward and backward seek operations can be performed, returns true; otherwise, returns false.

See Also:

CanWrite

Overrides Stream

This instance property indicates whether the LOB object supports writing.

Declaration
// C#
public override bool CanWrite{get;}
Property Value

BFILE is read only.

Remarks

BFILE is read-only, therefore, the boolean value is always false.

See Also:

Connection

This instance property indicates the connection used to read from a BFILE.

Declaration
// C#
public OracleConnection Connection {get;}
Property Value

An object of OracleConnection.

Exceptions

ObjectDisposedException - The object is already disposed.

See Also:

DirectoryName

This instance property indicates the directory alias of the BFILE.

Declaration
// C#
public string DirectoryName {get;set;}
Property Value

A string.

Exceptions

ObjectDisposedException - The object is already disposed.

InvalidOperationException - The value of the DirectoryName changed while the BFILE is open.

Remarks

The maximum length of a DirectoryName is 30 bytes.

See Also:

FileExists

This instance property indicates whether or not the BFILE specified by the DirectoryName and FileName exists.

Declaration
// C#
public bool FileExists {get;}
Property Value

bool

Exceptions

ObjectDisposedException - The object is already disposed.

InvalidOperationException - The OracleConnection is not open or has been closed during the lifetime of the object.

Remarks

Unless a connection, file name, and directory name are provided, this property is set to false by default.

See Also:

FileName

This instance property indicates the name of the BFILE.

Declaration
// C#
public string FileName {get;set}
Property Value

A string that contains the BFILE name.

Exceptions

ObjectDisposedException - The object is already disposed.

InvalidOperationException - The value of the DirectoryName changed while the BFILE is open.

Remarks

The maximum length of a FileName is 255 bytes.

Changing the FileName property while the BFILE object is opened causes an exception.

See Also:

IsEmpty

This instance property indicates whether the BFILE is empty or not.

Declaration
// C#
public bool IsEmpty {get;}
Property Value

bool

Exceptions

ObjectDisposedException - The object is already disposed.

See Also:

IsOpen

This instance property indicates whether the BFILE has been opened by this instance or not.

Declaration
// C#
public bool IsOpen {get;}
Property Value

A bool.

See Also:

Length

Overrides Stream

This instance property indicates the size of the BFILE data in bytes.

Declaration
// C#
public override Int64 Length {get;}
Property Value

Int64

Exceptions

ObjectDisposedException - The object is already disposed.

InvalidOperationException - The OracleConnection is not open or has been closed during the lifetime of the object.

See Also:

Position

Overrides Stream

This instance property indicates the current read position in the LOB stream.

Declaration
// C#
public override Int64 Position{get; set;}
Property Value

An Int64 value that indicates the read position.

Exceptions

ObjectDisposedException - The object is already disposed.

InvalidOperationException - The OracleConnection is not open or has been closed during the lifetime of the object.

ArgumentOutOfRangeException - The value is less than 0.

See Also:

Value

This instance property returns the data, starting from the first byte in BFILE, as a byte array.

Declaration
// C#
public byte[] Value{get;}
Property Value

A byte array.

Exceptions

ObjectDisposedException - The object is already disposed.

InvalidOperationException - The OracleConnection is not open or has been closed during the lifetime of the object.

Remarks

The length of data is bound by the maximum length of the byte array. The current value of the Position property is not used or changed.

See Also:

OracleBFile Instance Methods

OracleBFile instance methods are listed in Table 5-155.

Table 5-155 OracleBFile Instance Methods  
Methods Description

BeginRead

Inherited from Stream

BeginWrite

Not Supported

Clone

Creates a copy of an OracleBFile object

Close

Closes the current stream and releases any resources associated with the stream

CloseFile

Closes the BFILE referenced by the current BFILE instance

Compare

Compares data referenced by the two OracleBFiles

CreateObjRef

Inherited from MarshalByRefObject

CopyTo

Copies data as specified (Overloaded)

Dispose

Releases resources allocated by this object

EndRead

Inherited from Stream

EndWrite

Not Supported

Equals

Inherited from Object (Overloaded)

Flush

Not Supported

GetHashCode

Inherited from Object

GetLifetimeService

Inherited from MarshalByRefObject

GetType

Inherited from Object

InitializeLifetimeService

Inherited from MarshalByRefObject

IsEqual

Compares the LOB references

OpenFile

Opens the BFILE specified by the FileName and DirectoryName

Read

Reads a specified amount of bytes from the OracleBFile instance and populates the buffer

ReadByte

Inherited from Stream

Search

Searches for a binary pattern in the current instance of an OracleBFile

Seek

Sets the position on the current LOB stream

SetLength

Not Supported

ToString

Inherited from Object

Write

Not Supported

WriteByte

Not Supported

See Also:

Clone

This instance method creates a copy of an OracleBFile object.

Declaration
// C#
public object Clone();
Return Value

An OracleBFile object.

Implements

ICloneable

Exceptions

ObjectDisposedException - The object is already disposed.

InvalidOperationException - The OracleConnection is not open or has been closed during the lifetime of the object.

Remarks

The cloned object has the same property values as that of the object being cloned.

Example
// C#
...
//Need a proper casting for the return value when cloned
OracleBFile oraBfile_cloned = (OracleBFile) oraBfile.Clone();
...

See Also:

Close

Overrides Stream

This instance method closes the current stream and releases any resources associated with it.

Declaration
// C#
public override void Close();
Exceptions

ObjectDisposedException - The object is already disposed.

InvalidOperationException - The OracleConnection is not open or has been closed during the lifetime of the object.

See Also:

CloseFile

This instance method closes the BFILE referenced by the current BFILE instance.

Declaration
// C#
public void CloseFile();
Remarks

No error is returned if the BFILE exists, but is not opened.

See Also:

Compare

This instance method compares data referenced by the two OracleBFiles.

Declaration
// C#
public int Compare(Int64 src_offset, OracleBFile obj, Int64 dst_offset, Int64 
amount);
Parameters
Return Value

Returns a number that is:

Exceptions

ObjectDisposedException - The object is already disposed.

InvalidOperationException - The OracleConnection is not open or has been closed during the lifetime of the object.

ArgumentOutOfRangeException - The src_offset, the dst_offset, or the amount is less than 0.

Remarks

The provided object and the current instance must be using the same connection, that is, the same OracleConnection object.

The BFILE needs to be opened using OpenFile before the operation.

Example
  // C#
  ...
  // Assume you have 2 valid files in C:\MyDir
  OracleBFile myBFile1 = new OracleBFile(con, "c:\\MyDir", "MyFile1.txt");
  OracleBFile myBFile2 = new OracleBFile(con, "c:\\MyDir", "MyFile2.txt");

  int src_offset = 10;
  int dst_offset = 20;
  int amount     = 5;

  int result = myBFile1.Compare(src_offset, myBFile2, dst_offset, amount);

  if ( result == 0 )
    Console.WriteLine("Identical");
  else
    Console.WriteLine("Not Identical");
  ...

See Also:

CopyTo

CopyTo copies data from the current instance to the provided object.

Overload List:

CopyTo(OracleBlob)

This instance method copies data from the current instance to the provided OracleBlob object.

Declaration
// C#
public Int64 CopyTo(OracleBlob obj);
Parameters
Return Value

The return value is the amount copied.

Exceptions

ObjectDisposedException - The object is already disposed.

InvalidOperationException - This exception is thrown if any of the following conditions exist:

Remarks

The provided object and the current instance must be using the same connection; that is, the same OracleConnection object.

See Also:

CopyTo(OracleBlob, Int64)

This instance method copies data from the current OracleBFile instance to the provided OracleBlob object with the specified destination offset.

Declaration
// C#
public Int64 CopyTo(OracleBlob obj, Int64 dst_offset);
Parameters
Return Value

The return value is the amount copied.

Exceptions

ObjectDisposedException - The object is already disposed.

ArgumentOutOfRangeException - The dst_offset is less than 0.

InvalidOperationException - This exception is thrown if any of the following conditions exist:

Remarks

If the dst_offset is beyond the end of the OracleBlob data, spaces are written into the OracleBlob until the dst_offset is met.

The offsets are 0-based. No character conversion is performed by this operation.

The provided object and the current instance must be using the same connection; that is, the same OracleConnection object.

See Also:

CopyTo(Int64, OracleBlob, Int64, Int64)

This instance method copies data from the current OracleBFile instance to the provided OracleBlob object with the specified source offset, destination offset, and character amounts.

Declaration
// C#
public Int64 CopyTo(Int64 src_offset,OracleBlob obj,Int64 dst_offset, Int64 
amount);
Parameters
Return Value

The return value is the amount copied.

Exceptions

ObjectDisposedException - The object is already disposed.

ArgumentOutOfRangeException - The src_offset, the dst_offset, or the amount is less than 0.

InvalidOperationException - This exception is thrown if any of the following conditions exist:

Remarks

If the dst_offset is beyond the end of the OracleBlob data, spaces are written into the OracleBlob until the dst_offset is met.

The offsets are 0-based. No character conversion is performed by this operation.

The provided object and the current instance must be using the same connection; that is, the same OracleConnection object.

See Also:

CopyTo(OracleClob)

This instance method copies data from the current OracleBFile instance to the provided OracleClob object.

Declaration
// C#
public Int64 CopyTo(OracleClob obj);
Parameters
Return Value

The return value is the amount copied.

Exceptions

ObjectDisposedException - The object is already disposed.

InvalidOperationException - This exception is thrown if any of the following conditions exist:

Remarks

The provided object and the current instance must be using the same connection, that is, the same OracleConnection object.

See Also:

CopyTo(OracleClob, Int64)

This instance method copies data from the current OracleBFile instance to the provided OracleClob object with the specified destination offset.

Declaration
// C#
public Int64 CopyTo(OracleClob obj, Int64 dst_offset);
Parameters
Return Value

The amount copied.

Exceptions
Exceptions

ObjectDisposedException - The object is already disposed.

ArgumentOutOfRangeException - The dst_offset is less than 0.

InvalidOperationException - This exception is thrown if any of the following conditions exist:

Remarks

If the dst_offset is beyond the end of the OracleClob data, spaces are written into the OracleClob until the dst_offset is met.

The offsets are 0-based. No character conversion is performed by this operation.

The provided object and the current instance must be using the same connection, that is, the same OracleConnection object.

See Also:

CopyTo(Int64, OracleClob, Int64, Int64)

This instance method copies data from the current OracleBFile instance to the provided OracleClob object with the specified source offset, destination offset, and amount of characters.

Declaration
// C#
public Int64 CopyTo(Int64 src_offset,OracleClob obj,Int64 dst_offset,Int64 
amount);
Parameters
Return Value

The return value is the amount copied.

Exceptions

ObjectDisposedException - The object is already disposed.

ArgumentOutOfRangeException - The src_offset, the dst_offset, or the amount is less than 0.

InvalidOperationException - This exception is thrown if any of the following conditions exist:

Remarks

If the dst_offset is beyond the end of the current OracleClob data, spaces are written into the OracleClob until the dst_offset is met.

The offsets are 0-based. No character conversion is performed by this operation.

The provided object and the current instance must be using the same connection, that is, the same OracleConnection object.

See Also:

Dispose

This instance method releases resources allocated by this object.

Declaration
// C#
public void Dispose();
Implements

IDisposable

Remarks

Although some properties can still be accessed, their values may not be accountable. Since resources are freed, method calls may lead to exceptions. The object cannot be reused after being disposed.

See Also:

IsEqual

This instance method compares the LOB references.

Declaration
// C#
public bool IsEqual(OracleBFile obj);
Parameters
Return Value

Returns true if the current OracleBFile and the provided OracleBFile object refer to the same external LOB. Returns false otherwise.

Exceptions

ObjectDisposedException - The object is already disposed.

InvalidOperationException - The OracleConnection is not open or has been closed during the lifetime of the object.

Remarks

Note that this method can return true even if the two OracleBFile objects return false for == or Equals() since two different OracleBFile instances can refer to the same external LOB.

The provided object and the current instance must be using the same connection; that is, the same OracleConnection object.

See Also:

OpenFile

This instance method opens the BFILE specified by the FileName and DirectoryName.

Declaration
// C#
public void OpenFile();
Exceptions

ObjectDisposedException - The object is already disposed.

InvalidOperationException - The OracleConnection is not open or has been closed during the lifetime of the object.

Remarks

Many operations, such as Compare(), CopyTo(), Read(), and Search() require that the BFILE be opened using OpenFile before the operation.

Calling OpenFile on an opened BFILE is not operational.

See Also:

Read

Overrides Stream

This instance method reads a specified amount of bytes from the OracleBFile instance and populates the buffer.

Declaration
// C#
public override int Read(byte[ ] buffer, int offset, int count);
Parameters
Return Value

The return value indicates the number of bytes read from the BFILE, that is, the external LOB.

Exceptions

ObjectDisposedException - The object is already disposed.

InvalidOperationException - The OracleConnection is not open or has been closed during the lifetime of the object.

ArgumentOutOfRangeException - Either the offset or the count parameter is less than 0 or the offset is greater than or equal to the buffer.Length or the offset and the count together are greater than buffer.Length.

Remarks

The LOB data is read starting from the position specified by the Position property.

Example
  // C#
  ...
  byte buffer         = new byte[1024];
  int  bufferOffset   = 10;
  int  amountToBeRead = 10;

  // Read some data
  int byteRead = oraBFile.Read(buffer, bufferOffset, amountToBeRead);
  ...

See Also:

Search

This instance method searches for a binary pattern in the current instance of an OracleBFile.

Declaration
// C#
public int Search(byte[ ] val, Int64 offset, Int64 nth);
Parameters
Return Value

Returns the absolute offset of the start of the matched pattern (in bytes) for the nth occurrence of the match. Otherwise, 0 is returned.

Exceptions

ObjectDisposedException - The object is already disposed.

InvalidOperationException - The OracleConnection is not open or has been closed during the lifetime of the object.

ArgumentOutOfRangeException - Either the offset is less than 0 or nth is less than or equal to 0 or val.Length is greater than 16383 or nth is greater than or equal to OracleBFile.MaxSize or offset is greater than or equal to OracleBFile.MaxSize.

Remarks

The limit of the search pattern is 16383 bytes.

Example
// C#
...
// Search for the 2nd occurrence of a byte pattern '123'
// from oraBFile starting at offset 1
byte[] pattern = new byte[3] { 1,2,3 };
int positionFound = oraBFile.Search(pattern, 1, 2);
...

See Also:

Seek

Overrides Stream

This instance method sets the position on the current LOB stream.

Declaration
// C#
public override int64 Seek(Int64 offset, SeekOrigin origin);
Parameters
Return Value

Returns an Int64 that indicates the position.

Exceptions

ObjectDisposedException - The object is already disposed.

InvalidOperationException - The OracleConnection is not open or has been closed during the lifetime of the object.

Remarks

If offset is negative, the new position precedes the position specified by origin by the number of bytes specified by offset.

If offset is zero, the new position is the position specified by origin.

If offset is positive, the new position follows the position specified by origin by the number of bytes specified by offset.

SeekOrigin.Begin specifies the beginning of a stream.

SeekOrigin.Current specifies the current position within a stream.

SeekOrigin.End specifies the end of a stream.

Example
// C#
 ...
// Set the Position to 5 bytes (with respect to SeekOrigin.Begin), read 10 bytes
// out, and put the data in a buffer with offset = 10 bytes
byte buffer         = new byte[1024];
int  bufferOffset   = 10;
int  amountToBeRead = 10;
// Seek
int newPosition = oraBFile.Seek(5, SeekOrigin.Begin);

// Read some data
int byteRead = oraBFile.Read(buffer, bufferOffset, amountToBeRead);
...


See Also:


Go to previous page Go to beginning of chapter Go to next page
Oracle
Copyright © 2002, 2003 Oracle Corporation.

All Rights Reserved.
Go To Table Of Contents
Contents
Go To Index
Index