6

Androidで2.5mbの.zipファイル(1087ファイル-* .html、* .cssおよび* .db)を解凍する必要があります。java.util.zipを使用しましたが、正常に動作しますが、パフォーマンスを改善する必要があります。解凍プロセスは最後の 1.10 分です。この時間を短縮する必要があります。パフォーマンスを改善するためのいくつかの推奨事項に従いました。たとえば、次のとおりです。

  • BufferedInputStream、FileOutputStream、BufferedOutputStream を使用します。
  • zip をブロック単位で読む:

バイトデータ[] = 新しいバイト[2048]; while ((counter = bisMediaFile.read(data, 0, 2048)) != -1) { bosMediaFile.write(data, 0, counter); }

私のコードを改善する方法はありますか?. プログラムで使用するサード パーティの zip プログラムを検索していました。 Sevenzipjbinding-AllPlatforms で検出されたライブラリ」。7zip のホームページには、MAC、Windows、Linux 用のバージョンがありますが、Android については何も表示されませんでした。Androidでファイルを解凍するための他のライブラリをお勧めできますか?

これは私のすべてのコードです:

public static void processZipFile(String strBinaryPath,String strExtractPath, String strDestinationDBPath) throws Exception
{
    ZipFile zipInFile = null;
    try
    {
        if (strExtractPath != null)
        {
            zipInFile = new ZipFile(strBinaryPath);
            for (Enumeration<? extends ZipEntry> entries = zipInFile.entries(); entries.hasMoreElements();)
            {
                ZipEntry zipMediaEntry = entries.nextElement();
                if (zipMediaEntry.isDirectory())
                {
                    File mediaDir = new File(String.format("%s\\%s", strExtractPath, zipMediaEntry.getName()));
                    mediaDir.mkdirs();
                }
                else
                {
                        BufferedInputStream bisMediaFile = null;
                        FileOutputStream fosMediaFile = null; 
                        BufferedOutputStream bosMediaFile = null;
                        try
                        {
                                String strFileName = String.format("%s\\%s", strExtractPath, zipMediaEntry.getName());
                                File uncompressDir = new File(strFileName).getParentFile();
                                uncompressDir.mkdirs();

                                //if is a database file, extract to other path : android.movinginteractive.com/databases
                                if(strFileName.contains(".db"))
                                    strFileName = String.format("%s\\%s", strDestinationDBPath, ExtractDBName(zipMediaEntry.getName()));

                                bisMediaFile = new BufferedInputStream(zipInFile.getInputStream(zipMediaEntry));
                                fosMediaFile = new FileOutputStream(strFileName);
                                bosMediaFile = new BufferedOutputStream(fosMediaFile);

                                int counter;
                                byte data[] = new byte[2048];

                                while ((counter = bisMediaFile.read(data, 0, 2048)) != -1) 
                                {
                                    bosMediaFile.write(data, 0, counter);
                                }
                        }
                        catch (Exception ex)
                        {
                            throw ex;
                        }
                        finally
                        {
                            if (bosMediaFile != null)
                            {
                                bosMediaFile.flush();
                                bosMediaFile.close();
                            }
                            if (bisMediaFile != null)
                                bisMediaFile.close();
                        }
                }
            }


        }
    }
    catch (Exception ex)
    {
        throw ex;
    }
    finally
    {
        if (zipInFile != null)
            zipInFile.close();
        File flZipToDelete = new File(strBinaryPath);
        if(flZipToDelete.exists())
            flZipToDelete.delete();

    }
}
4

1 に答える 1

0

ファイルを解凍するためのCまたはC++コードスニペットを見つけて、AndroidNDKで実行できると確信しています。とはいえ、どのようなパフォーマンスの向上が得られるかはわかりません。

于 2011-02-17T09:26:21.837 に答える