* 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.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);
}
}

View File

@ -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,8 +28,8 @@ 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);
@ -38,9 +37,6 @@ public class SevenZipNativeBindings implements ArchiveExtractor, Closeable {
// raw multi-volume archives
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 {