Oracle® Data Provider for .NET Developer's Guide 11g Release 2 (11.2.0.2) Part Number E18754-01 |
|
|
PDF · Mobi · ePub |
An OracleBlob
object is an object that has a reference to BLOB
data. It provides methods for performing operations on BLOB
s.
System.Object
System.MarshalByRefObject
System.IO.Stream
Oracle.DataAccess.Types.OracleBlob
// C# public sealed class OracleBlob : Stream, ICloneable, INullable
All public static methods are thread-safe, although instance methods do not guarantee thread safety.
// C# using System; using Oracle.DataAccess.Client; using Oracle.DataAccess.Types; class OracleBlobSample { static void Main() { string constr = "User Id=scott;Password=tiger;Data Source=oracle"; OracleConnection con = new OracleConnection(constr); con.Open(); OracleBlob blob = new OracleBlob(con); // Write 4 bytes from writeBuffer, starting at buffer offset 0 byte[] writeBuffer = new byte[4] {1, 2, 3, 4}; blob.Write(writeBuffer, 0, 4); // Append first 2 bytes from writeBuffer {1, 2} to the oracleBlob blob.Append(writeBuffer, 0, 2); // Prints "blob.Length = 6" Console.WriteLine("blob.Length = " + blob.Length); // Reset the Position for the Read blob.Position = 0; // Read 6 bytes into readBuffer, starting at buffer offset 0 byte[] readBuffer = new byte[6]; int bytesRead = blob.Read(readBuffer, 0, 6); // Prints "bytesRead = 6" Console.WriteLine("bytesRead = " + bytesRead); // Prints "readBuffer = 123412" 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 '12' // starting from byte offset 0 in the OracleBlob byte[] pattern = new byte[2] {1, 2}; long posFound = blob.Search(pattern, 0, 2); // Prints "posFound = 5" Console.WriteLine("posFound = " + posFound); // Erase 4 bytes of data starting at byte offset 1 // Sets bytes to zero blob.Erase(1, 4); byte[] erasedBuffer = blob.Value; //Prints "erasedBuffer = 100002" Console.Write("erasedBuffer = "); for(int index = 0; index < erasedBuffer.Length; index++) { Console.Write(erasedBuffer[index]); } Console.WriteLine(); blob.Close(); blob.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:
OracleBlob
members are listed in the following tables.
OracleBlob
constructors are listed in Table 13-10.
Table 13-10 OracleBlob Constructors
Constructor | Description |
---|---|
Creates an instance of the |
OracleBlob
static fields are listed in Table 13-11.
Table 13-11 OracleBlob Static Fields
Field | Description |
---|---|
Holds the maximum number of bytes a |
|
Represents a null value that can be assigned to the value of an |
OracleBlob
static methods are listed in Table 13-12.
Table 13-12 OracleBlob Static Methods
Methods | Description |
---|---|
|
Inherited from |
OracleBlob Instance Properties
OracleBlob
instance properties are listed in Table 13-13.
Table 13-13 OracleBlob Instance Properties
Properties | Description |
---|---|
Indicates whether or not the LOB stream can be read |
|
Indicates whether or not forward and backward seek operations be performed |
|
Indicates whether or not the LOB object supports writing |
|
Indicates the |
|
Indicates whether the |
|
Indicates whether or not the |
|
Indicates whether or not the current instance has a null value |
|
Indicates whether or not the current instance is bound to a temporary |
|
Indicates the size of the |
|
Indicates the optimal data buffer length (or multiples thereof) that read and write operations should use to improve performance |
|
Indicates the current read or write position in the LOB stream |
|
Returns the data, starting from the first byte in |
OracleBlob
instance methods are listed in Table 13-14.
Table 13-14 OracleBlob Instance Methods
Methods | Description |
---|---|
Appends the supplied data to the current |
|
Opens the |
|
|
Inherited from |
|
Inherited from |
Creates a copy of an |
|
Closes the current stream and releases any resources associated with it |
|
Compares data referenced by the current instance and that of the supplied object |
|
Copies from the current |
|
|
Inherited from |
Releases resources allocated by this |
|
Closes the |
|
|
Inherited from |
|
Inherited from |
|
Inherited from |
Erases data (Overloaded) |
|
|
Not supported |
|
Inherited from |
|
Inherited from |
|
Inherited from |
|
Inherited from |
Compares the LOB data referenced by the two |
|
Reads a specified amount of bytes from the ODP.NET LOB Type instance and populates the |
|
|
Inherited from |
Searches for a binary pattern in the current instance of an |
|
Sets the position in the current LOB stream |
|
Trims or truncates the |
|
|
Inherited from |
Writes the supplied buffer into the |
|
|
Inherited from |
OracleBlob
constructors are listed in Table 13-10.
This constructor creates an instance of the OracleBlob
class bound to a temporary BLOB
with an OracleConnection
object.
OracleBlob(OracleConnection, bool)
This constructor creates an instance of the OracleBlob
class bound to a temporary BLOB
with an OracleConnection
object and a boolean value for caching.
This constructor creates an instance of the OracleBlob
class bound to a temporary BLOB
with an OracleConnection
object.
// C#
public OracleBlob(OracleConnection con);
con
The OracleConnection
object.
InvalidOperationException
- The OracleConnection
is not opened.
The connection must be opened explicitly by the application. OracleBlob
does not open the connection implicitly.
The temporary BLOB
utilizes the provided connection to store BLOB
data. Caching is not turned on by this constructor.
This constructor creates an instance of the OracleBlob
class bound to a temporary BLOB
with an OracleConnection
object and a boolean value for caching.
// C# public OracleBlob(OracleConnection con, bool bCaching);
con
The OracleConnection
object.
bCaching
A flag for enabling or disabling server-side caching.
InvalidOperationException
- The OracleConnection
is not opened.
The connection must be opened explicitly by the application. OracleBlob
does not open the connection implicitly.
The temporary BLOB
uses the provided connection to store BLOB
data. The bCaching
input parameter determines whether or not server-side caching is used.
OracleBlob
static fields are listed in Table 13-15.
Table 13-15 OracleBlob Static Fields
Field | Description |
---|---|
Holds the maximum number of bytes a |
|
Represents a null value that can be assigned to the value of an |
The MaxSize
field holds the maximum number of bytes a BLOB
can hold, which is 4,294,967,295 (2^32 - 1) bytes.
// C# public static readonly Int64 MaxSize = 4294967295;
This field can be 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 OracleBlob
instance.
// C# public static readonly OracleBlob Null;
OracleBlob
static methods are listed in Table 13-16.
Table 13-16 OracleBlob Static Methods
Methods | Description |
---|---|
|
Inherited from |
OracleBlob
instance properties are listed in Table 13-17.
Table 13-17 OracleBlob Instance Properties
Properties | Description |
---|---|
Indicates whether or not the LOB stream can be read |
|
Indicates whether or not forward and backward seek operations be performed |
|
Indicates whether or not the LOB object supports writing |
|
Indicates the |
|
Indicates whether the |
|
Indicates whether or not the |
|
Indicates whether or not the current instance has a null value |
|
Indicates whether or not the current instance is bound to a temporary |
|
Indicates the size of the |
|
Indicates the optimal data buffer length (or multiples thereof) that read and write operations should use to improve performance |
|
Indicates the current read or write 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;}
If the LOB stream can be written, returns true
; otherwise, returns false
.
This instance property indicates the OracleConnection
that is used to retrieve and write BLOB
data.
// C# public OracleConnection Connection {get;}
An object of OracleConnection
.
ObjectDisposedException
- The object is already disposed.
This instance property indicates whether the BLOB
is empty or not.
// C# public bool IsEmpty {get;}
A bool
that indicates whether or not the BLOB
is empty.
ObjectDisposedException
- The object is already disposed.
This instance property indicates whether or not the BLOB
has been opened to defer index updates.
// C# public bool IsInChunkWriteMode{get;}
If the BLOB
has been opened, returns true
; otherwise, returns false
.
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 or not the current instance is bound to a temporary BLOB
.
// C# public bool IsTemporary {get;}
bool
Overrides Stream
This instance property indicates the size of the BLOB
data in bytes.
// C# public override Int64 Length {get;}
A number indicating the size of the BLOB
data in bytes.
ObjectDisposedException
- The object is already disposed.
InvalidOperationException
- The OracleConnection
is not open or has been closed during the lifetime of the object.
This instance property indicates the optimal data buffer length (or multiples thereof) that read and write operations should use to improve performance.
// C# public int OptimumChunkSize{get;}
A number representing the minimum bytes to retrieve or send.
ObjectDisposedException
- The object is already disposed.
Overrides Stream
This instance property indicates the current read or write position in the LOB stream.
// C# public override Int64 Position{get; set;}
An Int64
that indicates the read or write 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 Position
is less than 0
.
This instance property returns the data, starting from the first byte in the BLOB
, 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.
ArgumentOutOfRangeException
- The Value
is less than 0
.
The value of Position
is not used or changed by using this property. 2 GB is the maximum byte array length that can be returned by this property.
OracleBlob
instance methods are listed in Table 13-18.
Table 13-18 OracleBlob Instance Methods
Methods | Description |
---|---|
Appends the supplied data to the current |
|
Opens the |
|
|
Inherited from |
|
Inherited from |
Creates a copy of an |
|
Closes the current stream and releases any resources associated with it |
|
Compares data referenced by the current instance and that of the supplied object |
|
Copies from the current |
|
|
Inherited from |
Releases resources allocated by this |
|
Closes the |
|
|
Inherited from |
|
Inherited from |
|
Inherited from |
Erases data (Overloaded) |
|
|
Not supported |
|
Inherited from |
|
Inherited from |
|
Inherited from |
|
Inherited from |
Compares the LOB data referenced by the two |
|
Reads a specified amount of bytes from the ODP.NET LOB Type instance and populates the |
|
|
Inherited from |
Searches for a binary pattern in the current instance of an |
|
Sets the position in the current LOB stream |
|
Trims or truncates the |
|
|
Inherited from |
Writes the supplied buffer into the |
|
|
Inherited from |
Append
appends the supplied data to the end of the current OracleBlob
instance.
This instance method appends the BLOB
data referenced by the provided OracleBlob
object to the current OracleBlob
instance.
This instance method appends data from the supplied byte array buffer to the end of the current OracleBlob
instance.
This instance method appends the BLOB
data referenced by the provided OracleBlob
object to the current OracleBlob
instance.
// C#
public void Append(OracleBlob obj);
obj
An object of OracleBlob
.
ObjectDisposedException
- The object is already disposed.
InvalidOperationException
- The parameter has a different connection than the object, OracleConnection
is not opened, or OracleConnection
has been reopened.
No character set conversions are made.
The provided object and the current instance must be using the same connection; that is, the same OracleConnection
object.
This instance method appends data from the supplied byte array buffer to the end of the current OracleBlob
instance.
// C# public void Append(byte[] buffer, int offset, int count);
buffer
An array of bytes.
offset
The zero-based byte offset in the buffer from which data is read.
count
The number of bytes to be appended.
ObjectDisposedException
- The object is already disposed.
InvalidOperationException
- The OracleConnection
is not open or has been closed during the lifetime of the object.
// C# using System; using Oracle.DataAccess.Client; using Oracle.DataAccess.Types; class AppendSample { static void Main() { string constr = "User Id=scott;Password=tiger;Data Source=oracle"; OracleConnection con = new OracleConnection(constr); con.Open(); OracleBlob blob = new OracleBlob(con); // Append 2 bytes {4, 5} to the OracleBlob byte[] buffer = new byte[3] {4, 5, 6}; blob.Append(buffer, 0, 2); byte[] appendBuffer = blob.Value; // Prints "appendBuffer = 45" Console.Write("appendBuffer = "); for(int index = 0; index < appendBuffer.Length; index++) { Console.Write(appendBuffer[index]); } Console.WriteLine(); blob.Close(); blob.Dispose(); con.Close(); con.Dispose(); } }
This instance method opens the BLOB
.
// C# public void BeginChunkWrite();
ObjectDisposedException
- The object is already disposed.
InvalidOperationException
- The OracleConnection
is not open or has been closed during the lifetime of the object.
BeginChunkWrite
does not need to be called before manipulating the BLOB data. This is provided for performance reasons.
After this method is called, write operations do not cause the domain or function-based index on the column to be updated. Index updates occur only once after EndChunkWrite
is called.
This instance method creates a copy of an OracleBlob
object.
// C# public object Clone();
An OracleBlob
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.
// C# using System; using Oracle.DataAccess.Client; using Oracle.DataAccess.Types; class CloneSample { static void Main() { string constr = "User Id=scott;Password=tiger;Data Source=oracle"; OracleConnection con = new OracleConnection(constr); con.Open(); OracleBlob blob1 = new OracleBlob(con); // Prints "blob1.Position = 0" Console.WriteLine("blob1.Position = " + blob1.Position); // Set the Position before calling Clone() blob1.Position = 1; // Clone the OracleBlob OracleBlob blob2 = (OracleBlob)blob1.Clone(); // Prints "blob2.Position = 1" Console.WriteLine("blob2.Position = " + blob2.Position); blob1.Close(); blob1.Dispose(); blob2.Close(); blob2.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();
This instance method compares data referenced by the current instance and that of the supplied object.
// C# public int Compare(Int64 src_offset, OracleBlob obj, Int64 dst_offset, Int64 amount);
src_offset
The comparison starting point (in bytes) for the current instance.
obj
The provided OracleBlob
object.
dst_offset
The comparison starting point (in bytes) for the provided OracleBlob
.
amount
The number of bytes to compare.
Returns a value that is:
Less than zero: if the data referenced by the current instance is less than that of the supplied instance
Zero: if both objects reference the same data
Greater than zero: if the data referenced by the current instance is greater than that of the supplied instance
ObjectDisposedException
- The object is already disposed.
InvalidOperationException
- The parameter has a different connection than the object, OracleConnection
is not opened, or OracleConnection
has been reopened.
ArgumentOutOfRangeException
- The src_offset
, the dst_offset
, or the amount
parameter is less than 0
.
The provided object and the current instance must be using the same connection, that is, the same OracleConnection
object.
CopyTo
copies data from the current instance to the provided OracleBlob
object.
This instance method copies data from the current instance to the provided OracleBlob
object.
This instance method copies data from the current OracleBlob
instance to the provided OracleBlob
object with the specified destination offset.
CopyTo(Int64, OracleBlob, Int64, Int64)
This instance method copies data from the current OracleBlob
instance to the provided OracleBlob
object with the specified source offset, destination offset, and character amounts.
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 OracleBlob
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 OracleBlob
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
The OracleBlob
object to which the data is copied.
dst_offset
The offset (in bytes) at 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.
InvalidOperationException
- The parameter has a different connection than the object, OracleConnection
is not opened, or OracleConnection
has been reopened.
ArgumentOutOfRangeException
- The src_offset
, the dst_offset
, or the amount
parameter is less than 0
.
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.
// C# using System; using Oracle.DataAccess.Client; using Oracle.DataAccess.Types; class CopyToSample { static void Main() { string constr = "User Id=scott;Password=tiger;Data Source=oracle"; OracleConnection con = new OracleConnection(constr); con.Open(); OracleBlob blob1 = new OracleBlob(con); OracleBlob blob2 = new OracleBlob(con); // Write 4 bytes, starting at buffer offset 0 byte[] buffer = new byte[4] {1, 2, 3, 4}; blob1.Write(buffer, 0, 4); // Copy 2 bytes from byte 0 of blob1 to byte 1 of blob2 blob1.CopyTo(0, blob2, 1, 2); byte[] copyBuffer = blob2.Value; //Prints "Value = 012" Console.Write("Value = "); for(int index = 0; index < copyBuffer.Length; index++) { Console.Write(copyBuffer[index]); } Console.WriteLine(); blob1.Close(); blob1.Dispose(); blob2.Close(); blob2.Dispose(); con.Close(); con.Dispose(); } }
This instance method releases resources allocated by this object.
// C# public void Dispose();
IDisposable
Once Dispose()
is called, the object of OracleBlob
is in an uninitialized state.
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 closes the BLOB
referenced by the current OracleBlob
instance.
// C# public void EndChunkWrite();
ObjectDisposedException
- The object is already disposed.
InvalidOperationException
- The OracleConnection
is not open or has been closed during the lifetime of the object.
Index updates occur immediately if there is write operation(s) deferred by the BeginChunkWrite
method.
Erase
erases a portion or all data.
This instance method erases all data.
This instance method erases a specified portion of data.
This instance method erases all data.
// C# public Int64 Erase();
The number of bytes erased.
Erase()
replaces all data with zero-byte fillers.
This instance method erases a specified portion of data.
// C# public Int64 Erase(Int64 offset, Int64 amount);
offset
The offset from which to erase.
amount
The quantity (in bytes) to erase.
The number of bytes erased.
ObjectDisposedException
- The object is already disposed.
InvalidOperationException
- The OracleConnection
is not open or has been closed during the lifetime of the object.
ArgumentOutOfRangeException
- The offset
or amount
parameter is less than 0
.
Replaces the specified amount
of data with zero-byte fillers.
This instance method compares the LOB data referenced by the two OracleBlob
s.
// C#
public bool IsEqual(OracleBlob obj);
obj
An OracleBlob
object.
If the current OracleBlob
and the provided OracleBlob
refer to the same LOB, returns true
. 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 OracleBlob
objects return false
for == or Equals()
because two different OracleBlob
instances can refer to the same LOB.
The provided object and the current instance must be using the same connection, that is, the same OracleConnection
object.
Overrides Stream
This instance method reads a specified amount of bytes from the ODP.NET LOB 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 starting offset (in bytes) at which the buffer is populated.
count
The amount of bytes to read.
The return value indicates the number of bytes read from the LOB.
ObjectDisposedException
- The object is already disposed.
InvalidOperationException
- The OracleConnection
is not open or has been closed during the lifetime of the object.
ArgumentOutOfRangeException
- This exception is thrown if any of the following conditions exist:
The offset
or the count
parameter is less than 0
.
The offset
is greater than or equal to the buffer
.Length
.
The offset
and the count
together are greater than the buffer
.Length
.
The LOB data is read starting from the position specified by the Position
property.
// C# using System; using Oracle.DataAccess.Client; using Oracle.DataAccess.Types; class ReadSample { static void Main() { string constr = "User Id=scott;Password=tiger;Data Source=oracle"; OracleConnection con = new OracleConnection(constr); con.Open(); OracleBlob blob = new OracleBlob(con); // Write 3 bytes, starting at buffer offset 1 byte[] writeBuffer = new byte[4] {1, 2, 3, 4}; blob.Write(writeBuffer, 1, 3); // Reset the Position for Read blob.Position = 1; // Read 2 bytes into buffer starting at buffer offset 1 byte[] readBuffer = new byte[4]; int bytesRead = blob.Read(readBuffer, 1, 2); // Prints "bytesRead = 2" Console.WriteLine("bytesRead = " + bytesRead); // Prints "readBuffer = 0340" Console.Write("readBuffer = "); for(int index = 0; index < readBuffer.Length; index++) { Console.Write(readBuffer[index]); } Console.WriteLine(); blob.Close(); blob.Dispose(); con.Close(); con.Dispose(); } }
This instance method searches for a binary pattern in the current instance of an OracleBlob
.
// C# public Int64 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 OracleBlob
is searched.
nth
The specific occurrence (1-based) of the match for which the absolute offset (in bytes) 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
- This exception is thrown if any of the following conditions exist:
The offset
is less than 0
.
The nth
is less than or equal to 0
.
The val
.Length
is greater than 16383
.
The nth
is greater than or equal to OracleBlob.MaxSize
.
The offset
is greater than or equal to OracleBlob.MaxSize
.
The limit of the search pattern is 16383 bytes.
// C# using System; using Oracle.DataAccess.Client; using Oracle.DataAccess.Types; class SearchSample { static void Main() { string constr = "User Id=scott;Password=tiger;Data Source=oracle"; OracleConnection con = new OracleConnection(constr); con.Open(); OracleBlob blob = new OracleBlob(con); // Write 7 bytes, starting at buffer offset 0 byte[] buffer = new byte[7] {1, 2, 3, 4, 1, 2, 3}; blob.Write(buffer, 0, 7); // Search for the 2nd occurrence of a byte pattern '23' // starting at offset 1 in the OracleBlob byte[] pattern = new byte[2] {2 ,3}; long posFound = blob.Search(pattern, 1, 2); // Prints "posFound = 6" Console.WriteLine("posFound = " + posFound); blob.Close(); blob.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 Int64
for 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.
Overrides Stream
This instance method trims or truncates the BLOB
value to the specified length (in bytes).
// C#
public override void SetLength(Int64 newlen);
newlen
The desired length of the current stream in bytes.
ObjectDisposedException
- The object is already disposed.
InvalidOperationException
- The OracleConnection
is not open or has been closed during the lifetime of the object.
ArgumentOutOfRangeException
- The newlen
parameter is less than 0
.
Overrides Stream
This instance method writes the supplied buffer into the OracleBlob
.
// C# public override void Write(byte[ ] buffer, int offset, int count);
buffer
The byte array buffer
that provides the data.
offset
The 0
-based offset (in bytes) from which the buffer
is read.
count
The amount of data (in bytes) that is to be written into the OracleBlob
.
ObjectDisposedException
- The object is already disposed.
InvalidOperationException
- The OracleConnection
is not open or has been closed during the lifetime of the object.
ArgumentOutOfRangeException
- This exception is thrown if any of the following conditions exist:
The offset
or the count
is less than 0
.
The offset
is greater than or equal to the buffer
.Length
.
The offset
and the count
together are greater than buffer
.Length
.
Destination offset
in the OracleBlob
can be specified by the Position
property.
// C# using System; using Oracle.DataAccess.Client; using Oracle.DataAccess.Types; class WriteSample { static void Main() { string constr = "User Id=scott;Password=tiger;Data Source=oracle"; OracleConnection con = new OracleConnection(constr); con.Open(); OracleBlob blob = new OracleBlob(con); // Set the Position for the Write blob.Position = 0; // Begin ChunkWrite to improve performance // Index updates occur only once after EndChunkWrite blob.BeginChunkWrite(); // Write to the OracleBlob in 5 chunks of 2 bytes each byte[] b = new byte[2] {1, 2}; for(int index = 0; index < 5; index++) { blob.Write(b, 0, b.Length); } blob.EndChunkWrite(); byte[] chunkBuffer = blob.Value; // Prints "chunkBuffer = 1212121212" Console.Write("chunkBuffer = "); for(int index = 0; index < chunkBuffer.Length; index++) { Console.Write(chunkBuffer[index]); } Console.WriteLine(); blob.Close(); blob.Dispose(); con.Close(); con.Dispose(); } }