i have a application for extract 7zip file i use this two lib for extract
compile 'org.apache.commons:commons-compress:1.12'
compile files('libs/xz-1.3.jar')
and this is my code
public void unzip() {
try {
File fc = new File(_location,"Driver2.7z");
System.out.println("file size"+fc.length());
//File fd = new File(_location,"Driver2.bin");
SevenZFile sevenZFile = new SevenZFile(fc);
SevenZArchiveEntry entry = sevenZFile.getNextEntry();
System.out.println( "Unzipping " );
while(entry!=null){
System.out.println(entry.getName());
FileOutputStream out = new FileOutputStream(_location + entry.getName());
//FileOutputStream out = new FileOutputStream(entry.getName());
System.out.println(entry.getName());
byte[] content = new byte[(int) entry.getSize()];
System.out.println(entry.getName());
sevenZFile.read(content, 0, content.length);
System.out.println(entry.getName());
out.write(content);
System.out.println(entry.getName());
out.close();
entry = sevenZFile.getNextEntry();
System.out.println(entry.getName());
}
sevenZFile.close();
Log.d("Unzip", "Unzipping complete. path : " +_location );
} catch(Exception e) {
System.out.println("Decompress"+ "unzip"+ e.getMessage());
}
}
with this code i get this error on some device
E/AndroidRuntime: FATAL EXCEPTION: Thread-218
Process: ir.milano.driver, PID: 30164
java.lang.OutOfMemoryError: Failed to allocate a 137881308 byte allocation with 4194304 free bytes and 129MB until OOM
at com.darkgamers.pepsiman.browser.mainmenu.DecompressFast.unzip(DecompressFast.java:38)
at ir.milano.driver.CopyFiles$1.run(CopyFiles.java:75)
the problem is this line
byte[] content = new byte[(int) entry.getSize()];