FileOutputStream resets the file

K

kuhan

We are running an File Upload application on solaris. The applet is
used as client. When user selects a file the file is divided into 3
Meg chunks and sent to the server where the chunks are collected and
re create the original file. We are passing the original file size and
total number of chunks and current index of the chunk in the request.
On server side for the first request we create in write mode and for
following requests we create in append mode. But some times we notice
the file size on server side is not same as the original file size
although all the chunks have been received.

When we debug further we found at some point the file size on server
side after appending getting reset to zero.

This is the code:

if (curRequest.equals("1")) {
FileOutputStream out = new
FileOutputStream(fileFullPath,false);
out.write(buf);
out.close();
}
else {
//For the subsequent requests create the file in
append mode
FileOutputStream out = new
FileOutputStream(fileFullPath,true);
out.write(buf);
out.close();
}
curFileSize = new Long(new File(fileFullPath).length());
System.out.println("UPLOAD - current total bytes uploaded:
" + curFileSize);


fileFullPath is the file in the server side.

The output we are getting:

UPLOAD - curFileName: The Corner DVD 2.sit:16of126
UPLOAD - original file size: 385954067
UPLOAD - size of actual chunk: 3072000
UPLOAD - current total bytes uploaded: 49152000
UPLOAD - curFileName: The Corner DVD 2.sit:17of126
UPLOAD - original file size: 385954067
UPLOAD - size of actual chunk: 3072000
UPLOAD - current total bytes uploaded: 52224000
UPLOAD - curFileName: The Corner DVD 2.sit:18of126
UPLOAD - original file size: 385954067
UPLOAD - size of actual chunk: 3072000
UPLOAD - current total bytes uploaded: 55296000
UPLOAD - curFileName: The Corner DVD 2.sit:19of126
UPLOAD - original file size: 385954067
UPLOAD - size of actual chunk: 3072000
UPLOAD - current total bytes uploaded: 58368000
UPLOAD - curFileName: The Corner DVD 2.sit:20of126
UPLOAD - original file size: 385954067
UPLOAD - size of actual chunk: 3072000
UPLOAD - current total bytes uploaded: 3072000 (The count is rest
here)
UPLOAD - curFileName: The Corner DVD 2.sit:21of126
UPLOAD - original file size: 385954067
UPLOAD - size of actual chunk: 3072000
UPLOAD - current total bytes uploaded: 6144000


It continue fine after this.

Can some body help me to point the direction I should look to solve
the problem?

Any known issues with FileOutputStream (I am using JDK1.4)

Thanks
kuhan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top