日本語PDF

Read

Streamをオーバーライドします

このインスタンス・メソッドでは、ODP.NET LOBインスタンスから指定バイト数を読み取り、bufferに移入します。

宣言

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

パラメータ

  • buffer

    移入されるバイト配列バッファ

  • offset

    バッファに移入される開始オフセット(バイト)

  • count

    読取りバイト数

戻り値

戻り値はLOBから読み取られるバイト数を示します。

例外

ObjectDisposedException - オブジェクトはすでに処理されています。

InvalidOperationException - OracleConnectionがオープンされていないか、またはオブジェクトの存続中にクローズされています。

ArgumentOutOfRangeException - この例外は次のいずれかの条件が存在する場合に表示されます。

  • offsetまたはcountパラメータが0未満の場合

  • offsetbuffer.Length以上である場合

  • offsetおよびcountの合計がbuffer.Lengthより大きい場合

備考

LOBデータの読取りは、Positionプロパティにより指定された位置から開始されます。

// 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();
  }
}