0

When I using ZipOutputStream and ZipEntry to compress some files into one zip file, I found the Arabic Files Names were corrupted when I decompress the zip file, although the English files names are correct .

e.g. شركة انظمة الاتصالات والحلول الأمنية المحدودة

Instead of: بيان المشاريع السابقة

Java Version : 1.6

My code (Start point convertToZip) :

public void convertToZip(OAApplicationModule oaapplicationmodule,Number AuctionHeaderID)
  {
        OADBTransaction oadbtransaction = oaapplicationmodule.getOADBTransaction();
        OracleResultSet rsZippedEmptyBlob= PrepareNewZipProcess ( oadbtransaction , AuctionHeaderID) ;

        try
        {
            if ( !rsZippedEmptyBlob.next() )
            {
                return ;
            }
            OracleResultSet rLoopSourceBlob =  (OracleResultSet)GetBlobResultSetFromRFX ( oadbtransaction , AuctionHeaderID ) ;
            BLOB zippedEmptyBlob = rsZippedEmptyBlob.getBLOB(1);
            ZipOutputStream zosFinal = new ZipOutputStream ( zippedEmptyBlob.getBinaryOutputStream()); 
            zosFinal.setMethod(ZipOutputStream.DEFLATED); 
            byte[] bytesArrayFromSourceBlob = new byte[1024]; 
            while(rLoopSourceBlob.next())
            {
                BLOB sourceBlobFile = rLoopSourceBlob.getBLOB(1);     
                ZipEntry zippedSingleFileName = new ZipEntry( rLoopSourceBlob.getString(2)  ) ;
                zosFinal.putNextEntry(zippedSingleFileName);
                int lengthRead ;
                InputStream DocumentStream = sourceBlobFile.getBinaryStream();

                while((lengthRead=DocumentStream.read(bytesArrayFromSourceBlob))>=0) //>0
                    {       
                        zosFinal.write(bytesArrayFromSourceBlob,0,lengthRead);
                    }
                sourceBlobFile.getBinaryStream().close();
                zosFinal.closeEntry();
            }
            zosFinal.close();
            oadbtransaction.commit();
        }
        catch ( Exception ex )
        {
            throw OAException.wrapperException(ex);
        }

  }
Aboodz
  • 1,549
  • 12
  • 23

1 Answers1

0

This is a bug in JDK6. The same problem is produced on any non-ascii file name. To solve this issue you can try either:

  1. using JDK7 (b57) or higher
  2. or using a different zip library such as Apache Commons
Community
  • 1
  • 1
Aboodz
  • 1,549
  • 12
  • 23