本文整理了Java中com.sun.jna.Native.toString()
方法的一些代码示例,展示了Native.toString()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Native.toString()
方法的具体详情如下:
包路径:com.sun.jna.Native
类名称:Native
方法名:toString
[英]Obtain a Java String from the given native byte array. If there is no NUL terminator, the String will comprise the entire array. If the system property jna.encoding
is set, its value will override the platform default encoding (if supported).
[中]从给定的本机字节数组中获取Java字符串。如果没有NUL终止符,则字符串将构成整个数组。如果设置了系统属性jna.encoding
,其值将覆盖平台默认编码(如果支持)。
代码示例来源:origin: kaitoy/pcap4j
@Override
public String toString() {
return Native.toString(buf);
}
}
代码示例来源:origin: net.java.dev.jna/jna
/**
* Obtain a Java String from the given native byte array. If there is
* no NUL terminator, the String will comprise the entire array. The
* encoding is obtained from {@link #getDefaultStringEncoding()}.
*
* @param buf The buffer containing the encoded bytes
* @see #toString(byte[], String)
*/
public static String toString(byte[] buf) {
return toString(buf, getDefaultStringEncoding());
}
代码示例来源:origin: net.java.dev.jna/jna
/**
* Obtain a Java String from the given native byte array, using the given
* encoding. If there is no NUL terminator, the String will comprise the
* entire array.
*
* <p><strong>Usage note</strong>: This function assumes, that {@code buf}
* holds a {@code char} array. This means only single-byte encodings are
* supported.</p>
*
* @param buf The buffer containing the encoded bytes. Must not be {@code null}.
* @param encoding The encoding name - if {@code null} then the platform
* default encoding will be used
*/
public static String toString(byte[] buf, String encoding) {
return Native.toString(buf, Native.getCharset(encoding));
}
代码示例来源:origin: org.elasticsearch/elasticsearch
/**
* Retrieves the short path form of the specified path.
*
* @param path the path
* @return the short path name (or the original path if getting the short path name fails for any reason)
*/
static String getShortPathName(String path) {
assert Constants.WINDOWS;
try {
final WString longPath = new WString("\\\\?\\" + path);
// first we get the length of the buffer needed
final int length = JNAKernel32Library.getInstance().GetShortPathNameW(longPath, null, 0);
if (length == 0) {
logger.warn("failed to get short path name: {}", Native.getLastError());
return path;
}
final char[] shortPath = new char[length];
// knowing the length of the buffer, now we get the short name
if (JNAKernel32Library.getInstance().GetShortPathNameW(longPath, shortPath, length) > 0) {
return Native.toString(shortPath);
} else {
logger.warn("failed to get short path name: {}", Native.getLastError());
return path;
}
} catch (final UnsatisfiedLinkError e) {
return path;
}
}
代码示例来源:origin: net.java.dev.jna/jna-platform
/**
* @return String, such as "Service Pack 3", that indicates the latest
* Service Pack installed on the system.<br>
* If no Service Pack has been installed, the string is empty.
*/
public String getServicePack() {
return Native.toString(szCSDVersion);
}
代码示例来源:origin: net.java.dev.jna/jna-platform
/**
* @return The module path.
*/
public String szExePath() {
return Native.toString(this.szExePath);
}
}
代码示例来源:origin: net.java.dev.jna/jna-platform
/**
* Gets the dbcc_name.
*
* @return the dbcc_name
*/
public String getDbcc_name() {
return Native.toString(this.dbcc_name);
}
}
代码示例来源:origin: net.java.dev.jna/jna-platform
/**
* @return The module name.
*/
public String szModule() {
return Native.toString(this.szModule);
}
代码示例来源:origin: org.pcap4j/pcap4j-core
@Override
public String toString() {
return Native.toString(buf);
}
}
代码示例来源:origin: net.java.dev.jna/jna-platform
/**
* Name of the key.
* @return String.
*/
public String getName() {
return Native.toString(Name);
}
代码示例来源:origin: net.java.dev.jna/jna-platform
/**
* @return String containing the file name
*/
public String getFileName() {
return Native.toString(cFileName);
}
代码示例来源:origin: net.java.dev.jna/jna-platform
/**
* @return String containing the alternate file name
*/
public String getAlternateFileName() {
return Native.toString(cAlternateFileName);
}
}
代码示例来源:origin: net.java.dev.jna/platform
/**
* Name of the key.
* @return String.
*/
public String getName() {
return Native.toString(Name);
}
代码示例来源:origin: org.elasticsearch/jna
/**
* Obtain a Java String from the given native byte array. If there is
* no NUL terminator, the String will comprise the entire array. The
* encoding is obtained from {@link #getDefaultStringEncoding()}.
*
* @param buf The buffer containing the encoded bytes
* @see #toString(byte[], String)
*/
public static String toString(byte[] buf) {
return toString(buf, getDefaultStringEncoding());
}
代码示例来源:origin: Exslims/MercuryTrade
private static String getGamePath() {
return WindowUtils.getAllWindows(false).stream().filter(window -> {
char[] className = new char[512];
User32.INSTANCE.GetClassName(window.getHWND(), className, 512);
return Native.toString(className).equals("POEWindowClass");
}).map(it -> {
String filePath = it.getFilePath();
return StringUtils.substringBeforeLast(filePath, "\\");
}).findAny().orElse(null);
}
}
代码示例来源:origin: net.java.dev.jna/jna-platform
@Override
public String getWindowTitle(final HWND hwnd) {
final int requiredLength = User32.INSTANCE
.GetWindowTextLength(hwnd) + 1;
final char[] title = new char[requiredLength];
final int length = User32.INSTANCE.GetWindowText(hwnd, title,
title.length);
return Native.toString(Arrays.copyOfRange(title, 0, length));
}
代码示例来源:origin: JetBrains/jediterm
@Nullable
public static String toStringViaUTF8(ID cfString) {
if (cfString.intValue() == 0) return null;
int lengthInChars = myFoundationLibrary.CFStringGetLength(cfString);
int potentialLengthInBytes = 3 * lengthInChars + 1; // UTF8 fully escaped 16 bit chars, plus nul
byte[] buffer = new byte[potentialLengthInBytes];
byte ok = myFoundationLibrary.CFStringGetCString(cfString, buffer, buffer.length, FoundationLibrary.kCFStringEncodingUTF8);
if (ok == 0) throw new RuntimeException("Could not convert string");
return Native.toString(buffer);
}
代码示例来源:origin: gradle.plugin.de.qaware.seu.as.code/seuac-credentials-plugin
private String translateStatusCode(int status) {
Pointer message = security.SecCopyErrorMessageString(status, null);
int lengthInChars = coreFoundation.CFStringGetLength(message);
int potentialLengthInBytes = 3 * lengthInChars + 1;
byte[] buffer = new byte[potentialLengthInBytes];
boolean res = coreFoundation.CFStringGetCString(message, buffer, potentialLengthInBytes, CoreFoundation.kCFStringEncodingUTF8);
coreFoundation.CFRelease(message);
return res ? Native.toString(buffer, UTF_8.name()) : "";
}
}
代码示例来源:origin: org.rococoa/rococoa-core
static String toStringViaUTF8(ID cfString) {
int lengthInChars = foundationLibrary.CFStringGetLength(cfString);
int potentialLengthInBytes = 3 * lengthInChars + 1; // UTF8 fully escaped 16 bit chars, plus nul
byte[] buffer = new byte[potentialLengthInBytes];
byte ok = foundationLibrary.CFStringGetCString(cfString, buffer, buffer.length, StringEncoding.kCFStringEncodingUTF8.value);
if (ok == 0)
throw new RococoaException("Could not convert string");
return Native.toString(buffer);
}
代码示例来源:origin: net.java.dev.jna/jna-platform
/**
* Return the path designated for temporary files.
*
* @return Path.
*/
public static String getTempPath() {
DWORD nBufferLength = new DWORD(WinDef.MAX_PATH);
char[] buffer = new char[nBufferLength.intValue()];
if (Kernel32.INSTANCE.GetTempPath(nBufferLength, buffer).intValue() == 0) {
throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
}
return Native.toString(buffer);
}
内容来源于网络,如有侵权,请联系作者删除!