1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-11-16 06:15:02 -05:00

* added helper function for testing 7z JBinding native code with a simple version call

This commit is contained in:
Reinhard Pointner 2015-10-17 17:20:10 +00:00
parent 94b87b0c3a
commit 2a64e1fe99
2 changed files with 17 additions and 19 deletions

View File

@ -6,6 +6,7 @@ import net.sf.sevenzipjbinding.IArchiveOpenCallback;
import net.sf.sevenzipjbinding.IInArchive; import net.sf.sevenzipjbinding.IInArchive;
import net.sf.sevenzipjbinding.IInStream; import net.sf.sevenzipjbinding.IInStream;
import net.sf.sevenzipjbinding.SevenZip; import net.sf.sevenzipjbinding.SevenZip;
import net.sf.sevenzipjbinding.SevenZipException;
import net.sf.sevenzipjbinding.SevenZipNativeInitializationException; import net.sf.sevenzipjbinding.SevenZipNativeInitializationException;
import com.sun.jna.Platform; import com.sun.jna.Platform;
@ -37,15 +38,16 @@ public class SevenZipLoader {
} }
} }
public static IInArchive open(IInStream stream, IArchiveOpenCallback callback) throws Exception { public static String getNativeVersion() throws SevenZipNativeInitializationException {
// initialize 7-Zip-JBinding
requireNativeLibraries(); requireNativeLibraries();
if (callback == null) { return SevenZip.getSevenZipVersion().version;
return SevenZip.openInArchive(null, stream);
} else {
return SevenZip.openInArchive(null, stream, callback);
} }
public static IInArchive open(IInStream stream, IArchiveOpenCallback callback) throws SevenZipException, SevenZipNativeInitializationException {
requireNativeLibraries();
return (callback == null) ? SevenZip.openInArchive(null, stream) : SevenZip.openInArchive(null, stream, callback);
} }
} }

View File

@ -5,7 +5,6 @@ import java.io.File;
import java.io.FileFilter; import java.io.FileFilter;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.EnumMap; import java.util.EnumMap;
import java.util.List; import java.util.List;
@ -29,8 +28,8 @@ public class SevenZipNativeBindings implements ArchiveExtractor, Closeable {
throw new FileNotFoundException(file.getAbsolutePath()); throw new FileNotFoundException(file.getAbsolutePath());
} }
try {
openVolume = new ArchiveOpenVolumeCallback(); openVolume = new ArchiveOpenVolumeCallback();
if (!Archive.hasMultiPartIndex(file)) { if (!Archive.hasMultiPartIndex(file)) {
// single volume archives and multi-volume rar archives // single volume archives and multi-volume rar archives
inArchive = SevenZipLoader.open(openVolume.getStream(file.getAbsolutePath()), openVolume); inArchive = SevenZipLoader.open(openVolume.getStream(file.getAbsolutePath()), openVolume);
@ -38,9 +37,6 @@ public class SevenZipNativeBindings implements ArchiveExtractor, Closeable {
// raw multi-volume archives // raw multi-volume archives
inArchive = SevenZipLoader.open(new net.sf.sevenzipjbinding.impl.VolumedArchiveInStream(file.getAbsolutePath(), openVolume), null); inArchive = SevenZipLoader.open(new net.sf.sevenzipjbinding.impl.VolumedArchiveInStream(file.getAbsolutePath(), openVolume), null);
} }
} catch (InvocationTargetException e) {
throw (Exception) e.getTargetException();
}
} }
public int itemCount() throws SevenZipException { public int itemCount() throws SevenZipException {