当前位置: 首页>>代码示例>>Java>>正文


Java Native.toString方法代码示例

本文整理汇总了Java中com.sun.jna.Native.toString方法的典型用法代码示例。如果您正苦于以下问题:Java Native.toString方法的具体用法?Java Native.toString怎么用?Java Native.toString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.sun.jna.Native的用法示例。


在下文中一共展示了Native.toString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: while

import com.sun.jna.Native; //导入方法依赖的package包/类
/**
 * Finds the given process in the process list.
 *
 * @param processEntry The process entry.
 * @param filenamePattern pattern matching the filename of the process.
 * @return The found process entry.
 */
public static boolean findProcessEntry
                (final Tlhelp32.PROCESSENTRY32.ByReference processEntry,
                 final Pattern filenamePattern) {
    Kernel32 kernel32 = Native.loadLibrary(Kernel32.class, W32APIOptions.UNICODE_OPTIONS);

    WinNT.HANDLE snapshot = kernel32.CreateToolhelp32Snapshot(Tlhelp32.TH32CS_SNAPPROCESS, new WinDef.DWORD(0));

    boolean found = false;

    try {
        while (kernel32.Process32Next(snapshot, processEntry)) {
            String fname = Native.toString(processEntry.szExeFile);

            if (fname != null && filenamePattern.matcher(fname).matches()) {
                found = true;
                break;
            }
        }
    } finally {
        kernel32.CloseHandle(snapshot);
    }

    return found;
}
 
开发者ID:mmarquee,项目名称:ui-automation,代码行数:32,代码来源:Utils.java

示例2: getHostname

import com.sun.jna.Native; //导入方法依赖的package包/类
/**
 * @return the hostname the of the current machine
 */
public static String getHostname() {
    if (Platform.isWindows()) {
        return Kernel32Util.getComputerName();
    } else {
        // For now, we'll consider anyhting other than Windows to be unix-ish enough to have gethostname
        // TODO - Consider http://stackoverflow.com/a/10543006 as a possibly better MacOS option
        
        byte[] hostnameBuffer = new byte[4097];
        // http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/limits.h.html suggests
        // the actual limit would be 255.
        
        int result = UnixCLibrary.INSTANCE.gethostname(hostnameBuffer, hostnameBuffer.length);
        if (result != 0) {
            throw new RuntimeException("gethostname call failed");
        }
        
        return Native.toString(hostnameBuffer);
    }
}
 
开发者ID:mattsheppard,项目名称:gethostname4j,代码行数:23,代码来源:Hostname.java

示例3: getAppUserModelId

import com.sun.jna.Native; //导入方法依赖的package包/类
public static String getAppUserModelId(HWND hwnd) {
	IntByReference processID = new IntByReference();
	User32.INSTANCE.GetWindowThreadProcessId(hwnd, processID);
	HANDLE hProcess = Kernel32.INSTANCE.OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, false, processID.getValue());
	UINTByReference length = new UINTByReference();
	Kernel32Ext.INSTANCE.GetApplicationUserModelId(hProcess, length, null);
	char[] modelID = new char[length.getValue().intValue()];
	Kernel32Ext.INSTANCE.GetApplicationUserModelId(hProcess, length, modelID);
	return new String(Native.toString(modelID));
}
 
开发者ID:Guerra24,项目名称:NanoUI,代码行数:11,代码来源:Util.java

示例4: sendKey

import com.sun.jna.Native; //导入方法依赖的package包/类
public void sendKey(final char key)
{
	if (_pid <= 0)
		return;
	if (getActiveWindow() != null)
	{
		byte[] windowText = new byte[512];
		MyUser32.INSTANCE.GetWindowTextA(lastActiveWindow, windowText, 512);
		String wText = Native.toString(windowText);
		wText = (wText.isEmpty()) ? "" : "; text: " + wText;
		System.out.println("sending key " + key + " to " + wText);

		MyUser32.INSTANCE.SendMessageW(lastActiveWindow,
				MyUser32.WM_KEYDOWN, key, 0);
		MyUser32.INSTANCE.SendMessageW(lastActiveWindow, MyUser32.WM_KEYUP,
				key, 0);
	}
	else
		System.out.println("no window found");

}
 
开发者ID:yajsw,项目名称:yajsw,代码行数:22,代码来源:WindowsXPProcess.java

示例5: byName

import com.sun.jna.Native; //导入方法依赖的package包/类
public static Process byName(String name) {
	if (Platform.isWindows()) {
		Tlhelp32.PROCESSENTRY32.ByReference entry = new Tlhelp32.PROCESSENTRY32.ByReference();
		Pointer snapshot = Kernel32.CreateToolhelp32Snapshot(Tlhelp32.TH32CS_SNAPALL.intValue(), 0);
		try {
			while (Kernel32.Process32Next(snapshot, entry)) {
				String processName = Native.toString(entry.szExeFile);
				if (name.equals(processName)) {
					return byId(entry.th32ProcessID.intValue());
				}
			}
		} finally {
			Kernel32.CloseHandle(snapshot);
		}
	} else if (Platform.isMac() || Platform.isLinux()) {
		return byId(Utils.exec("bash", "-c", "ps -A | grep -m1 \"" + name + "\" | awk '{print $1}'"));
	} else {
		throw new UnsupportedOperationException("Unknown operating system! (" + System.getProperty("os.name") + ")");
	}
	throw new IllegalStateException("Process '" + name + "' was not found. Are you sure its running?");
}
 
开发者ID:Jonatino,项目名称:Java-Memory-Manipulation,代码行数:22,代码来源:Processes.java

示例6: hashBytes

import com.sun.jna.Native; //导入方法依赖的package包/类
private String hashBytes(int iterations, int memory, int parallelism, byte[] pwd) {
    final byte[] salt = generateSalt();

    final Uint32_t iterations_t = new Uint32_t(iterations);
    final Uint32_t memory_t = new Uint32_t(memory);
    final Uint32_t parallelism_t = new Uint32_t(parallelism);

    int len = argon2Library.argon2_encodedlen(iterations_t, memory_t, parallelism_t,
            new Uint32_t(salt.length), new Uint32_t(hashLen)).intValue();
    final byte[] encoded = new byte[len];

    int result = callLibraryHash(pwd, salt, iterations_t, memory_t, parallelism_t, encoded);

    if (result != Argon2Library.ARGON2_OK) {
        String errMsg = argon2Library.argon2_error_message(result);
        throw new IllegalStateException(String.format("%s (%d)", errMsg, result));
    }

    return Native.toString(encoded, ASCII);
}
 
开发者ID:Netfall,项目名称:libargon2-java,代码行数:21,代码来源:BaseArgon2.java

示例7: hashBytes

import com.sun.jna.Native; //导入方法依赖的package包/类
private String hashBytes(int iterations, int memory, int parallelism, byte[] pwd) {
    final byte[] salt = generateSalt();

    final JnaUint32 jnaIterations = new JnaUint32(iterations);
    final JnaUint32 jnaMemory = new JnaUint32(memory);
    final JnaUint32 jnaParallelism = new JnaUint32(parallelism);

    int len = Argon2Library.INSTANCE.argon2_encodedlen(jnaIterations, jnaMemory, jnaParallelism,
            new JnaUint32(salt.length), new JnaUint32(hashLen), getType().getJnaType()).intValue();
    final byte[] encoded = new byte[len];

    int result = callLibraryHash(pwd, salt, jnaIterations, jnaMemory, jnaParallelism, encoded);

    if (result != Argon2Library.ARGON2_OK) {
        String errMsg = Argon2Library.INSTANCE.argon2_error_message(result);
        throw new IllegalStateException(String.format("%s (%d)", errMsg, result));
    }

    return Native.toString(encoded, ASCII);
}
 
开发者ID:phxql,项目名称:argon2-jvm,代码行数:21,代码来源:BaseArgon2.java

示例8: cLibGetHostname

import com.sun.jna.Native; //导入方法依赖的package包/类
/**
 * Returns the result of {@code gethostname()} function 
 * from the standard Unix/Linux C Library.
 * 
 * @return host name 
 * @throws NativeException if there was an error executing the
 *    system call.
 */
public static String cLibGetHostname() throws NativeException {
    byte[] buf = new byte[MAXHOSTNAMELEN];
    int retCode = CLib.INSTANCE.gethostname(buf, buf.length);
    
    if (retCode == 0) {
        return Native.toString(buf);
    }
    throw new NativeException(retCode, "error calling 'gethostname()' function");
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:HostnameUtilsUnix.java

示例9: getProcess

import com.sun.jna.Native; //导入方法依赖的package包/类
/**
 * return active process EXE
 * 
 * @return
 */
public static String getProcess() {
    char[] buffer = new char[MAX_TITLE_LENGTH * 2];
    PointerByReference pointer = new PointerByReference();
    GetWindowThreadProcessId(GetForegroundWindow(), pointer);
    Pointer process = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, false, pointer.getValue());
    GetModuleBaseNameW(process, null, buffer, MAX_TITLE_LENGTH);
    return Native.toString(buffer);
}
 
开发者ID:SlideKB,项目名称:SlideBar,代码行数:14,代码来源:ActiveProcess.java

示例10: callback

import com.sun.jna.Native; //导入方法依赖的package包/类
@Override
public boolean callback(HWND hWnd, Pointer data) {
	char[] textBuffer = new char[512];
	char[] textBuffer2 = new char[512];
	User32.INSTANCE.GetClassName(hWnd, textBuffer, 512);
	User32.INSTANCE.GetWindowText(hWnd, textBuffer2, 512);
	String wText = Native.toString(textBuffer);
	String wText2 = Native.toString(textBuffer2);
	childList.add(hWnd);
	System.out.println("className: " + wText + " title: " + wText2);
	return true;
}
 
开发者ID:frolovm,项目名称:poker-bot,代码行数:13,代码来源:WindowSearchCalback.java

示例11: getWindowsDirectory

import com.sun.jna.Native; //导入方法依赖的package包/类
@Override
public String getWindowsDirectory() {
	char test[] = new char[2 + 256 * 2];
	int r = Kernel32.INSTANCE.GetWindowsDirectoryW(test, 256);
	if (r > 0) {
		return Native.toString(test);
	}
	return null;
}
 
开发者ID:DigitalMediaServer,项目名称:DigitalMediaServer,代码行数:10,代码来源:WinUtils.java

示例12: Process

import com.sun.jna.Native; //导入方法依赖的package包/类
/**
 * Creates a new process wrapper that is able to read information from the
 * process, given by its PROCESSENTRY32 structure.
 * 
 * @see <a href=
 *      "https://msdn.microsoft.com/en-us/library/ms684839(v=vs.85).aspx">
 *      MSDN webpage#PROCESSENTRY32 structure</a>
 * 
 * @param pe32
 *            PROCESSENTRY32 structure of the process to wrap around
 */
public Process(final PROCESSENTRY32 pe32) {
	this.mPid = pe32.th32ProcessID.intValue();
	this.mSzExeFile = Native.toString(pe32.szExeFile);
	this.mCntThreads = pe32.cntThreads.intValue();
	this.mPcPriClassBase = pe32.pcPriClassBase.intValue();
	this.mTh32ParentProcessID = pe32.th32ParentProcessID.intValue();

	this.mHandleCache = null;
	this.mIconCache = null;
	this.mModuleCache = null;
	this.mHWindows = new LinkedList<>();
}
 
开发者ID:ZabuzaW,项目名称:Mem-Eater-Bug,代码行数:24,代码来源:Process.java

示例13: callBack

import com.sun.jna.Native; //导入方法依赖的package包/类
/** 
* 回调事件处理
* @param eventType 事件类型
* @param eventBuf 回调信息南向bean
* @param bufSize
* @param userData sessionId
* @see [类、类#方法、类#成员]
* @since  eSDK IVS V100R003C00
*/
public void callBack(int eventType, Pointer eventBuf, int bufSize, Pointer userData)
{
    LOGGER.debug("ivs event " + eventType + " call back start --->>>");
    UserDataSouth userDataSouth = new UserDataSouth(userData);
    userDataSouth.read();
    Object msg = callbackEventConvert.getCallbackMessage(eventType, eventBuf, bufSize, userDataSouth);
    
    String esdkSessionId = Native.toString(userDataSouth.sessionId);
    
    if (null != msg)
    {
        CallbackMsg callbackMsg = new CallbackMsg();
        
        callbackMsg.setEventType(eventType);
        callbackMsg.setEsdkSessionId(esdkSessionId);
        callbackMsg.setDate(new Date());
        callbackMsg.setMsg(msg);
        
        // 入队
        callbackMsgQueue.offer(callbackMsg);
        LOGGER.debug("callbackMsgQueue.offer size: " + callbackMsgQueue.size());
        LOGGER.debug("callbackMsgQueue.offer enentType: " + eventType);
    }

    LOGGER.debug("ivs event " + eventType + " call back end --->>>");
}
 
开发者ID:Huawei,项目名称:eSDK_IVS_Java,代码行数:36,代码来源:CallbackEventImpl.java

示例14: capture

import com.sun.jna.Native; //导入方法依赖的package包/类
public CameraFileSystemEntryBean capture(final GP2CameraCaptureType captureType) {
	CameraFilePath.ByReference refCameraFilePath = new CameraFilePath.ByReference();
	GP2ErrorHelper.checkResult(
			Gphoto2Library.INSTANCE.gp_camera_capture(cameraByReference, captureType.getCode(), refCameraFilePath, gp2Context.getPointerByRef()));
	return new CameraFileSystemEntryBean(Native.toString(refCameraFilePath.name, NATIVE_STRING_ENCODING),
			Native.toString(refCameraFilePath.folder, NATIVE_STRING_ENCODING), false);
}
 
开发者ID:mvmn,项目名称:jlibgphoto2,代码行数:8,代码来源:GP2Camera.java

示例15: getHostName

import com.sun.jna.Native; //导入方法依赖的package包/类
/**
 * Gets the local host name.
 * 
 * <p>
 * The underlying Windows function may return a simple host name (e.g.
 * {@code chicago}) or it may return a fully qualified host name (e.g.
 * {@code chicago.us.internal.net}). The {@code noQualify} parameter can
 * remove the domain part if it exists.
 *
 * <p>
 * Note that the underlying Windows function will do a name service lookup
 * and the method is therefore potentially blocking, although it is more
 * than likely that Windows has cached this result in the DNS Client Cache
 * and therefore the result will be returned very fast.
 *
 * <p>
 * Windows API equivalent: {@code gethostname()} function from 
 * {@code Ws2_32} library.
 * 
 * @param noQualify if {@code true} the result is never qualified with domain,
 *   if {@code false} the result is <i>potentially</i> a fully qualified
 *   host name.
 * 
 * @return host name
 * @throws NativeException if there was an error executing the
 *    system call.
 */
public static String getHostName(boolean noQualify) throws NativeException {
    
    byte[] buf = new byte[256];
    
    int returnCode = Winsock2Lib.INSTANCE.gethostname(buf, buf.length);
    if (returnCode == 0) {
        String result = Native.toString(buf);
        if (noQualify) {
            return IpAddressUtils.removeDomain(result);
        } else {
            return result;
        }
    } else {
        throw new NativeException(returnCode, "error calling 'gethostname()' function");
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:44,代码来源:HostnameUtilsWin.java


注:本文中的com.sun.jna.Native.toString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。