Examples: write method
This agent demonstrates making an exact copy of a file using Stream. The agent associates one stream with an existing file and a second stream with a new file. The agent reads blocks of bytes from the first stream and writes them to the second stream until end of stream occurs on the first stream.
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();
}
}
}