本文整理汇总了Java中com.sun.jna.Library类的典型用法代码示例。如果您正苦于以下问题:Java Library类的具体用法?Java Library怎么用?Java Library使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Library类属于com.sun.jna包,在下文中一共展示了Library类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadNativeLibrary
import com.sun.jna.Library; //导入依赖的package包/类
private static <T extends Library> T loadNativeLibrary(String name, Class<T> interfaceClass, Map<String, ?> options) {
T library = interfaceClass.cast(Native.loadLibrary(name, interfaceClass, options));
boolean needCustom = false;
search:
for (Method m : interfaceClass.getMethods())
for (Class<?> cls : m.getParameterTypes())
if (cls.isArray() && getConverter(cls.getComponentType()) != null) {
needCustom = true;
break search;
}
if (!needCustom)
return library;
// System.out.println("Using custom library proxy for " + interfaceClass.getName());
return interfaceClass.cast(
Proxy.newProxyInstance(interfaceClass.getClassLoader(),
new Class[]{ interfaceClass },
new Handler<T>(library, options)));
}
示例2: loadNativeLibrary
import com.sun.jna.Library; //导入依赖的package包/类
private static <T extends Library> T loadNativeLibrary(String name, Class<T> interfaceClass, Map<String, ?> options) {
T library = interfaceClass.cast(Native.loadLibrary(name, interfaceClass, options));
boolean needCustom = false;
for (Method m : interfaceClass.getMethods()) {
for (Class<?> cls : m.getParameterTypes()) {
if (cls.isArray() && getConverter(cls.getComponentType()) != null) {
needCustom = true;
}
}
}
//
// If no custom conversions are needed, just return the JNA proxy
//
if (!needCustom) {
return library;
} else {
// System.out.println("Using custom library proxy for " + interfaceClass.getName());
return interfaceClass.cast(Proxy.newProxyInstance(interfaceClass.getClassLoader(),
new Class[]{ interfaceClass }, new Handler<T>(library, options)));
}
}
示例3: loadWin32Library
import com.sun.jna.Library; //导入依赖的package包/类
private static <T extends Library> T loadWin32Library(String name, Class<T> interfaceClass, Map<String, ?> options) {
//
// 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 interfaceClass.cast(loadNativeLibrary(String.format(nameFormats[i], name), interfaceClass, options));
} catch (UnsatisfiedLinkError ex) {
continue;
}
}
throw new UnsatisfiedLinkError("Could not load library " + name);
}
示例4: openLib
import com.sun.jna.Library; //导入依赖的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);
}
示例5: loadLibrary
import com.sun.jna.Library; //导入依赖的package包/类
public static synchronized <T extends Library> T loadLibrary(String name, Class<T> interfaceClass, Map<String, ?> options) {
if (!Platform.isWindows())
return loadNativeLibrary(name, interfaceClass, options);
for (String format : windowsNameFormats)
try {
return interfaceClass.cast(loadNativeLibrary(String.format(format, name), interfaceClass, options));
} catch (UnsatisfiedLinkError ex) {
continue;
}
throw new UnsatisfiedLinkError("Could not load library: " + name);
}
示例6: load
import com.sun.jna.Library; //导入依赖的package包/类
public static <T extends Library> T load(String libraryName, Class<T> interfaceClass) {
for (String format : nameFormats)
try {
return GNative.loadLibrary(String.format(format, libraryName), interfaceClass, options);
} catch (UnsatisfiedLinkError ex) {
continue;
}
throw new UnsatisfiedLinkError("Could not load library: " + libraryName);
}
示例7: loadLibrary
import com.sun.jna.Library; //导入依赖的package包/类
public static synchronized <T extends Library> T loadLibrary(String name, Class<T> interfaceClass, Map<String, ?> options) {
for (String format : nameFormats)
try {
return loadNativeLibrary(String.format(format, name), interfaceClass, options);
} catch (UnsatisfiedLinkError ex) {
continue;
}
throw new UnsatisfiedLinkError("Could not load library: " + name);
}
示例8: defaultDirectory
import com.sun.jna.Library; //导入依赖的package包/类
/**
* Returns the correct userDataFolder for the given application name.
*/
public static String defaultDirectory() {
// default
String folder = "." + File.separator;
if (isMac()) {
folder = System.getProperty("user.home") + File.separator + "Library" + File.separator
+ "Application Support";
} else if (isWindows()) {
Map<String, Object> options = Maps.newHashMap();
options.put(Library.OPTION_TYPE_MAPPER, W32APITypeMapper.UNICODE);
options.put(Library.OPTION_FUNCTION_MAPPER, W32APIFunctionMapper.UNICODE);
HWND hwndOwner = null;
int nFolder = Shell32.CSIDL_LOCAL_APPDATA;
HANDLE hToken = null;
int dwFlags = Shell32.SHGFP_TYPE_CURRENT;
char pszPath[] = new char[Shell32.MAX_PATH];
Shell32 instance = (Shell32) Native.loadLibrary("shell32", Shell32.class, options);
int hResult = instance.SHGetFolderPath(hwndOwner, nFolder, hToken, dwFlags, pszPath);
if (Shell32.S_OK == hResult) {
String path = new String(pszPath);
int len = path.indexOf('\0');
folder = path.substring(0, len);
} else {
System.err.println("Error: " + hResult);
}
}
folder = folder + File.separator + "SpaceCubes" + File.separator;
return folder;
}
示例9: connect
import com.sun.jna.Library; //导入依赖的package包/类
protected boolean connect() {
try {
if (sysLibrary == null) {
logger.debug("Loading native code library...");
sysLibrary = (LibK8055) Native
.synchronizedLibrary((Library) Native.loadLibrary(
"k8055", LibK8055.class));
logger.debug("Done loading native code library");
}
if (!connected) {
if (sysLibrary.OpenDevice(boardNo) == boardNo) {
connected = true;
// We don't really know the existing state - so this results
// in the state of all inputs being republished
lastDigitalInputs = -1;
logger.info("K8055: Connect to board: " + boardNo
+ " succeeeded.");
} else {
logger.error("K8055: Connect to board: " + boardNo
+ " failed.");
}
}
;
} catch (Exception e) {
logger.error(
"Failed to load K8055 native library. Please check the libk8055 and jna native libraries are in the Java library path. ",
e);
}
return connected;
}
示例10: loadNativeLibrary
import com.sun.jna.Library; //导入依赖的package包/类
public static < L extends Library > L loadNativeLibrary( ArrayList< String > potentialNames, final Class< L > library )
{
final GenericDialogPlus gd = new GenericDialogPlus( "Specify path of native library" );
final String directory;
if ( defaultDirectory == null )
directory = IJ.getDirectory( "ImageJ" );
else
directory = defaultDirectory;
final File dir;
if ( directory == null || directory.equals( "null/") )
dir = new File( "" );
else
dir = new File( directory );
gd.addDirectoryField( "CUDA_Directory", dir.getAbsolutePath(), 80 );
gd.showDialog();
if ( gd.wasCanceled() )
return null;
return loadNativeLibrary( potentialNames, new File( defaultDirectory = gd.getNextString() ), library );
}
示例11: connect
import com.sun.jna.Library; //导入依赖的package包/类
protected boolean connect() {
try {
if (sysLibrary == null) {
logger.debug("Loading native code library...");
sysLibrary = (LibK8055) Native
.synchronizedLibrary((Library) Native.loadLibrary("k8055", LibK8055.class));
logger.debug("Done loading native code library");
}
if (!connected) {
if (sysLibrary.OpenDevice(boardNo) == boardNo) {
connected = true;
// We don't really know the existing state - so this results
// in the state of all inputs being republished
lastDigitalInputs = -1;
logger.info("K8055: Connect to board: " + boardNo + " succeeeded.");
} else {
logger.error("K8055: Connect to board: " + boardNo + " failed.");
}
}
;
} catch (Exception e) {
logger.error(
"Failed to load K8055 native library. Please check the libk8055 and jna native libraries are in the Java library path. ",
e);
}
return connected;
}
示例12: createLibrary
import com.sun.jna.Library; //导入依赖的package包/类
@Override
public INativeLibrary createLibrary(String name, Object callingConvention) {
Map<String, Object> options = new HashMap<>(2);
if (callingConvention == INativeFunction.CallingConventionCdecl) {
options.put(Library.OPTION_CALLING_CONVENTION,
Function.C_CONVENTION);
} else if (callingConvention == INativeFunction.CallingConventionStdcall) {
options.put(Library.OPTION_CALLING_CONVENTION,
Function.ALT_CONVENTION);
} else {
throw new IllegalArgumentException("illegal calling convention");
}
options.put(Library.OPTION_OPEN_FLAGS, -1);
return new JnaNativeLibrary(this, name, options);
}
示例13: main
import com.sun.jna.Library; //导入依赖的package包/类
/**
* @param args
* @throws IOException
*/
public static void main(final String[] args) throws IOException {
Library library = (Library) Native.loadLibrary("ConsultaOnLine", IConsultaOnLineJNA.class);
final IConsultaOnLineJNA consultaOnLine = (IConsultaOnLineJNA) library;
String filepath = JOptionPane.showInputDialog("Digite o caminho do XML a ser enviado a DLL:");
File file = new File(filepath);
System.out.println("Buscando XML " + file.getAbsolutePath() + " ...");
if(!file.exists()){
System.out.println("Arquivo XML " + file.getAbsolutePath() + " n�o encontrado!");
System.exit(1);
}
System.out.println("XML " + file.getAbsolutePath() + " encontrado!");
System.out.println("Convertendo XML para String " + file.getAbsolutePath() + " ...");
final String xml = obterXML(new BufferedReader(new FileReader(file)));
System.out.println("XML convertido para String " + xml + " com sucesso!");
int qtdeAcessos = Integer.parseInt(JOptionPane.showInputDialog("Digite o n�mero de threads a serem executadas:"));
System.out.println("Quantidade de threads: " + qtdeAcessos);
final String caminhoDLL = JOptionPane.showInputDialog("Digite o caminho do diret�rio EVServer:");
System.out.println("Caminho real das DLLs: " + caminhoDLL);
final String tipoServico = JOptionPane.showInputDialog("Digite o tipo de servi�o a ser consultado:");
System.out.println();
final JFrame frame = new JFrame("Resultado EV Server");
final JTextArea textarea = new JTextArea();
textarea.setColumns(100);
textarea.setRows(40);
final JScrollPane scroll = new JScrollPane(textarea);
scroll.setAutoscrolls(true);
frame.add(scroll);
frame.setSize(200, 150);
frame.pack();
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final ThreadGroup group = new ThreadGroup("Group");
for(int i = 0; i < qtdeAcessos; i++){
Thread thread = new Thread(group, new Runnable() {
@Override
public void run() {
textarea.append("Iniciando thread " + Thread.currentThread().getName() + " ...\n");
long time = System.currentTimeMillis();
String retorno = consultaOnLine.DBI_EfetuaConsultaServico(Integer.parseInt(tipoServico), xml, caminhoDLL, caminhoDLL);
textarea.append(Thread.currentThread().getName() + ": Retorno da DLL: \n" + retorno + "\n");
textarea.append(Thread.currentThread().getName() + ": Tempo de resposta: " + ((System.currentTimeMillis() - time) / 1000) + "\n");
textarea.setCaretPosition(textarea.getText().length());
}
});
thread.start();
}
while(group.activeCount() > 0);
textarea.append("Fim da execu��o!");
}
示例14: testDllValidador
import com.sun.jna.Library; //导入依赖的package包/类
/**
* @param args
* @return
*/
public ResulConsVO testDllValidador(String cnpj,String estado) {
// Native.setProtected(true);
Library library = (Library) Native.loadLibrary("ConsultaOnLine", IConsultaOnLineJNA.class);
//library = Native.synchronizedLibrary(library);
IConsultaOnLineJNA consultaOnLine = (IConsultaOnLineJNA) library;
long inicio = System.currentTimeMillis();
String resultado = consultaOnLine.DBI_EfetuaConsultaServico(8,
"<?xml version=\"1.0\" encoding=\"iso-8859-1\"?> "
+ "<ParametrosConsulta Versao=\"1.0\">"
+ "<CRM>77342</CRM>"
+ "<Estado>SP</Estado>"
+ "<Proxy>"
+ "<Ativo>false</Ativo>"
+ "<Usuario/>"
+ "<Senha/>"
+ "<Host/>"
+ "<Porta/>"
+ "</Proxy>"
+ "</ParametrosConsulta>",
"C:\\EV Server", "C:\\EV Server");
/*
String resultado = consultaOnLine.DBI_EfetuaConsultaServico(3,
"<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>"
+ "<ParametrosConsulta Versao=\"1.0\"> "
+ "<Municipio>CAMPINAS</Municipio>" + "<Estado>SP</Estado>"
+ "<Proxy>"
+ "<Ativo>true</Ativo>"
+ "<Usuario>/"
+ "<Senha/>"
+ "<Host/>"
+ "<Porta/>"
+ "</Proxy>" +
"</ParametrosConsulta>",
"C:\\EV Server", "C:\\EV Server");
*/
System.out.println(resultado);
ResulConsVO result = unMarshall(resultado);
Set<DadosRetInstVO> dadosRetInst = result.getRegistrosRetorno();
if(!result.getCodErro().equals(10000)){
System.out.println("Inicio results..."+result.getCodErro()+" "+result.getErro());
}
for (DadosRetInstVO dadosRetInstVO : dadosRetInst) {
RetornoCronometro retornoCronometro = new RetornoCronometro(dadosRetInstVO,inicio,System.currentTimeMillis());
TestJNADll_CRM.retornos.add(retornoCronometro);
System.out.print(retornoCronometro.fim - retornoCronometro.inicio+" ");
System.out.print(retornoCronometro.dadosRetInstVO.getRazaoSocial());
System.out.println();
}
//System.out.println("...fim results");
return null;
}
示例15: testDllValidador
import com.sun.jna.Library; //导入依赖的package包/类
/**
* @param args
* @return
*/
public ResulConsVO testDllValidador(String cnpj,String estado) {
// Native.setProtected(true);
Library library = (Library) Native.loadLibrary("ConsultaOnLine", IConsultaOnLineJNA.class);
//library = Native.synchronizedLibrary(library);
IConsultaOnLineJNA consultaOnLine = (IConsultaOnLineJNA) library;
long inicio = System.currentTimeMillis();
String resultado = consultaOnLine.DBI_EfetuaConsultaServico(10,
"<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>"
+ "<ParametrosConsulta Versao=\"1.0\"> "
+ "<Municipio>campinas</Municipio>"
+ "<Estado>SP</Estado>"
+ "<Proxy>"
+ "<Ativo>false</Ativo>"
+ "<Usuario/>"
+ "<Senha/>"
+ "<Host/>"
+ "<Porta/>"
+ "</Proxy>"
+ "</ParametrosConsulta>",
"C:\\EV Server", "C:\\EV Server");
/*
String resultado = consultaOnLine.DBI_EfetuaConsultaServico(3,
"<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>"
+ "<ParametrosConsulta Versao=\"1.0\"> "
+ "<Municipio>CAMPINAS</Municipio>" + "<Estado>SP</Estado>"
+ "<Proxy>"
+ "<Ativo>true</Ativo>"
+ "<Usuario>/"
+ "<Senha/>"
+ "<Host/>"
+ "<Porta/>"
+ "</Proxy>" +
"</ParametrosConsulta>",
"C:\\EV Server", "C:\\EV Server");
*/
System.out.println(resultado);
ResulConsVO result = unMarshall(resultado);
Set<DadosRetInstVO> dadosRetInst = result.getRegistrosRetorno();
if(!result.getCodErro().equals(10000)){
System.out.println("Inicio results..."+result.getCodErro()+" "+result.getErro());
}
for (DadosRetInstVO dadosRetInstVO : dadosRetInst) {
RetornoCronometro retornoCronometro = new RetornoCronometro(dadosRetInstVO,inicio,System.currentTimeMillis());
TestJNADll_IBGE.retornos.add(retornoCronometro);
System.out.print(retornoCronometro.fim - retornoCronometro.inicio+" ");
System.out.print(retornoCronometro.dadosRetInstVO.getRazaoSocial());
System.out.println();
}
//System.out.println("...fim results");
return null;
}