Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

file processing on the servlet --urgent--

 
Sandeep R A
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 13055
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 java.io.File.createTempFile() and related methods.
Bill
 
Gopal Shah
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Gopals.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic