ZipInputStream / ZipOutputStream

ZipInputStream / ZipOutputStream - Java - Programmation

Marsh Posté le 07-01-2005 à 12:02:03    

Hi everybody,
 
I have to store some zipped data in a database and get them.
In entry, I have a byte array (byte[]).
I can zip my data, but not unzip it.
 
What I do :
 
To zip :

Code :
  1. byte[] ba = GetmyByteArray();
  2. /* => ba.length=182029 */
  3. ByteArrayOutputStream baos = new ByteArrayOutputStream();
  4. ZipOutputStream zos =new ZipOutputStream(baos);
  5. zos.setLevel(9);
  6. zos.setMethod(ZipOutputStream.DEFLATED);
  7. ZipEntry ze = new ZipEntry("toto" );
  8. ze.setSize(ba.length);
  9. zos.putNextEntry(ze);
  10. zos.write(ba);
  11. zos.closeEntry();
  12. zos.close();
  13. byte[] baZipped = baos.toByteArray();
  14. pstSTATEMENT.setBytes(i+1, baZipped);
  15. /* => baZipped.length = 179253 */


 
To UNZIP :

Code :
  1. Blob bResult = myResultSet.getBlob(iCOL);
  2. /* => The Blob has the good size (same as baZipped.length) */
  3. InputStream bais = bResult.getBinaryStream();
  4. ZipInputStream zipReader = new ZipInputStream(bais);
  5. ZipEntry ze = zipReader.getNextEntry();
  6. /* => ZipEntry has "toto" as name => OK */
  7. /* => ZipEntry has -1 as size and as compressedSize => beuh */
  8. int i = zipReader.read(buf) ;
  9. int i = zipReader.read(buf, 0, 182029);
  10. /* => both return 858 instead of 182029 */


 
I never get an uncompressed byte[] !!!
 
Please help !
Raphael.  

Reply

Marsh Posté le 07-01-2005 à 12:02:03   

Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed