안드로이드에서 2.5mb (1087 파일 - * .html, * .css 및 * .db)의 .zip 파일을 압축 해제해야합니다. java.util.zip 사용, 잘 작동하지만 성능을 향상시켜야합니다. 마지막으로 1.10 분 동안 압축을 풀어야합니다.이 시간을 줄여야합니다. 예를 들어, 성능을 향상시키기 위해 나는 약간의 recomendations을 따랐다 :안드로이드에서 java.util.zip을 사용하는 것보다 빠른 방법으로 파일 압축 해제
- 사용 BufferedInputStream을, FileOutputStream에와의 BufferedOutputStream.
- 블록의 압축 읽어
바이트 데이터 [] = 새로운 바이트 [2048]; while (counter = bisMediaFile.read (data, 0, 2048))! = -1) { bosMediaFile.write (data, 0, counter); }
내 코드를 개선하는 방법이 있습니까? 예를 들어 나는 7ZipJBinding을 시도했지만, 안드로이드가 이것을 지원하지 않는 것처럼 보입니다. 왜냐하면 나는 sevenzipjbinding.jar와 sevenzipjbinding-AllPlatforms.jar를 참조했기 때문에 오류가 발생합니다 : "Native 7zipjbinding-AllPlatforms에서 감지 된 라이브러리 ". 7zip 홈페이지에는 MAC, Windows, Linux 용 버전이 있지만 안드로이드에 대해서는 아무 것도 보지 못했습니다. 다른 라이브러리에서 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();
}
}
시간을 소비하는 곳을 확인하려면 코드의 프로필을 작성해야합니다. 7zip 또는 Info-ZIP 압축 해제를 참조로 사용하여 합리적인 구현이 얼마나 빨리 수행되어야하는지 확인할 수 있습니다. –
1087은 많은 파일입니다. 문제가 될 수 있습니까? 또한, 더 큰 버퍼로 시도 했습니까? – bigstones
그래, 고마워, 내가 제안을 시도하고 내가 이것에 대해 논평 한 후에. 고맙습니다. – Jhon