本文整理了Java中com.sun.jna.Native.getDefaultStringEncoding()
方法的一些代码示例,展示了Native.getDefaultStringEncoding()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Native.getDefaultStringEncoding()
方法的具体详情如下:
包路径:com.sun.jna.Native
类名称:Native
方法名:getDefaultStringEncoding
暂无
代码示例来源:origin: net.java.dev.jna/jna
/** Create a native string as a NUL-terminated array of <code>wchar_t</code>
* (if <code>wide</code> is true) or <code>char</code>.<p>
* If not <code>wide</code>, the encoding is obtained from {@link
* Native#getDefaultStringEncoding()}.
*
* @param string value to write to native memory
* @param wide whether to store the String as <code>wchar_t</code>
*/
public NativeString(String string, boolean wide) {
this(string, wide ? WIDE_STRING : Native.getDefaultStringEncoding());
}
代码示例来源:origin: net.java.dev.jna/jna
/** Create a native string (NUL-terminated array of <code>char</code>).<p>
* Uses the encoding returned by {@link Native#getDefaultStringEncoding()}.
*/
public NativeString(String string) {
this(string, Native.getDefaultStringEncoding());
}
代码示例来源:origin: net.java.dev.jna/jna
/** Create a native array of strings. */
public StringArray(String[] strings, boolean wide) {
this((Object[])strings, wide ? NativeString.WIDE_STRING : Native.getDefaultStringEncoding());
}
/** Create a native array of strings using the given encoding. */
代码示例来源:origin: net.java.dev.jna/jna
/**
* @param s The string
* @return A NUL-terminated byte buffer equivalent to the given String,
* using the encoding returned by {@link #getDefaultStringEncoding()}.
* @see #toByteArray(String, String)
*/
public static byte[] toByteArray(String s) {
return toByteArray(s, getDefaultStringEncoding());
}
代码示例来源:origin: net.java.dev.jna/jna
/**
* Copy native memory to a Java String. The encoding used is obtained
* form {@link Native#getDefaultStringEncoding()}.
*
* @param offset byte offset from pointer to start reading bytes
* @return the <code>String</code> value being pointed to
*/
public String getString(long offset) {
return getString(offset, Native.getDefaultStringEncoding());
}
代码示例来源: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
/**
* @param s The input string
* @return A byte array corresponding to the given String. The encoding
* used is obtained from {@link #getDefaultStringEncoding()}.
*/
static byte[] getBytes(String s) {
return getBytes(s, getDefaultStringEncoding());
}
代码示例来源:origin: net.java.dev.jna/jna
/** <p>Returns an array of <code>String</code> based on a native array
* of <code>char *</code>. The array length is determined by a
* NULL-valued terminating element.
* </p>
* The strings are decoded using the encoding returned by {@link
* Native#getDefaultStringEncoding()}.
*/
public String[] getStringArray(long offset) {
return getStringArray(offset, -1, Native.getDefaultStringEncoding());
}
代码示例来源:origin: net.java.dev.jna/jna
/** <p>Returns an array of <code>String</code> based on a native array
* of <code>char *</code>, using the given array length.
* </p>
* The strings are decoded using the encoding returned by {@link
* Native#getDefaultStringEncoding()}.
*/
public String[] getStringArray(long offset, int length) {
return getStringArray(offset, length, Native.getDefaultStringEncoding());
}
代码示例来源:origin: net.java.dev.jna/jna
/**
* @param cls The native interface type
* @return The preferred string encoding for the given native interface.
* If there is no setting, defaults to the {@link #getDefaultStringEncoding()}.
* @see com.sun.jna.Library#OPTION_STRING_ENCODING
*/
public static String getStringEncoding(Class<?> cls) {
Map<String, ?> options = getLibraryOptions(cls);
String encoding = (String) options.get(Library.OPTION_STRING_ENCODING);
return encoding != null ? encoding : getDefaultStringEncoding();
}
代码示例来源:origin: net.java.dev.jna/jna
/**
* Copy bytes out of string <code>value</code> to the location being
* pointed to, using the encoding indicated by {@link
* Native#getDefaultStringEncoding()}.
*
* @param offset byte offset from pointer at which characters in
* <code>value</code> must be set
* @param value <code>java.lang.String</code> value to set
*/
public void setString(long offset, String value) {
setString(offset, value, Native.getDefaultStringEncoding());
}
代码示例来源:origin: net.java.dev.jna/jna
static String getString(Pointer pointer, long offset) {
return getString(pointer, offset, getDefaultStringEncoding());
}
代码示例来源:origin: net.java.dev.jna/jna
/**
* Create a new <code>Function</code> that is linked with a native
* function that follows the given calling convention.
*
* <p>The allocated instance represents a pointer to the given
* function address, called with the given calling
* convention.
*
* @param functionAddress
* Address of the native function
* @param callFlags
* Function <a href="#callflags">call flags</a>
* @param encoding
* Encoding for conversion between Java and native strings.
*/
Function(Pointer functionAddress, int callFlags, String encoding) {
checkCallingConvention(callFlags & MASK_CC);
if (functionAddress == null
|| functionAddress.peer == 0) {
throw new NullPointerException("Function address may not be null");
}
this.functionName = functionAddress.toString();
this.callFlags = callFlags;
this.peer = functionAddress.peer;
this.options = Collections.EMPTY_MAP;
this.encoding = encoding != null
? encoding : Native.getDefaultStringEncoding();
}
代码示例来源:origin: net.java.dev.jna/jna
private NativeLibrary(String libraryName, String libraryPath, long handle, Map<String, ?> options) {
this.libraryName = getLibraryName(libraryName);
this.libraryPath = libraryPath;
this.handle = handle;
Object option = options.get(Library.OPTION_CALLING_CONVENTION);
int callingConvention = option instanceof Number ? ((Number)option).intValue() : Function.C_CONVENTION;
this.callFlags = callingConvention;
this.options = options;
this.encoding = (String)options.get(Library.OPTION_STRING_ENCODING);
if (this.encoding == null) {
this.encoding = Native.getDefaultStringEncoding();
}
// Special workaround for w32 kernel32.GetLastError
// Short-circuit the function to use built-in GetLastError access
if (Platform.isWindows() && "kernel32".equals(this.libraryName.toLowerCase())) {
synchronized(functions) {
Function f = new Function(this, "GetLastError", Function.ALT_CONVENTION, encoding) {
@Override
Object invoke(Object[] args, Class<?> returnType, boolean b, int fixedArgs) {
return Integer.valueOf(Native.getLastError());
}
@Override
Object invoke(Method invokingMethod, Class<?>[] paramTypes, Class<?> returnType, Object[] inArgs, Map<String, ?> options) {
return Integer.valueOf(Native.getLastError());
}
};
functions.put(functionKey("GetLastError", callFlags, encoding), f);
}
}
}
代码示例来源:origin: net.java.dev.jna/jna
this.callFlags = callFlags;
this.options = library.options;
this.encoding = encoding != null ? encoding : Native.getDefaultStringEncoding();
try {
this.peer = library.getSymbolAddress(functionName);
代码示例来源:origin: net.java.dev.jna/jna-platform
/**
* List extended attributes on file.
*
* @param fd file handle
* @return collection of extended attributes' names
* @throws IOException on any error except <code>ERANGE</code> which handled internally
*/
public static Collection<String> fListXAttr(int fd) throws IOException {
return fListXAttr(fd, Native.getDefaultStringEncoding());
}
代码示例来源:origin: net.java.dev.jna/jna-platform
/**
* Set or replace value of extended attribute.
*
* @param fd file handle
* @param name extended attribute name
* @param value value to set
* @throws IOException on any error
*/
public static void fSetXAttr(int fd, String name, String value) throws IOException {
fSetXAttr(fd, name, value, Native.getDefaultStringEncoding());
}
代码示例来源:origin: net.java.dev.jna/jna-platform
/**
* Get extended attribute value.
*
* @param path file path
* @param name extended attribute name
* @return extended attribute value
* @throws IOException on any error except <code>ERANGE</code> which handled internally
*/
public static String getXAttr(String path, String name) throws IOException {
return getXAttr(path, name, Native.getDefaultStringEncoding());
}
代码示例来源:origin: org.elasticsearch/jna
/** Returns an array of <code>String</code> based on a native array
* of <code>char*</code> or <code>wchar_t*</code> based on the
* <code>wide</code> parameter, using the given array length.
*
* @deprecated use {@link #getStringArray(long,int,String)} or {@link
* #getWideStringArray(long,int)} instead.
*/
@Deprecated
public String[] getStringArray(long offset, int length, boolean wide) {
return getStringArray(offset, length, wide ? NativeString.WIDE_STRING : Native.getDefaultStringEncoding());
}
代码示例来源:origin: org.elasticsearch/jna
/** <p>Returns an array of <code>String</code> based on a native array
* of <code>char *</code>, using the given array length.
* </p>
* The strings are decoded using the encoding returned by {@link
* Native#getDefaultStringEncoding()}.
*/
public String[] getStringArray(long offset, int length) {
return getStringArray(offset, length, Native.getDefaultStringEncoding());
}
内容来源于网络,如有侵权,请联系作者删除!