Solved

Files and Streams

Posted on 2004-08-09
5
373 Views
Last Modified: 2010-03-31
Question -

A method used AnyMethod(java.io.File , java.io.File ) signature
I have InputStream and string of the data in the file as I  create them on the fly and there is no "file" in the server.
How do I pass the InputStream/string to the method with the above signature.

Context
I am using FOP and it uses xml and fo .
To emberd itin a servelt and convert to PDF it uses

 XSLTInputHandler inputHandler = new XSLTInputHandler(xmlFile, xslFile);

where the xmlFile, xslFile are java.io.File, I have the XML and XSL as InputStreams / strings in my servers memory as they are generated dynamically, how to pass them

Thx
0
Comment
Question by:applekanna
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 35

Expert Comment

by:girionis
ID: 11750452
Create a file from this input stream:

FileOutputStream fos = new FileOutputStream(new File("myfile.pdf"));
// get the bytes from the input stream
fos.write(<bytes>);
fos.flush();
fos.close();

Then use this file (myfile.pdf) to pass it in the method.
0
 
LVL 3

Author Comment

by:applekanna
ID: 11750518
FileOutputStream fos = new FileOutputStream(new File("myfile.pdf"));

1. when I do something like this , would not I run into concurrency issues in the servlet because of the file name, so to make it use I need to give each file a unique file name (say system time - any other ideas)

2. Also I need to keep deleting the files to take care of memory issues.

I am currently doing the above both

Out of curiosity
Is this the only way ...or is there any other method
0
 
LVL 35

Accepted Solution

by:
girionis earned 100 total points
ID: 11750545
1. It depends if the FileOutputStream is an instance variable or not. If it is you can always synchronize it.

2. Delete them from disk first and then setting them to null would be enough for memory.

I am not sure if there is any other way, it might be though. If the method accepts two parameters of type "File" then you either need to pass a File or a subclass of it. It would be easier if you could change the method's signature and make it an Object so you can either pass a File or an InputStream (and check inside your method for the type of Object passed).
0
 
LVL 3

Author Comment

by:applekanna
ID: 11750613
Thx for ur comments
0
 
LVL 35

Expert Comment

by:girionis
ID: 11750648
Thank you for accepting, glad I was of help :)
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question