In this post I explain how to get a resource, for example an image, from a java agent even if this file is not saved on the file system.
The agent is tested in lotus client 8.5.x.
-
- Create a java agent
-
- Edit the class JavaAgent:
import lotus.domino.*; import java.awt.image.BufferedImage; import java.io.ByteArrayInputStream; import java.io.File; import java.io.InputStream; import javax.imageio.ImageIO; import org.apache.commons.io.IOUtils; public class JavaAgent extends AgentBase { public void NotesMain() { try { Session session = getSession(); AgentContext agentContext = session.getAgentContext(); // (Your code goes here) // first example: from image resource to bytes // you need org.apache.commons.io.IOUtils InputStream is = getClass().getClassLoader().getResourceAsStream("myPicture.jpg"); byte[] bytes = IOUtils.toByteArray(is); // second example: from image resource to file InputStream in = (ByteArrayInputStream)getClass().getClassLoader().getResourceAsStream("myPicture.jpg"); BufferedImage img = ImageIO.read(in); ImageIO.write(img, "jpg", new File("c:\\myPicture.jpg")); } catch(Exception e) { e.printStackTrace(); } }
- Edit the class JavaAgent:
In the first example the image is converted to bytes (you need to import org.apache.commons.io.IOUtils and to import the relative .jar file under Archive)
In the second example the image is saved on the disk.
Leave a Reply