You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Brian Cook <bc...@printtime.com> on 2005/08/23 18:13:27 UTC

[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


Vasileios.Kantartzis@nc3a.nato.int 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.
bcook@printtime.com
913.345.8900