Extracting attachments from lotus notes api using

2019-07-07 01:56发布

I am trying to extract attachments using EmbeddedObjects, I am able to extract attachments but create em*tm temp files in system temp folder.

 EmbeddedObject embeddedObject=document.getAttachment(attachmentName);
 InputStream inputStream=embeddedObject.getInputStream();
 .....
 ......
 inputStream.close();
 embeddedObject..recycle();
 document..recycle();

After closing input Stream its not deleting temp file form system temp folder. Is it any thing wrong in my code or its setting issue with lotus notes.

Can you please help me in this?

Thanks for the help.

2条回答
我欲成王,谁敢阻挡
2楼-- · 2019-07-07 02:00

My suggestion would be to first comment out all the code that you represented in your post as

.....
......

Does the temp file still get left behind? If so, it looks like it's a bug in the Notes back end classes for 8.x that needs to be reported to IBM.

If not, then something in the commented-out code is preventing the the close() call from succeeding. InputStream is an abstract class, so perhaps you are binding inputStream to another type of stream object that must be closed in order to prevent the file from staying open.

查看更多
老娘就宠你
3楼-- · 2019-07-07 02:06

This is a common issue, and it relates to the incorrect closure/recycle of objects (either missing or out of sequence). E0*TM files will be created while the objects are alive and cleaned up when recycled.

If they are correct then check to see if any Antivirus software running that is blocking deletion.

The following sample code I used to test this before works, so compare to yours.

  try { 

   System.out.println("Start"); 
   String path = "test.txt";    

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

   System.out.println("Get DB");    
   Database db = session.getCurrentDatabase();  

   System.out.println("View + doc");    
   View vw = db.getView("main");    
   Document doc = vw.getFirstDocument();    

   System.out.println("Embedded object");   
   EmbeddedObject att = doc.getAttachment(path);    
   InputStream is = att.getInputStream();   
   ByteArrayOutputStream fos = new ByteArrayOutputStream(); 

   byte buffer[] = new byte[(int) att.getFileSize()];   
   int read;    
   do { 
    read = is.read(buffer, 0, buffer.length);   
    if (read > 0) { 
     fos.write(buffer, 0, read);    
    }   
   } while (read > -1); 

   fos.close(); 
   is.close();

   // recycle the domino variables  
   doc.recycle();   
   vw.recycle();    
   db.recycle();    
   att.recycle();   

  } catch (Exception e) {   
   e.printStackTrace(); 
  }
查看更多
登录 后发表回答