日本語PDF

Seek

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

このインスタンス・メソッドでは現行のLOBストリームに位置を設定します。

宣言

// C#
public override Int64 Seek(Int64 offset, SeekOrigin origin);

パラメータ

  • offset

    起点に相対的なバイト・オフセット

  • origin

    新規位置を取得する場合に使用する参照ポイントを示すタイプSystem.IO.SeekOriginの値

戻り値

位置を示すInt64が戻されます。

例外

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

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

備考

offsetが負の場合は、新規位置がoffsetによって指定されたバイト数だけ、originで指定した位置より前にあります。

offsetがゼロの場合は、originで指定した位置が新規位置となります。

offsetが正の場合は、新規位置がoffsetによって指定されたバイト数だけ、originで指定した位置より後にあります。

SeekOrigin.Beginはストリームの開始を指定します。

SeekOrigin.Currentはストリーム内の現行位置を指定します。

SeekOrigin.Endはストリームの終点を指定します。

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