@Override public String toString() { return Native.toString(buf); } }
/** * 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()); }
/** * 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)); }
/** * 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; } }
/** * @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); }
/** * @return The module path. */ public String szExePath() { return Native.toString(this.szExePath); } }
/** * Gets the dbcc_name. * * @return the dbcc_name */ public String getDbcc_name() { return Native.toString(this.dbcc_name); } }
/** * @return The module name. */ public String szModule() { return Native.toString(this.szModule); }
@Override public String toString() { return Native.toString(buf); } }
/** * Name of the key. * @return String. */ public String getName() { return Native.toString(Name); }
/** * @return String containing the file name */ public String getFileName() { return Native.toString(cFileName); }
/** * @return String containing the alternate file name */ public String getAlternateFileName() { return Native.toString(cAlternateFileName); } }
/** * Name of the key. * @return String. */ public String getName() { return Native.toString(Name); }
/** * 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()); }
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); } }
@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)); }
@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); }
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()) : ""; } }
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); }
/** * 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); }