File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes file processing on the servlet  --urgent-- Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "file processing on the servlet  --urgent--" Watch "file processing on the servlet  --urgent--" New topic

file processing on the servlet --urgent--

Sandeep R A

Joined: Feb 19, 2004
Posts: 1
hi.. i am building a servlet to read files sent by users using the http post method.. is there a way i can read and manipulate the file on the server without having to store it any place.. in short i wish to have an object instance of the file on the servlet which i can pass around to other servlets or applications to do diff types of processing on them
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13036
If you receive the data into a byte[] or char[], you can create a ByteArrayInputStream or CharReader - If your other Java code is designed to read from one of these streams instead of being locked into requiring a file, you could avoid creating a file..
However, you might be better off using Java's temporary file capability - see and related methods.
Gopal Shah
Ranch Hand

Joined: May 17, 2003
Posts: 65
U can have the object stored in a common place, namely ServletContext. This will enable u to share the object between threads.
But then u have to make sure that this object is thread safe becoz if u use the setAttribute() nethod with a constant key, the Server will crash. Instead use a unique key (say e.g. hashCode of the object) and pass on this key as value in Request object.
Alternatively, u could pass on the data object using Request object. But if the size of the data object is considerable, then it will affect the performance of the Server on the whole.
I agree. Here's the link:
subject: file processing on the servlet --urgent--
It's not a secret anymore!