プライマリ・コンテンツに移動
Oracle® Data Provider for .NET開発者ガイド
ODAC 12.2c リリース1 (12.2.0.1) for Microsoft Windows
E88311-03
目次へ移動
目次
索引へ移動
索引

前
次

Read

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

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

宣言

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

パラメータ

  • buffer

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

  • offset

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

  • count

    読取りバイト数

戻り値

この戻り値は、BFILE、つまり外部LOBから読み取られるバイト数を示します。

例外

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

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

ArgumentOutOfRangeException - offsetまたはcountパラメータが0未満、offsetbuffer.Length以上、またはoffsetcountの合計がbuffer.Lengthより大きい場合のいずれか。

備考

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

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