Surendra:

The problem you are trying to solve is significantly more important than at first you might believe. Not only is the management of temporary files crucial in a production system (one that is expected to run for any significant length of time) but if you use the existing implementation of org.apache.commons.fileupload or org.apache.struts.upload (which itself uses the commons fileupload) the JVM will eventually core dump because java.io.File.deleteOnExit() leaks memory in the native heap (see http://developer.java.sun.com/developer/bugParade/bugs/4513817.html).

As you might have guessed by this time I've recently had to solve this very problem. I did so by subclassing ThresholdingOutputStream and providing an implementation of the thresholdReached() method that calls what is essentially File.createTempFile(...). In order to be able to assert my implementation of ThresholdingOutputStream I had to subclass DefaultFileItemFactory and provide an implementation of the createItem(...) method that returns my implementation of the FileItem interface. Of course, to be able to do all this I needed to make a couple minor "fixes" to the org.apache.commons.fileupload classes (please see http://nagoya.apache.org/bugzilla/show_bug.cgi?id=27477 for details).

Cheers,
        Forrest

On Mar 12, 2004, at 8:22 AM, [EMAIL PROTECTED] wrote:

Thanks Henry!

When you create a valid file handle, it actually does create a file which is
ready to be associted with the "OutputStream" and hence content can be
written.


For example:

//Creating File handle
File tempFile = File.createTempFile("test", ".txt"); //Here the actual file
is created in the file system


//Create DeferredFileOutputStream

DeferredFileOutputStream fos = new DeferredFileOutputStream(2048, tempFile);

//For example I write a byte[] lower than 2048 then content will stay in
memory ( for sake of the example
byte[] tempBytes = new String("TEST").getBytes();
fos.write(tempByte);
fos.flush();
fos.close()


//Now .. let us check if data is in memory
if (fos.isInMemory()) System.out.println("In memory");

//Now since file was created even though not used.. I still have to delete
this
tempFile.delete();



The second part of my question is "I would rather have file creation and
deletion does inside this class" by a method call. It should allow the
consumer to set (by method call) "location" where temp files to be created.


Hope this clearifies my question. Again, this is not a big issue but in
production systems temp file creation and deletion are crucial.

Thanks so much for your time!








-----Original Message----- From: Henri Yandell [mailto:[EMAIL PROTECTED] Sent: Friday, March 12, 2004 10:13 AM To: Jakarta Commons Users List Subject: Re: Common-io - DeferredOutputStream



new File(..) doesn't create an actual File, so I'm not sure why that's
such a bad thing?

I'm not really sure what the second half of your email means though. Can
you elaborate?


Hen

On Fri, 12 Mar 2004 [EMAIL PROTECTED] wrote:

This is a great class. However, it requires a File handle ( means I have
to
create a File before I used this) in the constructor which defeats the
purpose. Can the file creation ( based threshold ) and deletion is done
internally.


Regards,

Surendra





---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to