You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by Nicolas De Loof <ni...@cgey.com> on 2003/05/27 10:42:32 UTC

FileUpload of a _large_ file

Hi all

I use struts nightly build 2003 05 25 on tomcat 4.1.24 (win2k)

I've got some errors with FileUpload.

As I think it is the latest stuts dependency to stabilize before RC2, I send this mail on struts-dev list. I send a copy
to Martin Cooper as beeing author of o.a.c.filupload.DeferedFileOutputStream.

When I upload little files (less than 10 Ko) all works fine.

When I upload one "large" file (370 Ko) I get a NullPointerException.


I think there is a bug on DeferedFileOutputStream, here is what I discovered using debugger :

on init ThresholdingOutputStream.thresold = 262144. (don't know where it comes from)

When uploaded datas size exceed thresold, DeferedFileOutputStream
thresholdReached() method is called to write datas into a temp File.
Here is the method body :

protected void thresholdReached() throws IOException
{
    byte[] data = memoryOutputStream.toByteArray();
    FileOutputStream fos = new FileOutputStream(outputFile);
    fos.write(data);
    diskOutputStream = fos;
    currentOutputStream = fos;
    memoryOutputStream = null;
}

On next call to this method, memoryOutputStream is null and NullPointerException occurs on first line.

If I understand well how DeferedFileOutputStream works, next data should be directly written into temp file, so
thresholdReached() should not be called anymore.
(memoryOutputStream == null) or (diskOutputStream  != null) or
(currentOutputStream == diskOutputStream) should be used as a flag to know that direct write to disk is in use :

protected void thresholdReached() throws IOException
{
    if (currentOutputStream == diskOutputStream) {
        // We allready write directly to disk
        return;
    }
    byte[] data = memoryOutputStream.toByteArray();
    FileOutputStream fos = new FileOutputStream(outputFile);
    fos.write(data);
    diskOutputStream = fos;
    currentOutputStream = fos;
    memoryOutputStream = null;
}



Hope my poor english is not so bag you didn't understand anything about this ...

Nico.


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-dev-help@jakarta.apache.org


Nightly build problem? (was Re: FileUpload of a _large_ file)

Posted by Martin Cooper <ma...@apache.org>.

On Tue, 27 May 2003, Nicolas De Loof wrote:

> I made some test using commons-fileupload-1.0-dev.jar (nightly build 20030525) downloaded from
> http://cvs.apache.org/builds/jakarta-commons/nightly/commons-fileupload/
>
> With that fileUpload version all works fine
> (and I just understood the usage of ThresholdingOutputStream.thresholdExceeded)

Yes, that was fixed not too long ago.

BTW, the ThresholdingOutputStream might land somewhere else in the longer
term, since it's pretty handy outside of FileUpload too. But not before
FileUpload 1.0 goes out the door.

>
> I thought struts "nightly build" was built with latest "nightly build" commons. Did I miss something ?

Hmm, it's certainly supposed to be. If that's not happening, then there
might be a problem with the build script. That's Craig's bailiwick, since
it's in his house. Craig, any ideas?

--
Martin Cooper


>
> Nico.
>
>
>
>
> > Hi all
> >
> > I use struts nightly build 2003 05 25 on tomcat 4.1.24 (win2k)
> >
> > I've got some errors with FileUpload.
> >
> > As I think it is the latest stuts dependency to stabilize before RC2, I send this mail on struts-dev list. I send a
> copy
> > to Martin Cooper as beeing author of o.a.c.filupload.DeferedFileOutputStream.
> >
> > When I upload little files (less than 10 Ko) all works fine.
> >
> > When I upload one "large" file (370 Ko) I get a NullPointerException.
> >
> >
> > I think there is a bug on DeferedFileOutputStream, here is what I discovered using debugger :
> >
> > on init ThresholdingOutputStream.thresold = 262144. (don't know where it comes from)
> >
> > When uploaded datas size exceed thresold, DeferedFileOutputStream
> > thresholdReached() method is called to write datas into a temp File.
> > Here is the method body :
> >
> > protected void thresholdReached() throws IOException
> > {
> >     byte[] data = memoryOutputStream.toByteArray();
> >     FileOutputStream fos = new FileOutputStream(outputFile);
> >     fos.write(data);
> >     diskOutputStream = fos;
> >     currentOutputStream = fos;
> >     memoryOutputStream = null;
> > }
> >
> > On next call to this method, memoryOutputStream is null and NullPointerException occurs on first line.
> >
> > If I understand well how DeferedFileOutputStream works, next data should be directly written into temp file, so
> > thresholdReached() should not be called anymore.
> > (memoryOutputStream == null) or (diskOutputStream  != null) or
> > (currentOutputStream == diskOutputStream) should be used as a flag to know that direct write to disk is in use :
> >
> > protected void thresholdReached() throws IOException
> > {
> >     if (currentOutputStream == diskOutputStream) {
> >         // We allready write directly to disk
> >         return;
> >     }
> >     byte[] data = memoryOutputStream.toByteArray();
> >     FileOutputStream fos = new FileOutputStream(outputFile);
> >     fos.write(data);
> >     diskOutputStream = fos;
> >     currentOutputStream = fos;
> >     memoryOutputStream = null;
> > }
> >
> >
> >
> > Hope my poor english is not so bag you didn't understand anything about this ...
> >
> > Nico.
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: struts-dev-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: struts-dev-help@jakarta.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-dev-help@jakarta.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-dev-help@jakarta.apache.org


Re: FileUpload of a _large_ file

Posted by Nicolas De Loof <ni...@cgey.com>.
I made some test using commons-fileupload-1.0-dev.jar (nightly build 20030525) downloaded from
http://cvs.apache.org/builds/jakarta-commons/nightly/commons-fileupload/

With that fileUpload version all works fine
(and I just understood the usage of ThresholdingOutputStream.thresholdExceeded)

I thought struts "nightly build" was built with latest "nightly build" commons. Did I miss something ?

Nico.




> Hi all
>
> I use struts nightly build 2003 05 25 on tomcat 4.1.24 (win2k)
>
> I've got some errors with FileUpload.
>
> As I think it is the latest stuts dependency to stabilize before RC2, I send this mail on struts-dev list. I send a
copy
> to Martin Cooper as beeing author of o.a.c.filupload.DeferedFileOutputStream.
>
> When I upload little files (less than 10 Ko) all works fine.
>
> When I upload one "large" file (370 Ko) I get a NullPointerException.
>
>
> I think there is a bug on DeferedFileOutputStream, here is what I discovered using debugger :
>
> on init ThresholdingOutputStream.thresold = 262144. (don't know where it comes from)
>
> When uploaded datas size exceed thresold, DeferedFileOutputStream
> thresholdReached() method is called to write datas into a temp File.
> Here is the method body :
>
> protected void thresholdReached() throws IOException
> {
>     byte[] data = memoryOutputStream.toByteArray();
>     FileOutputStream fos = new FileOutputStream(outputFile);
>     fos.write(data);
>     diskOutputStream = fos;
>     currentOutputStream = fos;
>     memoryOutputStream = null;
> }
>
> On next call to this method, memoryOutputStream is null and NullPointerException occurs on first line.
>
> If I understand well how DeferedFileOutputStream works, next data should be directly written into temp file, so
> thresholdReached() should not be called anymore.
> (memoryOutputStream == null) or (diskOutputStream  != null) or
> (currentOutputStream == diskOutputStream) should be used as a flag to know that direct write to disk is in use :
>
> protected void thresholdReached() throws IOException
> {
>     if (currentOutputStream == diskOutputStream) {
>         // We allready write directly to disk
>         return;
>     }
>     byte[] data = memoryOutputStream.toByteArray();
>     FileOutputStream fos = new FileOutputStream(outputFile);
>     fos.write(data);
>     diskOutputStream = fos;
>     currentOutputStream = fos;
>     memoryOutputStream = null;
> }
>
>
>
> Hope my poor english is not so bag you didn't understand anything about this ...
>
> Nico.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-dev-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-dev-help@jakarta.apache.org