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
Solved

Files and Streams

Posted on 2004-08-09
5
363 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
  • 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
java jdbc batch example 8 41
CSV file parsing thru Java 13 34
Html Table Looping (part 2) 5 27
restrict decimal places for double datatype 10 19
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

861 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