Buffering a file
Hi,
I wish to create a pdf and email it in the same program. I can do both, but to create the pdf I need to create a File. This is restricted on the server I'm running. I was wondering if anybody had any suggestions on how to buffer a File without needing an actual file in storage.
Thanks in advance.
Maybe your system provides access to a /tmp directory, or there's a virtual disk you can use.But are you absolutely sure that your PDF-creation library won't let you write the PDF to a stream, rather than just a file? Recheck the API.
Alternatively, you could create an object implementing DataSource, and whose job is to encapsulate the PDF.This seems like such a common problem though I'd expect there to be a DataHandler for PDFs available already.
Sounds like you are talking about JavaMail, which does have a ByteArrayDataSource. (Either standard in JavaMail 1.4 or in the demo directory as an example before that.) And you can output your PDF to a ByteArrayOutputStream. Put the two together and you're done.