This may be a pure Java question rather than a Notes question, but here goes: Using various examples in the documentation as a guide more than any deep understanding of the language, I’m trying to cobble together a Java agent which will create a Notes document, create a PDF file (using iText), and attach the file to the document. Using a FileOutputStream to generate the PDF works just fine; the file appears at the root of my C: drive as expected. The problem appears when I try to convert that more or less directly into a Stream object. One of the examples in the Notes help uses OutputStreamWriter as an intermediate object as I’ve attempted to do here, but the Stream object doesn’t end up with any contents. If I use the open method of the Stream class, I can go to the file on disk and bring it into the Notes document, but my ultimate goal is to try to do this all in memory without ever having to write anything to disk. Is this possible, and if so, what am I doing wrong? The current state of the code is below (minus imports, encompassing try/catch blocks and the like; the agent compiles and runs without error, it’s just the Stream never gets any content).
Database db = agentContext.getCurrentDatabase();
lotus.domino.Document doc = db.createDocument();
doc.appendItemValue(“Form”, “Basic”);
FileOutputStream fos = new FileOutputStream(“C:/bar.pdf”);
Document document = new Document();
PdfWriter.getInstance(document, fos);
Stream outStream = session.createStream();
document.open();
document.add(new Paragraph(“Hello world!”));
MIMEEntity entity = doc.createMIMEEntity( “RTF” );
document.close();
OutputStreamWriter osw = new OutputStreamWriter(fos);
// This next line may be the problem.
// outStream.getBytes() always ends up being 0
outStream.getContents(osw);
if (outStream.getBytes() != 0) {
entity.setContentFromBytes(outStream, "application/pdf", entity.ENC_BASE64);
}
else {
pw.println("No content");
}
doc.save(true, true);