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.

[321 byte] By [fortyseconda] at [2007-10-3 5:00:41]
# 1
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.
paulcwa at 2007-7-14 23:06:13 > top of Java-index,Java Essentials,Java Programming...
# 2
The PDF-library will let me write to an outputstream, I'm just unsure how to use that to create a FileDataSource or some other class that will allow me to attach it to an email.
fortyseconda at 2007-7-14 23:06:13 > top of Java-index,Java Essentials,Java Programming...
# 3
FileDataSource seems to have a getOutputStream method. Can you use that?
paulcwa at 2007-7-14 23:06:13 > top of Java-index,Java Essentials,Java Programming...
# 4
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.
paulcwa at 2007-7-14 23:06:13 > top of Java-index,Java Essentials,Java Programming...
# 5
Unfortunately getting the outputstream doesn't do me any good, I need to find a way to get it to take the stream instead of a file. I think implementing DataSource may ben an option though.Thanks for your suggestion.
fortyseconda at 2007-7-14 23:06:13 > top of Java-index,Java Essentials,Java Programming...
# 6
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.
DrClapa at 2007-7-14 23:06:13 > top of Java-index,Java Essentials,Java Programming...
# 7
Thanks,It's working perfectly!Message was edited by: fortysecond
fortyseconda at 2007-7-14 23:06:13 > top of Java-index,Java Essentials,Java Programming...