file upload and unzip

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

file upload and unzip

Vasileios.Kantartzis
Dear all

I would like to get your input again on the subject of handling an
uploaded zip file in tomcat

I have tried to follow some suggestions from the list with no luck so
far ( I still get the same results).

I am trying to upload the file into tomcat and use the .getInput stream
from the FileItem  to handle the file.

The following methods decompress the zipped content into a file space on
my server.

The result I am getting baxk from tomcat is that it cannot handle the
zip file because some file stream is still open.

As far as I have checked in my code there are no open streams left. Is
it possible that some stream is pending from the upload libs?

 

Thanks for your time

And help in advanced

 

public void decompress(String destFolder, String file, InputStream
inputStream) throws IOException {
 
  ZipInputStream zis=new ZipInputStream(inputStream);
  ZipFile zf=new ZipFile(this.getFile());
     
     
     ZipEntry ze;
  while(( ze=zis.getNextEntry())!=null){
  //ZipEntry ze = zf.getEntry(file.getName());
   //System.out.println ("unzipping: " +ze.getName());
    this.processEntry(ze,destFolder,inputStream);
  }
 
 }

 

synchronized void processEntry( ZipEntry ze,String destFolder,
InputStream ins)throws IOException
  {
       
//  get zip entry
         
//  get an input stream for the entry
     
      //and an output stream
      File outFile = new File(destFolder+"/"+ze.getName());
     
      FileOutputStream fos = new FileOutputStream(outFile);
//        
      int bread;
//  transfer buffer
      byte[] bin = new byte[4096];            

      //loop through reading the zipped file entry and
      // write it to the external file
      //System.out.println("writing output to
"+outFile.getAbsolutePath());
      while ( (bread = ins.read(bin, 0, 4096)) > -1) {
        fos.write(bin, 0, bread);
      }

      ins.close();
      fos.close();
    }
 

Reply | Threaded
Open this post in threaded view
|

[Upload] Re: file upload and unzip

Brian Cook

You will have better luck getting responses to your posts if you follow
the guild lines at :

http://jakarta.apache.org/site/mail.html


[hidden email] wrote:

> Dear all
>
> I would like to get your input again on the subject of handling an
> uploaded zip file in tomcat
>
> I have tried to follow some suggestions from the list with no luck so
> far ( I still get the same results).
>
> I am trying to upload the file into tomcat and use the .getInput stream
> from the FileItem  to handle the file.
>
> The following methods decompress the zipped content into a file space on
> my server.
>
> The result I am getting baxk from tomcat is that it cannot handle the
> zip file because some file stream is still open.
>
> As far as I have checked in my code there are no open streams left. Is
> it possible that some stream is pending from the upload libs?
>
>  
>
> Thanks for your time
>
> And help in advanced
>
>  
>
> public void decompress(String destFolder, String file, InputStream
> inputStream) throws IOException {
>  
>   ZipInputStream zis=new ZipInputStream(inputStream);
>   ZipFile zf=new ZipFile(this.getFile());
>      
>      
>      ZipEntry ze;
>   while(( ze=zis.getNextEntry())!=null){
>   //ZipEntry ze = zf.getEntry(file.getName());
>    //System.out.println ("unzipping: " +ze.getName());
>     this.processEntry(ze,destFolder,inputStream);
>   }
>  
>  }
>
>  
>
> synchronized void processEntry( ZipEntry ze,String destFolder,
> InputStream ins)throws IOException
>   {
>        
> //  get zip entry
>          
> //  get an input stream for the entry
>      
>       //and an output stream
>       File outFile = new File(destFolder+"/"+ze.getName());
>      
>       FileOutputStream fos = new FileOutputStream(outFile);
> //        
>       int bread;
> //  transfer buffer
>       byte[] bin = new byte[4096];            
>
>       //loop through reading the zipped file entry and
>       // write it to the external file
>       //System.out.println("writing output to
> "+outFile.getAbsolutePath());
>       while ( (bread = ins.read(bin, 0, 4096)) > -1) {
>         fos.write(bin, 0, bread);
>       }
>
>       ins.close();
>       fos.close();
>     }
>  
>
>

--
Brian Cook
Digital Services Analyst
Print Time Inc.
[hidden email]
913.345.8900


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]
Reply | Threaded
Open this post in threaded view
|

RE: [Upload] Re: file upload and unzip

Vasileios.Kantartzis
In reply to this post by Vasileios.Kantartzis
Thanks for the reply


-----Original Message-----
From: Brian Cook [mailto:[hidden email]]
Sent: 23 August 2005 18:13
To: Jakarta Commons Users List
Subject: [Upload] Re: file upload and unzip


You will have better luck getting responses to your posts if you follow
the guild lines at :

http://jakarta.apache.org/site/mail.html


[hidden email] wrote:
> Dear all
>
> I would like to get your input again on the subject of handling an
> uploaded zip file in tomcat
>
> I have tried to follow some suggestions from the list with no luck so
> far ( I still get the same results).
>
> I am trying to upload the file into tomcat and use the .getInput
stream
> from the FileItem  to handle the file.
>
> The following methods decompress the zipped content into a file space
on

> my server.
>
> The result I am getting baxk from tomcat is that it cannot handle the
> zip file because some file stream is still open.
>
> As far as I have checked in my code there are no open streams left. Is
> it possible that some stream is pending from the upload libs?
>
>  
>
> Thanks for your time
>
> And help in advanced
>
>  
>
> public void decompress(String destFolder, String file, InputStream
> inputStream) throws IOException {
>  
>   ZipInputStream zis=new ZipInputStream(inputStream);
>   ZipFile zf=new ZipFile(this.getFile());
>      
>      
>      ZipEntry ze;
>   while(( ze=zis.getNextEntry())!=null){
>   //ZipEntry ze = zf.getEntry(file.getName());
>    //System.out.println ("unzipping: " +ze.getName());
>     this.processEntry(ze,destFolder,inputStream);
>   }
>  
>  }
>
>  
>
> synchronized void processEntry( ZipEntry ze,String destFolder,
> InputStream ins)throws IOException
>   {
>        
> //  get zip entry
>          
> //  get an input stream for the entry
>      
>       //and an output stream
>       File outFile = new File(destFolder+"/"+ze.getName());
>      
>       FileOutputStream fos = new FileOutputStream(outFile);
> //        
>       int bread;
> //  transfer buffer
>       byte[] bin = new byte[4096];            
>
>       //loop through reading the zipped file entry and
>       // write it to the external file
>       //System.out.println("writing output to
> "+outFile.getAbsolutePath());
>       while ( (bread = ins.read(bin, 0, 4096)) > -1) {
>         fos.write(bin, 0, bread);
>       }
>
>       ins.close();
>       fos.close();
>     }
>  
>
>


--
Brian Cook
Digital Services Analyst
Print Time Inc.
[hidden email]
913.345.8900


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]