當前位置: 首頁>>代碼示例>>Java>>正文


Java Library類代碼示例

本文整理匯總了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)));
    }
 
開發者ID:gstreamer-java,項目名稱:gstreamer1.x-java,代碼行數:19,代碼來源:GNative.java

示例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)));
        }
    }
 
開發者ID:armouroflight,項目名稱:java-gobject,代碼行數:23,代碼來源:GNative.java

示例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);
}
 
開發者ID:armouroflight,項目名稱:java-gobject,代碼行數:17,代碼來源:GNative.java

示例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);
}
 
開發者ID:jnasmartcardio,項目名稱:jnasmartcardio,代碼行數:23,代碼來源:Winscard.java

示例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);
}
 
開發者ID:gstreamer-java,項目名稱:gstreamer1.x-java,代碼行數:12,代碼來源:GNative.java

示例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);
}
 
開發者ID:gstreamer-java,項目名稱:gstreamer1.x-java,代碼行數:10,代碼來源:GstNative.java

示例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);
}
 
開發者ID:gstreamer-java,項目名稱:gst1-java-core,代碼行數:10,代碼來源:GNative.java

示例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;
}
 
開發者ID:IgnisIncendio,項目名稱:space-cubes,代碼行數:38,代碼來源:SystemNativesHelper.java

示例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;
}
 
開發者ID:andrey-desman,項目名稱:openhab-hdl,代碼行數:34,代碼來源:k8055Binding.java

示例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 );
}
 
開發者ID:fiji,項目名稱:SPIM_Registration,代碼行數:28,代碼來源:NativeLibraryTools.java

示例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;
}
 
開發者ID:openhab,項目名稱:openhab1-addons,代碼行數:31,代碼來源:k8055Binding.java

示例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);
}
 
開發者ID:intarsys,項目名稱:native-c,代碼行數:16,代碼來源:JnaNativeInterface.java

示例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!");
}
 
開發者ID:darciopacifico,項目名稱:omr,代碼行數:65,代碼來源:TestDll.java

示例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;
	}
 
開發者ID:darciopacifico,項目名稱:omr,代碼行數:77,代碼來源:TestJNADll_CRM.java

示例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;
	}
 
開發者ID:darciopacifico,項目名稱:omr,代碼行數:77,代碼來源:TestJNADll_IBGE.java


注:本文中的com.sun.jna.Library類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。