This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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
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
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.