tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Pid <...@pidster.com>
Subject Re: Tomcat 5.5 creates 0 byte files
Date Fri, 02 Jul 2010 08:52:42 GMT
On 02/07/2010 09:43, Murat Birben wrote:
> Hi all,
>=20
> I have a very simple file upload mechanism in java. I just take the fil=
e and
> save it on the server. I'm testing this simple code with selenium and *=
when
> a timeout occurs in the selenium test *tomcat creates 0 byte files unde=
r
> tomcat_home/work/Catalina/localhost/uploadServlet/ directory as MultiPa=
rt*
> files. It creates thousands of files, until there is no disk space left=
 on
> device. What may cause this problem? How can I solve this? Is there any=
one
> has an idea about this?

Thousands of 0 byte files are causing the disk to run out of space?


p

> My environment is: Ubuntu - 8.04 server, apache tomcat - 5.5.29, sun ja=
va
> 1.6
>=20
> Thanks,
>=20
> Here is the code snippet that i use
>=20
>         File fFile =3D null;
>         FileOutputStream fileOutputStream =3D null;
>         FileInputStream fileInputStream =3D null;
>         try {
>=20
>             String strFileName =3D request.getParameter("FileName");
>             String strPath =3D request.getParameter("Path");
>             //String strMediaType =3D request.getParameter("MediaType")=
;
>=20
>             //String strDescription =3D request.getParameter("Descripti=
on");
>             fFile =3D (File) request.getAttribute("Content");
>=20
>             int index =3D strPath.length() - 1; //If the user forgets t=
o
> put the last / for the path... We put it for him/her
>=20
>             if (strPath.charAt(index) !=3D '/') {
>                 strPath +=3D "/";
>             }
>             if (!new File(strPath).exists()) {
>                 new File(strPath).mkdirs();
>             }
>=20
>             File file =3D new File(strPath + strFileName);
>             fileOutputStream =3D new FileOutputStream(file);
>             fileInputStream =3D new FileInputStream(fFile);
>=20
>             byte[] bBuf =3D new byte[1024];
>=20
>             int iBufLen =3D 0;
>             int iReadLen =3D 1024;
>             int iTotelLen =3D 0;
>             /*read 1024 bytes at a time*/
>             while ((iBufLen =3D fileInputStream.read(bBuf)) !=3D -1) {
>=20
>                 fileOutputStream.write(bBuf);
>                 fileOutputStream.flush();
>                 iTotelLen +=3D iBufLen;
>                 if (fileInputStream.available() < iReadLen) {
>                     iReadLen =3D fileInputStream.available();
>=20
>                     break;
>                 }
>             }
>=20
>             byte[] tempbBuf =3D new byte[iReadLen];
>             fileInputStream.read(tempbBuf, 0, iReadLen);
>=20
>             fileOutputStream.write(tempbBuf);
>=20
>=20
>         } catch (IOException ex) {
>             ex.printStackTrace();
>         } finally {
>             fileOutputStream.close();
>             fileInputStream.close();
>=20
>             if (fFile.exists()) {
>=20
>                 fFile.delete();
>             }
>         }
>=20
>=20
>=20



Mime
View raw message