From 2a64e1fe9981900bb35f53cc4d6f88fef1df7cac Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Sat, 17 Oct 2015 17:20:10 +0000 Subject: [PATCH] * added helper function for testing 7z JBinding native code with a simple version call --- .../net/filebot/archive/SevenZipLoader.java | 16 ++++++++------- .../archive/SevenZipNativeBindings.java | 20 ++++++++----------- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/source/net/filebot/archive/SevenZipLoader.java b/source/net/filebot/archive/SevenZipLoader.java index e4e43f8f..6164a6fd 100644 --- a/source/net/filebot/archive/SevenZipLoader.java +++ b/source/net/filebot/archive/SevenZipLoader.java @@ -6,6 +6,7 @@ import net.sf.sevenzipjbinding.IArchiveOpenCallback; import net.sf.sevenzipjbinding.IInArchive; import net.sf.sevenzipjbinding.IInStream; import net.sf.sevenzipjbinding.SevenZip; +import net.sf.sevenzipjbinding.SevenZipException; import net.sf.sevenzipjbinding.SevenZipNativeInitializationException; import com.sun.jna.Platform; @@ -37,15 +38,16 @@ public class SevenZipLoader { } } - public static IInArchive open(IInStream stream, IArchiveOpenCallback callback) throws Exception { - // initialize 7-Zip-JBinding + public static String getNativeVersion() throws SevenZipNativeInitializationException { requireNativeLibraries(); - if (callback == null) { - return SevenZip.openInArchive(null, stream); - } else { - return SevenZip.openInArchive(null, stream, callback); - } + return SevenZip.getSevenZipVersion().version; + } + + public static IInArchive open(IInStream stream, IArchiveOpenCallback callback) throws SevenZipException, SevenZipNativeInitializationException { + requireNativeLibraries(); + + return (callback == null) ? SevenZip.openInArchive(null, stream) : SevenZip.openInArchive(null, stream, callback); } } diff --git a/source/net/filebot/archive/SevenZipNativeBindings.java b/source/net/filebot/archive/SevenZipNativeBindings.java index 03f3efd8..1fce0856 100644 --- a/source/net/filebot/archive/SevenZipNativeBindings.java +++ b/source/net/filebot/archive/SevenZipNativeBindings.java @@ -5,7 +5,6 @@ import java.io.File; import java.io.FileFilter; import java.io.FileNotFoundException; import java.io.IOException; -import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.EnumMap; import java.util.List; @@ -29,17 +28,14 @@ public class SevenZipNativeBindings implements ArchiveExtractor, Closeable { throw new FileNotFoundException(file.getAbsolutePath()); } - try { - openVolume = new ArchiveOpenVolumeCallback(); - if (!Archive.hasMultiPartIndex(file)) { - // single volume archives and multi-volume rar archives - inArchive = SevenZipLoader.open(openVolume.getStream(file.getAbsolutePath()), openVolume); - } else { - // raw multi-volume archives - inArchive = SevenZipLoader.open(new net.sf.sevenzipjbinding.impl.VolumedArchiveInStream(file.getAbsolutePath(), openVolume), null); - } - } catch (InvocationTargetException e) { - throw (Exception) e.getTargetException(); + openVolume = new ArchiveOpenVolumeCallback(); + + if (!Archive.hasMultiPartIndex(file)) { + // single volume archives and multi-volume rar archives + inArchive = SevenZipLoader.open(openVolume.getStream(file.getAbsolutePath()), openVolume); + } else { + // raw multi-volume archives + inArchive = SevenZipLoader.open(new net.sf.sevenzipjbinding.impl.VolumedArchiveInStream(file.getAbsolutePath(), openVolume), null); } }