com.sun.jna.Native.toStringList()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(3.6k)|赞(0)|评价(0)|浏览(123)

本文整理了Java中com.sun.jna.Native.toStringList()方法的一些代码示例,展示了Native.toStringList()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Native.toStringList()方法的具体详情如下:
包路径:com.sun.jna.Native
类名称:Native
方法名:toStringList

Native.toStringList介绍

[英]Converts a "list" of strings each null terminated into a List of String values. The end of the list is signaled by an extra NULL value at the end or by the end of the buffer.
[中]将每个以null结尾的字符串的“列表”转换为字符串值列表。列表的结尾由缓冲区结尾或结尾处的额外空值表示。

代码示例

代码示例来源:origin: net.java.dev.jna/jna

/**
 * Converts a "list" of strings each null terminated
 * into a {@link List} of {@link String} values. The end of the
 * list is signaled by an extra NULL value at the end or by the
 * end of the buffer.
 * @param buf The buffer containing the strings
 * @return A {@link List} of all the strings in the buffer
 * @see #toStringList(char[], int, int)
 */
public static List<String> toStringList(char[] buf) {
  return toStringList(buf, 0, buf.length);
}

代码示例来源:origin: org.elasticsearch/jna

/**
 * Converts a &quot;list&quot; of strings each null terminated
 * into a {@link List} of {@link String} values. The end of the
 * list is signaled by an extra NULL value at the end or by the
 * end of the buffer.
 * @param buf The buffer containing the strings
 * @return A {@link List} of all the strings in the buffer
 * @see #toStringList(char[], int, int)
 */
public static List<String> toStringList(char[] buf) {
  return toStringList(buf, 0, buf.length);
}

代码示例来源:origin: net.java.dev.jna/jna-platform

/**
 * Invokes the {@link Kernel32#QueryDosDevice(String, char[], int)} method
 * and parses the result
 * @param lpszDeviceName The device name
 * @param maxTargetSize The work buffer size to use for the query
 * @return The parsed result
 */
public static final List<String> queryDosDevice(String lpszDeviceName, int maxTargetSize) {
  char[] lpTargetPath = new char[maxTargetSize];
  int dwSize = Kernel32.INSTANCE.QueryDosDevice(lpszDeviceName, lpTargetPath, lpTargetPath.length);
  if (dwSize == 0) {
    throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
  }
  return Native.toStringList(lpTargetPath, 0, dwSize);
}

代码示例来源:origin: net.java.dev.jna/jna-platform

/**
 * Returns valid drives in the system.
 *
 * @return A {@link List} of valid drives.
 */
public static List<String> getLogicalDriveStrings() {
  DWORD dwSize = Kernel32.INSTANCE.GetLogicalDriveStrings(new DWORD(0), null);
  if (dwSize.intValue() <= 0) {
    throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
  }
  char buf[] = new char[dwSize.intValue()];
  dwSize = Kernel32.INSTANCE.GetLogicalDriveStrings(dwSize, buf);
  int bufSize = dwSize.intValue();
  if (bufSize <= 0) {
    throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
  }
  return Native.toStringList(buf, 0, bufSize);
}

代码示例来源:origin: net.java.dev.jna/jna-platform

/**
 * Invokes and parses the result of {@link Kernel32#GetVolumePathNamesForVolumeName(String, char[], int, IntByReference)}
 * @param lpszVolumeName The volume name
 * @return The parsed result
 * @throws Win32Exception If failed to retrieve the required information
 */
public static final List<String> getVolumePathNamesForVolumeName(String lpszVolumeName) {
  char[] lpszVolumePathNames = new char[WinDef.MAX_PATH + 1];
  IntByReference lpcchReturnLength = new IntByReference();
  if (!Kernel32.INSTANCE.GetVolumePathNamesForVolumeName(lpszVolumeName, lpszVolumePathNames, lpszVolumePathNames.length, lpcchReturnLength)) {
    int hr = Kernel32.INSTANCE.GetLastError();
    if (hr != WinError.ERROR_MORE_DATA) {
      throw new Win32Exception(hr);
    }
    int required = lpcchReturnLength.getValue();
    lpszVolumePathNames = new char[required];
    // this time we MUST succeed
    if (!Kernel32.INSTANCE.GetVolumePathNamesForVolumeName(lpszVolumeName, lpszVolumePathNames, lpszVolumePathNames.length, lpcchReturnLength)) {
      throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
    }
  }
  int bufSize = lpcchReturnLength.getValue();
  return Native.toStringList(lpszVolumePathNames, 0, bufSize);
}

相关文章

Native类方法