Oracle® Data Provider for .NET開発者ガイド ODAC 12.2c リリース1 (12.2.0.1) for Microsoft Windows E88311-03 |
|
![]() 前 |
![]() 次 |
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(); } }