JAVA/CORBA クラス


例:read メソッド
次のエージェントは、Stream を使用したファイルの正確なコピーの作成を示します。このエージェントは、1 つのストリームを既存のファイルに関連付け、2 つ目のストリームを新規ファイルに関連付けます。このエージェントは、第 1 ストリームからバイトのブロックを読み込み、第 1 ブロックのストリームの終わりが発生するまで第 2 ストリームに書き込みます。

import lotus.domino.*;

public class JavaAgent extends AgentBase {

public void NotesMain() {

try {
Session session = getSession();
AgentContext agentContext = session.getAgentContext();

// (Your code goes here)
String inPath = "c:\\StreamFiles\\domobj.tlb";
String outPath = "c:\\StreamFiles\\domobjcopy.tlb";

// Get the input file
Stream inStream = session.createStream();
if (inStream.open(inPath, "binary")) {
if (inStream.getBytes() > 0) {
// Get the output file
Stream outStream = session.createStream();
if (outStream.open(outPath, "binary")) {
if (outStream.getBytes() == 0) {
// Transfer input file to output file
do {
byte[] buffer = inStream.read(32767);
outStream.write(buffer);
} while (!inStream.isEOS());
inStream.close();
outStream.close();
}
else
System.out.println("Output file exists and has content");
}
else
System.out.println("Output file open failed");
}
else
System.out.println("Input file has no content");
}
else
System.out.println("Input file open failed");

} catch(NotesException e) {
e.printStackTrace();

} catch(Exception e) {
e.printStackTrace();
}
}
}

関連項目