本文整理匯總了Java中com.sun.jna.NativeLibrary類的典型用法代碼示例。如果您正苦於以下問題:Java NativeLibrary類的具體用法?Java NativeLibrary怎麽用?Java NativeLibrary使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
NativeLibrary類屬於com.sun.jna包,在下文中一共展示了NativeLibrary類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: addWatch
import com.sun.jna.NativeLibrary; //導入依賴的package包/類
@Override public LKey addWatch(String path) throws IOException {
// what if the file doesn't exist?
int id = IMPL.inotify_add_watch(fd, path,
InotifyImpl.IN_CREATE | InotifyImpl.IN_MOVED_TO |
InotifyImpl.IN_DELETE | InotifyImpl.IN_MOVED_FROM |
InotifyImpl.IN_MODIFY | InotifyImpl.IN_ATTRIB);
//XXX handle error return value (-1)
LOG.log(Level.FINEST, "addWatch{0} res: {1}", new Object[]{path, id});
if (id <= 0) {
// 28 == EINOSPC
int errno = NativeLibrary.getInstance("c").getFunction("errno").getInt(0); // NOI18N
throw new IOException("addWatch on " + path + " errno: " + errno); // NOI18N
}
LKey newKey = map.get(id);
if (newKey == null) {
newKey = new LKey(id, path);
map.put(id, newKey);
}
return newKey;
}
示例2: Saitek
import com.sun.jna.NativeLibrary; //導入依賴的package包/類
public Saitek(File... libraryPath) {
// try paths individually
for (File f : libraryPath) {
String path = f.toString();
if (path.length() > 0) {
// System.out.println("Using jna.library.path " + path);
System.setProperty("jna.library.path", path);
}
try {
NativeLibrary.getInstance(DirectOutputLibrary.JNA_LIBRARY_NAME);
dol = (DirectOutputLibrary) Native.loadLibrary(DirectOutputLibrary.JNA_LIBRARY_NAME, DirectOutputLibrary.class);
} catch (UnsatisfiedLinkError err) {
System.err.println("Unable to load DirectOutput.dll from " + f + " (running on " + System.getProperty("os.name") + "-" + System.getProperty("os.version")
+ "-" + System.getProperty("os.arch") + "\nContinuuing...");
continue;
}
System.out.println("Loaded library from " + f);
break;
}
if (dol == null) {
throw new IllegalArgumentException("Unable to load DirectOutput.dll from the paths provided");
}
executor = Executors.newSingleThreadExecutor();
executor.submit(this::init);
}
示例3: loadLibraryWithTiming
import com.sun.jna.NativeLibrary; //導入依賴的package包/類
private static NativeLibrary loadLibraryWithTiming(String name) {
String successName = String.format("mr4c.loadlib.%s.success", name);
String failureName = String.format("mr4c.loadlib.%s.failure", name);
StatsTimer timer = new StatsTimer(
MR4CStats.getClient(),
successName,
failureName
);
boolean success = false;
try {
NativeLibrary result = doLoadLibrary(name);
success = true;
return result;
} finally {
timer.done(success);
}
}
示例4: loadNativeLibraries
import com.sun.jna.NativeLibrary; //導入依賴的package包/類
protected void loadNativeLibraries() {
s_log.info("Begin loading native libraries");
s_log.info("jna.library.path={}", System.getProperty("jna.library.path"));
s_log.info("jna.platform.library.path={}", System.getProperty("jna.platform.library.path"));
s_log.info("LD_LIBRARY_PATH={}", System.getenv("LD_LIBRARY_PATH"));
s_log.info("MR4C native library found at [{}]", Mr4cLibrary.JNA_NATIVE_LIB.getFile().getAbsolutePath());
String libName = getAlgorithmConfig().getArtifact();
s_log.info("Loading native algorithm library [{}]", libName);
m_lib = JnaUtils.loadLibrary(libName);
s_log.info("Native algorithm library found at [{}]", m_lib.getFile().getAbsolutePath());
for ( String name : getAlgorithmConfig().getExtras() ) {
s_log.info("Loading extra native library [{}]", name);
NativeLibrary lib = JnaUtils.loadLibrary(name);
s_log.info("Extra native library found at [{}]", lib.getFile().getAbsolutePath());
m_extras.add(lib);
}
s_log.info("End loading native libraries");
}
示例5: initialize
import com.sun.jna.NativeLibrary; //導入依賴的package包/類
@Override
public void initialize(IWorkbenchConfigurer configurer) {
super.initialize(configurer);
org.eclipse.ui.ide.IDE.registerAdapters();
declareWorkbenchImages();
boolean found = false;
String vlcLib = ManagementFactory.getRuntimeMXBean().getSystemProperties().get("vlc");
if (vlcLib != null) {
found = true;
NativeLibrary.addSearchPath("vlc", vlcLib);
}
if (!found) {
found = new NativeDiscovery().discover();
}
if (!found) {
MessageDialog.openError(PlatformUI.getWorkbench().getDisplay().getActiveShell(), "Error", "Cannot play videos. VLC is either not installed or located in an unexpected directory. " + "If VLC is installed in an unexpected directory you can provide the path to its library. " + "Find SynergyView.ini and add a line to the end (if not already there) starting with " + "-Dvlc= followed by the path to an installation instance of VLC's lib folder.");
}
}
示例6: getWin32NativeLibrary
import com.sun.jna.NativeLibrary; //導入依賴的package包/類
private static NativeLibrary getWin32NativeLibrary(String name) {
//
// gstreamer on win32 names the dll files one of foo.dll, libfoo.dll and libfoo-0.dll
//
String[] nameFormats = {
"%s", "lib%s", "lib%s-0",
};
for (int i = 0; i < nameFormats.length; ++i) {
try {
return NativeLibrary.getInstance(String.format(nameFormats[i], name));
} catch (UnsatisfiedLinkError ex) {
continue;
}
}
throw new UnsatisfiedLinkError("Could not load library " + name);
}
示例7: isAeroEnabled
import com.sun.jna.NativeLibrary; //導入依賴的package包/類
public static boolean isAeroEnabled(){
if( HearthHelper.getOSName().equals("win") && DWM == null){
try{
DWM = NativeLibrary.getInstance("dwmapi");
} catch(Throwable e) {}
}
boolean dwmEnabled = false;
if(DWM != null){
boolean[] bool = { false };
Object[] args = { bool };
Function DwmIsCompositionEnabled = DWM.getFunction("DwmIsCompositionEnabled");
HRESULT result = (HRESULT) DwmIsCompositionEnabled.invoke(HRESULT.class, args);
boolean success = result.intValue()==0;
if(success && bool[0]){
dwmEnabled = true;
}
}
return dwmEnabled;
}
示例8: startup
import com.sun.jna.NativeLibrary; //導入依賴的package包/類
@Override
public void startup() throws PluginException {
try {
LOGGER.info("Initializing Praat library");
final String praatSearchFolder =
PrefHelper.get(PRAAT_SEARCH_FOLDER, null);
if(praatSearchFolder != null) {
NativeLibrary.addSearchPath("praat", praatSearchFolder);
}
Praat.INSTANCE.praat_lib_init();
final PraatVersion praatVersion = PraatVersion.getVersion();
// print version information to log
final StringBuilder sb = new StringBuilder();
sb.append("Praat version: ").append(praatVersion.versionStr);
sb.append(" ").append(praatVersion.day).append('-').append(praatVersion.month).append('-').append(praatVersion.year);
LOGGER.info(sb.toString());
} catch (UnsatisfiedLinkError e) {
LOGGER.log(Level.SEVERE, e.getLocalizedMessage(), e);
}
}
示例9: loadVlc
import com.sun.jna.NativeLibrary; //導入依賴的package包/類
public static void loadVlc() {
// String os = System.getProperty("os.name").toLowerCase();
// boolean is64bit = "64".equals(System.getProperty("sun.arch.data.model"));
if (Config.isWindows()) {
// windows
if (Config.is64bit()) {
System.out.println("Loading 64 bit Windows Libraries.");
NativeLibrary.addSearchPath("libvlc", Config.VLC_URL + "windows" + File.separator + "x64" + File.separator);
} else {
System.out.println("Loading 32 bit Windows Libraries.");
NativeLibrary.addSearchPath("libvlc", Config.VLC_URL + "windows" + File.separator + "x86" + File.separator);
}
} else if (Config.isMac()) {
// mac
} else if (Config.isLinux()) {
// linus
} else if (Config.isSolaris()) {
// solaris
}
}
示例10: openLib
import com.sun.jna.NativeLibrary; //導入依賴的package包/類
public static WinscardLibInfo openLib() {
String libraryName = Platform.isWindows() ? WINDOWS_PATH : Platform.isMac() ? MAC_PATH : PCSC_PATH;
HashMap<String, Object> options = new HashMap<String, Object>();
if (Platform.isWindows()) {
options.put(Library.OPTION_FUNCTION_MAPPER, new WindowsFunctionMapper());
} else if (Platform.isMac()) {
options.put(Library.OPTION_FUNCTION_MAPPER, new MacFunctionMapper());
}
WinscardLibrary lib = (WinscardLibrary) Native.loadLibrary(libraryName, WinscardLibrary.class, options);
NativeLibrary nativeLibrary = NativeLibrary.getInstance(libraryName);
// SCARD_PCI_* is #defined to the following symbols (both pcsclite and winscard)
ScardIoRequest SCARD_PCI_T0 = new ScardIoRequest(nativeLibrary.getGlobalVariableAddress("g_rgSCardT0Pci"));
ScardIoRequest SCARD_PCI_T1 = new ScardIoRequest(nativeLibrary.getGlobalVariableAddress("g_rgSCardT1Pci"));
ScardIoRequest SCARD_PCI_RAW = new ScardIoRequest(nativeLibrary.getGlobalVariableAddress("g_rgSCardRawPci"));
SCARD_PCI_T0.read();
SCARD_PCI_T1.read();
SCARD_PCI_RAW.read();
SCARD_PCI_T0.setAutoSynch(false);
SCARD_PCI_T1.setAutoSynch(false);
SCARD_PCI_RAW.setAutoSynch(false);
return new WinscardLibInfo(lib, SCARD_PCI_T0, SCARD_PCI_T1, SCARD_PCI_RAW);
}
示例11: ensureVLCLib
import com.sun.jna.NativeLibrary; //導入依賴的package包/類
/**
* Ensures that the vlcj Lib is properly loaded
*/
public synchronized static void ensureVLCLib(){
if(!vlcjLoaded && !vlcjLoadError)
{
String vlclibName = RuntimeUtil.getLibVlcLibraryName();
List<String> libPaths = VLCUtil.getVLCLibPaths();
logger.info("jni loading: " + vlclibName);
for (String libPath : libPaths) {
logger.debug("adding search path: " + libPath);
NativeLibrary.addSearchPath(vlclibName, libPath);
}
try{
Native.loadLibrary(vlclibName, LibVlc.class);
vlcjLoaded = true;
}catch(UnsatisfiedLinkError e){
vlcjLoadError = true;
logger.error(e);
}
}
}
示例12: initVideoImportEngine
import com.sun.jna.NativeLibrary; //導入依賴的package包/類
@Override
public void initVideoImportEngine(Optional<String> pathToLibrary) {
if (pathToLibrary.isPresent()) {
log.debug("Path to library {}", pathToLibrary);
NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName(), pathToLibrary.get());
Native.loadLibrary(RuntimeUtil.getLibVlcLibraryName(), LibVlc.class);
log.debug("Library loaded");
}
}
示例13: getStdOutNo
import com.sun.jna.NativeLibrary; //導入依賴的package包/類
public int getStdOutNo() {
try {
return CLibrary.INSTANCE.fileno(NativeLibrary.getInstance("c")
.getFunction(getStdOutName()).getPointer(0));
} catch (Throwable ex) {
log("error getting stdout no -> return default. " + ex.getMessage());
}
return 1;
}
示例14: getStdErrNo
import com.sun.jna.NativeLibrary; //導入依賴的package包/類
public int getStdErrNo() {
try {
return CLibrary.INSTANCE.fileno(NativeLibrary.getInstance("c")
.getFunction(getStdErrName()).getPointer(0));
} catch (Throwable ex) {
log("error getting stderr no -> return default. " + ex.getMessage());
}
return 2;
}
示例15: getStdInNo
import com.sun.jna.NativeLibrary; //導入依賴的package包/類
public int getStdInNo() {
try {
return CLibrary.INSTANCE.fileno(NativeLibrary.getInstance("c")
.getFunction(getStdInName()).getPointer(0));
} catch (Throwable ex) {
log("error getting stdin no -> return default. " + ex.getMessage());
}
return 0;
}