Oracle® Data Provider for .NET Developer's Guide 11g Release 2 (11.2.0.3) Part Number E23174-02 |
|
|
PDF · Mobi · ePub |
An OracleBFile
is an object that has a reference to BFILE
data. It provides methods for performing operations on BFILE
s.
Note:
OracleBFile
is supported for applications running against Oracle8.x and later.System.Object
System.MarshalByRefObject
System.IO.Stream
Oracle.DataAccess.Types.OracleBFile
// C# public sealed class OracleBFile : Stream, ICloneable, INullable
All public static methods are thread-safe, although instance methods do not guarantee thread safety.
OracleBFile
is supported for applications running against Oracle8.x and later.
// Database Setup, if you have not done so yet. /* Log on as DBA (SYS or SYSTEM) that has CREATE ANY DIRECTORY privilege. CREATE OR REPLACE DIRECTORY MYDIR AS 'C:\TEMP'; */ // C# using System; using Oracle.DataAccess.Client; using Oracle.DataAccess.Types; class OracleBFileSample { static void Main() { // Create MYDIR directory object as indicated previously and create a file // MyFile.txt with the text ABCDABC under C:\TEMP directory. // Note that the byte representation of the ABCDABC is 65666768656667 string constr = "User Id=scott;Password=tiger;Data Source=oracle"; OracleConnection con = new OracleConnection(constr); con.Open(); OracleBFile bFile = new OracleBFile(con, "MYDIR", "MyFile.txt"); // Open the OracleBFile bFile.OpenFile(); // Read 7 bytes into readBuffer, starting at buffer offset 0 byte[] readBuffer = new byte[7]; int bytesRead = bFile.Read(readBuffer, 0, 7); // Prints "bytesRead = 7" Console.WriteLine("bytesRead = " + bytesRead); // Prints "readBuffer = 65666768656667" Console.Write("readBuffer = "); for(int index = 0; index < readBuffer.Length; index++) { Console.Write(readBuffer[index]); } Console.WriteLine(); // Search for the 2nd occurrence of a byte pattern {66,67} // starting from byte offset 1 in the OracleBFile byte[] pattern = new byte[2] {66, 67}; long posFound = bFile.Search(pattern, 1, 2); // Prints "posFound = 6" Console.WriteLine("posFound = " + posFound); // Close the OracleBFile bFile.CloseFile(); bFile.Close(); bFile.Dispose(); con.Close(); con.Dispose(); } }
Namespace: Oracle.DataAccess.Types
Assembly: Oracle.DataAccess.dll
ODP.NET Version: ODP.NET for .NET Framework 2.0 or ODP.NET for .NET Framework 4
See Also:
OracleBFile
members are listed in the following tables.
OracleBFile
constructors are listed in Table 13-1.
Table 13-1 OracleBFile Constructors
Constructor | Description |
---|---|
Creates an instance of the |
OracleBFile
static fields are listed in Table 13-2.
Table 13-2 OracleBFile Static Fields
Field | Description |
---|---|
The static field holds the maximum number of bytes a |
|
Represents a null value that can be assigned to the value of an |
OracleBFile
static methods are listed in Table 13-3.
Table 13-3 OracleBFile Static Methods
Methods | Description |
---|---|
|
Inherited from |
OracleBFile Instance Properties
OracleBFile
instance properties are listed in Table 13-4.
Table 13-4 OracleBFile Instance Properties
Properties | Description |
---|---|
Indicates whether or not the LOB stream can be read |
|
Indicates whether or not forward and backward seek operations can be performed |
|
Indicates whether or not the LOB object supports writing |
|
Indicates the connection used to read from a |
|
Indicates the directory alias of the |
|
Indicates whether or not the specified |
|
Indicates the name of the |
|
Indicates whether the |
|
Indicates whether or not the current instance has a null value |
|
Indicates whether the |
|
Indicates the size of the |
|
Indicates the current read position in the LOB stream |
|
Returns the data, starting from the first byte in |
OracleBFile
instance methods are listed in Table 13-5.
Table 13-5 OracleBFile Instance Methods
Methods | Description |
---|---|
|
Inherited from |
|
Not Supported |
Creates a copy of an |
|
Closes the current stream and releases any resources associated with the stream |
|
Closes the |
|
Compares data referenced by the two |
|
|
Inherited from |
Copies data as specified (Overloaded) |
|
Releases resources allocated by this object |
|
|
Inherited from |
|
Not Supported |
|
Inherited from |
|
Not Supported |
|
Inherited from |
|
Inherited from |
|
Inherited from |
|
Inherited from |
Compares the LOB references |
|
Opens the |
|
Reads a specified amount of bytes from the |
|
|
Inherited from |
Searches for a binary pattern in the current instance of an |
|
Sets the position on the current LOB stream |
|
|
Not Supported |
|
Inherited from |
|
Not Supported |
|
Not Supported |
OracleBFile
constructors create new instances of the OracleBFile
class.
This constructor creates an instance of the OracleBFile
class with an OracleConnection
object.
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
.
This constructor creates an instance of the OracleBFile
class with an OracleConnection
object.
// C#
public OracleBFile(OracleConnection con);
con
The OracleConnection
object.
InvalidOperationException
- The OracleConnection
is not open or has been closed during the lifetime of the object.
The connection must be opened explicitly by the application. OracleBFile
does not open the connection implicitly.
This constructor creates an instance of the OracleBFile
class with an OracleConnection
object, the location of the BFILE
, and the name of the BFILE
.
// C# public OracleBFile(OracleConnection con, string directoryName, string fileName);
con
The OracleConnection
object.
directoryName
The directory alias created by the CREATE
DIRECTORY
SQL statement.
fileName
The name of the external LOB.
InvalidOperationException
- The OracleConnection
is not open or has been closed during the lifetime of the object.
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.
OracleBFile
static fields are listed in Table 13-6.
Table 13-6 OracleBFile Static Fields
Field | Description |
---|---|
The static field holds the maximum number of bytes a |
|
Represents a null value that can be assigned to the value of an |
This static field holds the maximum number of bytes a BFILE
can hold, which is 4,294,967,295 (2^32 - 1) bytes.
// C# public static readonly Int64 MaxSize = 4294967295;
This field is useful in code that checks whether or not the operation exceeds the maximum length allowed.
This static field represents a null value that can be assigned to the value of an OracleBFile
instance.
// C# public static readonly OracleBFile Null;
OracleBFile
static methods are listed in Table 13-7.
Table 13-7 OracleBFile Static Methods
Methods | Description |
---|---|
|
Inherited from |
OracleBFile
instance properties are listed in Table 13-8.
Table 13-8 OracleBFile Instance Properties
Properties | Description |
---|---|
Indicates whether or not the LOB stream can be read |
|
Indicates whether or not forward and backward seek operations can be performed |
|
Indicates whether or not the LOB object supports writing |
|
Indicates the connection used to read from a |
|
Indicates the directory alias of the |
|
Indicates whether or not the specified |
|
Indicates the name of the |
|
Indicates whether the |
|
Indicates whether or not the current instance has a null value |
|
Indicates whether the |
|
Indicates the size of the |
|
Indicates the current read position in the LOB stream |
|
Returns the data, starting from the first byte in |
Overrides Stream
This instance property indicates whether or not the LOB stream can be read.
// C# public override bool CanRead{get;}
If the LOB stream can be read, returns true
; otherwise, returns false
.
Overrides Stream
This instance property indicates whether or not forward and backward seek operations can be performed.
// C# public override bool CanSeek{get;}
If forward and backward seek operations can be performed, returns true
; otherwise, returns false
.
Overrides Stream
This instance property indicates whether or not the LOB object supports writing.
// C# public override bool CanWrite{get;}
BFILE
is read only.
BFILE
is read-only, therefore, the boolean value is always false
.
This instance property indicates the connection used to read from a BFILE
.
// C# public OracleConnection Connection {get;}
An object of OracleConnection
.
ObjectDisposedException
- The object is already disposed.
This instance property indicates the directory alias of the BFILE
.
// C# public string DirectoryName {get;set;}
A string
.
ObjectDisposedException
- The object is already disposed.
InvalidOperationException
- The value of the DirectoryName
changed while the BFILE
is open.
The maximum length of a DirectoryName
is 30 bytes.
This instance property indicates whether or not the BFILE
specified by the DirectoryName
and FileName
exists.
// C# public bool FileExists {get;}
bool
ObjectDisposedException
- The object is already disposed.
InvalidOperationException
- The OracleConnection
is not open or has been closed during the lifetime of the object.
Unless a connection, file name, and directory name are provided, this property is set to false
by default.
This instance property indicates the name of the BFILE
.
// C# public string FileName {get;set}
A string
that contains the BFILE
name.
ObjectDisposedException
- The object is already disposed.
InvalidOperationException
- The value of the DirectoryName
changed while the BFILE
is open.
The maximum length of a FileName
is 255 bytes.
Changing the FileName
property while the BFILE
object is opened causes an exception.
This instance property indicates whether the BFILE
is empty or not.
// C# public bool IsEmpty {get;}
bool
ObjectDisposedException
- The object is already disposed.
This property indicates whether or not the current instance has a null value.
// C# public bool IsNull{get;}
Returns true
if the current instance has a null value; otherwise, returns false
.
This instance property indicates whether the BFILE
has been opened by this instance or not.
// C# public bool IsOpen {get;}
A bool
.
Overrides Stream
This instance property indicates the size of the BFILE
data in bytes.
// C# public override Int64 Length {get;}
Int64
ObjectDisposedException
- The object is already disposed.
InvalidOperationException
- The OracleConnection
is not open or has been closed during the lifetime of the object.
Overrides Stream
This instance property indicates the current read position in the LOB stream.
// C# public override Int64 Position{get; set;}
An Int64
value that indicates the read position.
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.
This instance property returns the data, starting from the first byte in BFILE
, as a byte array.
// C# public byte[] Value{get;}
A byte array.
ObjectDisposedException
- The object is already disposed.
InvalidOperationException
- The OracleConnection
is not open or has been closed during the lifetime of the object.
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.
OracleBFile
instance methods are listed in Table 13-9.
Table 13-9 OracleBFile Instance Methods
Methods | Description |
---|---|
|
Inherited from |
|
Not Supported |
Creates a copy of an |
|
Closes the current stream and releases any resources associated with the stream |
|
Closes the |
|
Compares data referenced by the two |
|
|
Inherited from |
Copies data as specified (Overloaded) |
|
Releases resources allocated by this object |
|
|
Inherited from |
|
Not Supported |
|
Inherited from |
|
Not Supported |
|
Inherited from |
|
Inherited from |
|
Inherited from |
|
Inherited from |
Compares the LOB references |
|
Opens the |
|
Reads a specified amount of bytes from the |
|
|
Inherited from |
Searches for a binary pattern in the current instance of an |
|
Sets the position on the current LOB stream |
|
|
Not Supported |
|
Inherited from |
|
Not Supported |
|
Not Supported |
This instance method creates a copy of an OracleBFile
object.
// C# public object Clone();
An OracleBFile
object.
ICloneable
ObjectDisposedException
- The object is already disposed.
InvalidOperationException
- The OracleConnection
is not open or has been closed during the lifetime of the object.
The cloned object has the same property values as that of the object being cloned.
// Database Setup, if you have not done so yet. /* Log on as DBA (SYS or SYSTEM) that has CREATE ANY DIRECTORY privilege. CREATE OR REPLACE DIRECTORY MYDIR AS 'C:\TEMP'; */ // C# using System; using Oracle.DataAccess.Client; using Oracle.DataAccess.Types; class CloneSample { static void Main() { // Create MYDIR directory object as indicated previously and create a file // MyFile.txt with the text ABCDABC under C:\TEMP directory. // Note that the byte representation of the ABCDABC is 65666768656667 string constr = "User Id=scott;Password=tiger;Data Source=oracle"; OracleConnection con = new OracleConnection(constr); con.Open(); OracleBFile bFile1 = new OracleBFile(con, "MYDIR", "MyFile.txt"); // Prints "bFile1.Position = 0" Console.WriteLine("bFile1.Position = " + bFile1.Position); // Set the Position before calling Clone() bFile1.Position = 1; // Clone the OracleBFile OracleBFile bFile2 = (OracleBFile) bFile1.Clone(); // Prints "bFile2.Position = 1" Console.WriteLine("bFile2.Position = " + bFile2.Position); bFile1.Close(); bFile1.Dispose(); bFile2.Close(); bFile2.Dispose(); con.Close(); con.Dispose(); } }
Overrides Stream
This instance method closes the current stream and releases any resources associated with it.
// C# public override void Close();
ObjectDisposedException
- The object is already disposed.
InvalidOperationException
- The OracleConnection
is not open or has been closed during the lifetime of the object.
This instance method closes the BFILE
referenced by the current BFILE
instance.
// C# public void CloseFile();
No error is returned if the BFILE
exists, but is not opened.
This instance method compares data referenced by the two OracleBFile
s.
// C# public int Compare(Int64 src_offset, OracleBFile obj, Int64 dst_offset, Int64 amount);
src_offset
The offset of the current instance.
obj
The provided OracleBFile
object.
dst_offset
The offset of the OracleBFile
object.
amount
The number of bytes to compare.
Returns a number that is:
Less than zero: if the BFILE
data of the current instance is less than that of the provided BFILE
data.
Zero: if both the BFILE
s store the same data.
Greater than zero: if the BFILE
data of the current instance is greater than that of the provided BFILE
data.
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
.
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.
// Database Setup, if you have not done so yet. /* Log on as DBA (SYS or SYSTEM) that has CREATE ANY DIRECTORY privilege. CREATE OR REPLACE DIRECTORY MYDIR AS 'C:\TEMP'; */ // C# using System; using Oracle.DataAccess.Client; using Oracle.DataAccess.Types; class CompareSample { static void Main() { // Create MYDIR directory object as indicated previously and create a file // MyFile.txt with the text ABCDABC under C:\TEMP directory. // Note that the byte representation of the ABCDABC is 65666768656667 string constr = "User Id=scott;Password=tiger;Data Source=oracle"; OracleConnection con = new OracleConnection(constr); con.Open(); OracleBFile bFile1 = new OracleBFile(con, "MYDIR", "MyFile.txt"); OracleBFile bFile2 = new OracleBFile(con, "MYDIR", "MyFile.txt"); // Open the OracleBFiles bFile1.OpenFile(); bFile2.OpenFile(); // Compare 2 bytes from the 1st byte of bFile1 and // the 5th byte of bFile2 onwards int result = bFile1.Compare(1, bFile2, 5, 2); // Prints "result = 0" (Indicates the data is identical) Console.WriteLine("result = " + result); // Close the OracleBFiles bFile1.CloseFile(); bFile2.CloseFile(); bFile1.Close(); bFile1.Dispose(); bFile2.Close(); bFile2.Dispose(); con.Close(); con.Dispose(); } }
CopyTo
copies data from the current instance to the provided object.
This instance method copies data from the current instance to the provided OracleBlob
object.
This instance method copies data from the current OracleBFile
instance to the provided OracleBlob
object with the specified destination offset.
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.
This instance method copies data from the current OracleBFile
instance to the provided OracleClob
object.
This instance method copies data from the current OracleBFile
instance to the provided OracleClob
object with the specified destination offset.
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.
This instance method copies data from the current instance to the provided OracleBlob
object.
// C#
public Int64 CopyTo(OracleBlob obj);
obj
The OracleBlob
object to which the data is copied.
The return value is the amount copied.
ObjectDisposedException
- The object is already disposed.
InvalidOperationException
- This exception is thrown if any of the following conditions exist:
The OracleConnection
is not open or has been closed during the lifetime of the object.
The LOB object parameter has a different connection than the object.
The provided object and the current instance must be using the same connection; that is, the same OracleConnection
object.
This instance method copies data from the current OracleBFile
instance to the provided OracleBlob
object with the specified destination offset.
// C# public Int64 CopyTo(OracleBlob obj, Int64 dst_offset);
obj
The OracleBlob
object to which the data is copied.
dst_offset
The offset (in bytes) at which the OracleBlob
object is copied.
The return value is the amount copied.
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:
The OracleConnection
is not open or has been closed during the lifetime of the object.
The LOB object parameter has a different connection than the object.
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.
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.
// C# public Int64 CopyTo(Int64 src_offset,OracleBlob obj,Int64 dst_offset, Int64 amount);
src_offset
The offset (in bytes) in the current instance, from which the data is read.
obj
An OracleBlob
object to which the data is copied.
dst_offset
The offset (in bytes) to which the OracleBlob
object is copied.
amount
The amount of data to be copied.
The return value is the amount copied.
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:
The OracleConnection
is not open or has been closed during the lifetime of the object.
The LOB object parameter has a different connection than the object.
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.
This instance method copies data from the current OracleBFile
instance to the provided OracleClob
object.
// C#
public Int64 CopyTo(OracleClob obj);
obj
The OracleClob
object to which the data is copied.
The return value is the amount copied.
ObjectDisposedException
- The object is already disposed.
InvalidOperationException
- This exception is thrown if any of the following conditions exist:
The OracleConnection
is not open or has been closed during the lifetime of the object.
The LOB object parameter has a different connection than the object.
The provided object and the current instance must be using the same connection, that is, the same OracleConnection
object.
This instance method copies data from the current OracleBFile
instance to the provided OracleClob
object with the specified destination offset.
// C# public Int64 CopyTo(OracleClob obj, Int64 dst_offset);
obj
The OracleClob
object that the data is copied to.
dst_offset
The offset (in characters) at which the OracleClob
object is copied to.
The amount copied.
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:
The OracleConnection
is not open or has been closed during the lifetime of the object.
The LOB object parameter has a different connection than the object.
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.
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.
// C# public Int64 CopyTo(Int64 src_offset,OracleClob obj,Int64 dst_offset, Int64 amount);
src_offset
The offset (in characters) in the current instance, from which the data is read.
obj
An OracleClob
object that the data is copied to.
dst_offset
The offset (in characters) at which the OracleClob
object is copied to.
amount
The amount of data to be copied.
The return value is the amount copied.
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:
The OracleConnection
is not open or has been closed during the lifetime of the object.
The LOB object parameter has a different connection than the object.
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.
This instance method releases resources allocated by this object.
// C# public void Dispose();
IDisposable
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.
This instance method compares the LOB references.
// C#
public bool IsEqual(OracleBFile obj);
obj
The provided OracleBFile
object.
Returns true
if the current OracleBFile
and the provided OracleBFile
object refer to the same external LOB. Returns false
otherwise.
ObjectDisposedException
- The object is already disposed.
InvalidOperationException
- The OracleConnection
is not open or has been closed during the lifetime of the object.
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.
This instance method opens the BFILE
specified by the FileName
and DirectoryName
.
// C# public void OpenFile();
ObjectDisposedException
- The object is already disposed.
InvalidOperationException
- The OracleConnection
is not open or has been closed during the lifetime of the object.
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.
Overrides Stream
This instance method reads a specified amount of bytes from the OracleBFile
instance and populates the buffer
.
// C# public override int Read(byte[ ] buffer, int offset, int count);
buffer
The byte array buffer to be populated.
offset
The offset of the byte array buffer to be populated.
count
The amount of bytes to read.
The return value indicates the number of bytes read from the BFILE
, that is, the external LOB.
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
.
The LOB data is read starting from the position specified by the Position
property.
// Database Setup, if you have not done so yet. /* Log on as DBA (SYS or SYSTEM) that has CREATE ANY DIRECTORY privilege. CREATE OR REPLACE DIRECTORY MYDIR AS 'C:\TEMP'; */ // C# using System; using Oracle.DataAccess.Client; using Oracle.DataAccess.Types; class ReadSample { static void Main() { // Create MYDIR directory object as indicated previously and create a file // MyFile.txt with the text ABCDABC under C:\TEMP directory. // Note that the byte representation of the ABCDABC is 65666768656667 string constr = "User Id=scott;Password=tiger;Data Source=oracle"; OracleConnection con = new OracleConnection(constr); con.Open(); OracleBFile bFile = new OracleBFile(con, "MYDIR", "MyFile.txt"); // Open the OracleBFile bFile.OpenFile(); // Read 7 bytes into readBuffer, starting at buffer offset 0 byte[] readBuffer = new byte[7]; int bytesRead = bFile.Read(readBuffer, 0, 7); // Prints "bytesRead = 7" Console.WriteLine("bytesRead = " + bytesRead); // Prints "readBuffer = 65666768656667" Console.Write("readBuffer = "); for(int index = 0; index < readBuffer.Length; index++) { Console.Write(readBuffer[index]); } Console.WriteLine(); // Close the OracleBFile bFile.CloseFile(); bFile.Close(); bFile.Dispose(); con.Close(); con.Dispose(); } }
This instance method searches for a binary pattern in the current instance of an OracleBFile
.
// C# public int Search(byte[ ] val, Int64 offset, Int64 nth);
val
The binary pattern being searched for.
offset
The 0
-based offset (in bytes) starting from which the OracleBFile
is searched.
nth
The specific occurrence (1
-based) of the match for which the offset is returned.
Returns the absolute offset
of the start of the matched pattern (in bytes) for the nth
occurrence of the match. Otherwise, 0
is returned.
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
.
The limit of the search pattern is 16383 bytes.
// Database Setup, if you have not done so yet. /* Log on as DBA (SYS or SYSTEM) that has CREATE ANY DIRECTORY privilege. CREATE OR REPLACE DIRECTORY MYDIR AS 'C:\TEMP'; */ // C# using System; using Oracle.DataAccess.Client; using Oracle.DataAccess.Types; class SearchSample { static void Main() { // Create MYDIR directory object as indicated previously and create a file // MyFile.txt with the text ABCDABC under C:\TEMP directory. // Note that the byte representation of the ABCDABC is 65666768656667 string constr = "User Id=scott;Password=tiger;Data Source=oracle"; OracleConnection con = new OracleConnection(constr); con.Open(); OracleBFile bFile = new OracleBFile(con, "MYDIR", "MyFile.txt"); // Open the OracleBFile bFile.OpenFile(); // Search for the 2nd occurrence of a byte pattern {66,67} // starting from byte offset 1 in the OracleBFile byte[] pattern = new byte[2] {66, 67}; long posFound = bFile.Search(pattern, 1, 2); // Prints "posFound = 6" Console.WriteLine("posFound = " + posFound); // Close the OracleBFile bFile.CloseFile(); bFile.Close(); bFile.Dispose(); con.Close(); con.Dispose(); } }
Overrides Stream
This instance method sets the position on the current LOB stream.
// C# public override Int64 Seek(Int64 offset, SeekOrigin origin);
offset
A byte offset relative to origin.
origin
A value of type System.IO.SeekOrigin
indicating the reference point used to obtain the new position.
Returns an Int64
that indicates the position.
ObjectDisposedException
- The object is already disposed.
InvalidOperationException
- The OracleConnection
is not open or has been closed during the lifetime of the object.
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.
// Database Setup, if you have not done so yet. /* Log on as DBA (SYS or SYSTEM) that has CREATE ANY DIRECTORY privilege. CREATE OR REPLACE DIRECTORY MYDIR AS 'C:\TEMP'; */ // C# using System; using System.IO; using Oracle.DataAccess.Client; using Oracle.DataAccess.Types; class SeekSample { static void Main() { // Create MYDIR directory object as indicated previously and create a file // MyFile.txt with the text ABCDABC under C:\TEMP directory. // Note that the byte representation of the ABCDABC is 65666768656667 string constr = "User Id=scott;Password=tiger;Data Source=oracle"; OracleConnection con = new OracleConnection(constr); con.Open(); OracleBFile bFile = new OracleBFile(con, "MYDIR", "MyFile.txt"); // Open the OracleBFile bFile.OpenFile(); // Set the Position to 2 with respect to SeekOrigin.Begin long newPosition = bFile.Seek(2, SeekOrigin.Begin); // Prints "newPosition = 2" Console.WriteLine("newPosition = " + newPosition); // Prints "bFile.Position = 2" Console.WriteLine("bFile.Position = " + bFile.Position); // Read 2 bytes into readBuffer, starting at buffer offset 1 byte[] readBuffer = new byte[4]; int bytesRead = bFile.Read(readBuffer, 1, 2); // Prints "bytesRead = 2" Console.WriteLine("bytesRead = " + bytesRead); // Prints "readBuffer = 067680" Console.Write("readBuffer = "); for(int index = 0; index < readBuffer.Length; index++) { Console.Write(readBuffer[index]); } Console.WriteLine(); // Close the OracleBFile bFile.CloseFile(); bFile.Close(); bFile.Dispose(); con.Close(); con.Dispose(); } }