1
XZ Java 라이브러리를 사용하여 크기가 약 16MB 인 Android에서 .xz
파일을 추출합니다. 추출/압축 풀기 코드를 AsyncTask
으로 실행 중이므로 onProgressUpdate(Integer ... values)
메서드를 통해 추출의 백분율을보고 싶습니다.android의 XZ Java 추출 비율 얻기
내 압축 풀기 코드는 다음과 유사합니다.
byte[] buf = new byte[8192];
String name = null;
try {
name = "my_archive.xz";
InputStream in = getResources().openRawResource(R.raw.my_archive);//new FileInputStream(name); //
FileOutputStream out = openFileOutput("my_archive.sqlite", Context.MODE_PRIVATE);
label = (TextView)findViewById(R.id.textLabel);
try {
in = new XZInputStream(in);
label.setText("Writing db file.");
int size;
while ((size = in.read(buf)) != -1) {
out.write(buf,0,size);
progress++;
publishProgress(progress);
}
}
catch (Exception e)
{
System.err.println("Input Stream error: "+e.getMessage());
}
finally {
// Close FileInputStream (directly or indirectly
// via LZMAInputStream, it doesn't matter).
in.close();
}
} catch (FileNotFoundException e) {
System.err.println("LZMADecDemo: Cannot open " + name + ": "
+ e.getMessage());
System.exit(1);
} catch (EOFException e) {
System.err.println("LZMADecDemo: Unexpected end of input on "
+ name);
System.exit(1);
} catch (IOException e) {
System.err.println("LZMADecDemo: Error decompressing from "
+ name + ": " + e.getMessage());
System.exit(1);
}
변수 progress
은 실제로 백분율 값을 보유해야합니다. 누구든지이 라이브러리를 사용하고 있으며 진행률을 계산할 수있는 쉬운 방법을 찾으면 여기에서 나를 도와주세요.
도움을 미리 감사드립니다.