2012-02-26 07:58:16 -05:00
|
|
|
|
2014-04-19 02:30:29 -04:00
|
|
|
package net.filebot.archive;
|
2012-02-26 07:58:16 -05:00
|
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.OutputStream;
|
|
|
|
|
|
|
|
import net.sf.sevenzipjbinding.ExtractAskMode;
|
|
|
|
import net.sf.sevenzipjbinding.ExtractOperationResult;
|
|
|
|
import net.sf.sevenzipjbinding.IArchiveExtractCallback;
|
|
|
|
import net.sf.sevenzipjbinding.ISequentialOutStream;
|
2015-10-16 12:44:54 -04:00
|
|
|
import net.sf.sevenzipjbinding.IInArchive;
|
2012-02-26 07:58:16 -05:00
|
|
|
import net.sf.sevenzipjbinding.PropID;
|
|
|
|
import net.sf.sevenzipjbinding.SevenZipException;
|
|
|
|
|
|
|
|
|
|
|
|
class ExtractCallback implements IArchiveExtractCallback {
|
2015-07-25 18:47:19 -04:00
|
|
|
|
2015-10-16 12:44:54 -04:00
|
|
|
private IInArchive inArchive;
|
2012-02-26 07:58:16 -05:00
|
|
|
private ExtractOutProvider extractOut;
|
2015-07-25 18:47:19 -04:00
|
|
|
|
2012-02-26 07:58:16 -05:00
|
|
|
private ExtractOutStream output = null;
|
2015-07-25 18:47:19 -04:00
|
|
|
|
|
|
|
|
2015-10-16 12:44:54 -04:00
|
|
|
public ExtractCallback(IInArchive inArchive, ExtractOutProvider extractOut) {
|
2012-02-26 07:58:16 -05:00
|
|
|
this.inArchive = inArchive;
|
|
|
|
this.extractOut = extractOut;
|
|
|
|
}
|
2015-07-25 18:47:19 -04:00
|
|
|
|
|
|
|
|
|
|
|
@Override
|
2012-02-26 07:58:16 -05:00
|
|
|
public ISequentialOutStream getStream(int index, ExtractAskMode extractAskMode) throws SevenZipException {
|
|
|
|
if (extractAskMode != ExtractAskMode.EXTRACT) {
|
|
|
|
return null;
|
|
|
|
}
|
2015-07-25 18:47:19 -04:00
|
|
|
|
2012-02-26 07:58:16 -05:00
|
|
|
boolean isFolder = (Boolean) inArchive.getProperty(index, PropID.IS_FOLDER);
|
|
|
|
if (isFolder) {
|
|
|
|
return null;
|
|
|
|
}
|
2015-07-25 18:47:19 -04:00
|
|
|
|
2012-02-26 07:58:16 -05:00
|
|
|
String path = (String) inArchive.getProperty(index, PropID.PATH);
|
|
|
|
try {
|
|
|
|
OutputStream target = extractOut.getStream(new File(path));
|
|
|
|
if (target == null) {
|
|
|
|
return null;
|
|
|
|
}
|
2015-07-25 18:47:19 -04:00
|
|
|
|
2012-02-26 07:58:16 -05:00
|
|
|
output = new ExtractOutStream(target);
|
|
|
|
return output;
|
|
|
|
} catch (IOException e) {
|
|
|
|
throw new SevenZipException(e);
|
|
|
|
}
|
|
|
|
}
|
2015-07-25 18:47:19 -04:00
|
|
|
|
|
|
|
|
|
|
|
@Override
|
2012-02-26 07:58:16 -05:00
|
|
|
public void prepareOperation(ExtractAskMode extractAskMode) throws SevenZipException {
|
|
|
|
}
|
2015-07-25 18:47:19 -04:00
|
|
|
|
|
|
|
|
|
|
|
@Override
|
2012-02-26 07:58:16 -05:00
|
|
|
public void setOperationResult(ExtractOperationResult extractOperationResult) throws SevenZipException {
|
|
|
|
if (output != null) {
|
|
|
|
try {
|
|
|
|
output.close();
|
|
|
|
} catch (IOException e) {
|
|
|
|
throw new SevenZipException(e);
|
|
|
|
} finally {
|
|
|
|
output = null;
|
|
|
|
}
|
|
|
|
}
|
2015-07-25 18:47:19 -04:00
|
|
|
|
2012-02-26 07:58:16 -05:00
|
|
|
if (extractOperationResult != ExtractOperationResult.OK) {
|
|
|
|
throw new SevenZipException("Extraction Error: " + extractOperationResult);
|
|
|
|
}
|
|
|
|
}
|
2015-07-25 18:47:19 -04:00
|
|
|
|
|
|
|
|
|
|
|
@Override
|
2012-02-26 07:58:16 -05:00
|
|
|
public void setCompleted(long completeValue) throws SevenZipException {
|
|
|
|
}
|
2015-07-25 18:47:19 -04:00
|
|
|
|
|
|
|
|
|
|
|
@Override
|
2012-02-26 07:58:16 -05:00
|
|
|
public void setTotal(long total) throws SevenZipException {
|
|
|
|
}
|
2015-07-25 18:47:19 -04:00
|
|
|
|
2012-02-26 07:58:16 -05:00
|
|
|
}
|