Java Zip help


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Java Zip help

  1. #1
    Join Date
    Sep 2004
    Posts
    223

    Java Zip help

    Hello,

    Currently I have a table in an Oracle database that has a BLOB column which stores Zip files.

    I.e. in the web app, it creates a temp zip file of files, then inserts that zip file into the DB.

    I want to be able to read that zip file into a ZipInputStream, which I CAN do, but when I read the ZipEntry's of that zip using, I can get the size of each ZipEntry (the getSize() method of the ZipEntry returns -1).

    Does any one know why this may be?

    I have checked the zip file by using a download feature we have, and the zip file is NOT corrupted, so thats not it.

    Maybe it cant read them because Im reading it in from a blob???

    Who knows!

    Thanks for any help, i really need to get around this




    Here is some code:

    Code:
    Blob zipBlob = getWpMemoService().getWPAttachmentBlob(workItem.getAttachmentId(), false);
        ZipInputStream zis = null;
        ArrayList attachmentsForms;
        try {
          if (zipBlob != null)
          {
            zis = new ZipInputStream(zipBlob.getBinaryStream());
            attachmentsForms = new ArrayList();
      
            ZipEntry entry = null;
            while ((entry = zis.getNextEntry()) != null) {
              try
              {
                AttachmentForm af = new AttachmentForm();
                af.setAttachmentName(entry.getName());
                af.setAttachmentSize(entry.getSize());
                af.setContentType(FileUtil.getSimpleFileContentType(entry.getName()));
                af.setSelected(true);
                
                attachmentsForms.add(af);
              }
              finally{
                zis.closeEntry();
              }
            }
            modifyForm.getAttachmentsFormManager().setAttachmentForms(attachmentsForms);
          }
        } catch (SQLException e) {
          handleException(request, mapping, e);
        } finally {
          if (zis != null)
            zis.close();
        }
    A kram a day keeps the doctor......guessing

  2. #2
    Join Date
    Aug 2007
    Posts
    5
    "ZipEntry.getSize()" returns -1 only when it doesn't know that how much data is available. It doesn't means that data is NOT Available.
    Do it another way: -
    1. Read all the Data from a BLOB stream into a BYTE array and then create a ZipInputStream object. Something like this: -

    Code:
    Blob zipBlob = getWpMemoService().getWPAttachmentBlob(workItem.getAttachmentId(), false);
    ZipInputStream zipInpStream = new ZipInputStream( new BufferedInputStream(
            new ByteArrayInputStream( readBytes(zipBlob) ) ) );
    
    	//put here rest of the code
    
    
    private byte[] readBytes(Blob zipBlob){
    //Write the code of reading bytes from a BLOB and return it as an byte Array. 
    //Change the below code as per your Convenience.
     byte[] zipByteArr = blob.getBytes (  1,  ( int )  ( blob.length (  )  )  ) ; 
    
    return zipByteArr;
    }

  3. #3
    Join Date
    Sep 2004
    Posts
    223
    Yeah I did know that it still could read data, I just wanted to be able to get the size of the attachment without reading the whole thing into memory.

    We have a lot of attachments in some cases and they can be quite large, so I'm hesitant to read the bytes into memory.

    Thanks for the help so far!
    A kram a day keeps the doctor......guessing

Similar Threads

  1. Java book
    By Lou in forum Java
    Replies: 9
    Last Post: 09-19-2007, 06:58 AM
  2. Java vs. .Net. A questionnaire
    By Basil in forum .NET
    Replies: 1
    Last Post: 05-13-2005, 07:46 AM
  3. DevX does seem one sideded
    By Rob Abbe in forum Talk to the Editors
    Replies: 44
    Last Post: 01-13-2003, 03:57 PM
  4. Re: VB vs. Visual Age for Java
    By JJ in forum Enterprise
    Replies: 1
    Last Post: 07-06-2000, 05:50 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center