Refine search
private OSVR_ClientInterface getInterface(byte[] str) { PointerByReference pbr = new PointerByReference(); OsvrClientKitLibrary.osvrClientGetInterface((OsvrClientKitLibrary.OSVR_ClientContext)environment.getVRHardware().getVRSystem(), str, pbr); return new OSVR_ClientInterface(pbr.getValue()); }
public Pointer getValue() { return getPointer().getPointer(0); } }
public PointerByReference(Pointer value) { super(Native.POINTER_SIZE); setValue(value); }
try { int suggestionsCount = 0; PointerByReference suggestions = new PointerByReference(); final byte[] wordAsBytes = stringToBytes(word); if (wordAsBytes.length == 0 && word.length() > 0) { Pointer[] pointerArray = suggestions.getValue(). getPointerArray(0, suggestionsCount); long len = pointerArray[i].indexOf(0, (byte)0); if (len != -1) { if (len > Integer.MAX_VALUE) { "String improperly terminated: " + len); byte[] data = pointerArray[i].getByteArray(0, (int)len);
/** * Allocates align memory for use with O_DIRECT and returns native byte buffer. * @param fsBlockSize alignment, FS ans OS block size. * @param size capacity. * @return byte buffer, to be released by {@link #free(ByteBuffer)}. */ public static ByteBuffer allocate(int fsBlockSize, int size) { assert fsBlockSize > 0; assert size > 0; PointerByReference refToPtr = new PointerByReference(); int retVal = IgniteNativeIoLib.posix_memalign(refToPtr, new NativeLong(fsBlockSize), new NativeLong(size)); if (retVal != 0) throw new IgniteOutOfMemoryException("Failed to allocate memory: " + IgniteNativeIoLib.strerror(retVal)); return GridUnsafe.wrapPointer(Pointer.nativeValue(refToPtr.getValue()), size); }
// Original C declaration void allocate_buffer(char **bufp, int* lenp); // Equivalent JNA mapping void allocate_buffer(PointerByReference bufp, IntByReference lenp); // Usage PointerByReference pref = new PointerByReference(); IntByReference iref = new IntByReference(); lib.allocate_buffer(pref, iref); Pointer p = pref.getValue(); byte[] buffer = p.getByteArray(0, iref.getValue());
int strSize = 255; int result = 0; IntByReference byteIO = new IntByReference(); Pointer lngVarPtr1 = null;Pointer lngMemVar1 = null; Pointer lngVarPtr2 = null;Pointer lngMemVar2 = null; int lngMemLen1; int lngMemLen2; lngProcID = new PointerByReference(); int ThreadId = user32.GetWindowThreadProcessId(hWnd, lngProcID); lngProcHandle = Kernel32.OpenProcess(Kernel32.PROCESS_VM_OPERATION | Kernel32.PROCESS_VM_WRITE | Kernel32.PROCESS_VM_READ, false, lngProcID.getValue()); lngVarPtr1 = new Memory(strSize + 1); result = Kernel32.ReadProcessMemory(lngProcHandle, lngMemVar1, lngVarPtr1, lngMemLen1, byteIO); result = Kernel32.CloseHandle(lngProcHandle); return lngVarPtr1.getWideString(0);
public WebElement findElementByXPath(String using) { PointerByReference rawElement = new PointerByReference(); int result = lib.wdFindElementByXPath(driver, element, new WString(using), rawElement); handleErrorCode("xpath", using, result); return new InternetExplorerElement(lib, parent, rawElement.getValue()); }
private static List<String> getAttrNames(PointerByReference names) throws DrmaaException { List<String> namesList = new ArrayList<String>(); IntByReference size = new IntByReference(); int errnum; errnum = LibDrmaa.drmaa_get_num_attr_names(names.getValue(), size); checkError(errnum, "unable to get attribute names"); int num = size.getValue(); Memory value = new Memory(LibDrmaa.DRMAA_ATTR_BUFFER); for (int i = 1; i <= num; i++) { errnum = LibDrmaa.drmaa_get_next_attr_name(names.getValue(), value, LibDrmaa.DRMAA_ATTR_BUFFER_LEN); checkError(errnum, "unable to get attribute name " + i); if (errnum == LibDrmaa.DRMAA_ERRNO.DRMAA_ERRNO_NO_MORE_ELEMENTS) break; namesList.add(value.getString(0)); } return namesList; }
PointerByReference bufptr = new PointerByReference(); IntByReference entriesRead = new IntByReference(); IntByReference totalEntries = new IntByReference(); try { int rc = Netapi32.INSTANCE.NetLocalGroupEnum(serverName, 1, bufptr, LMCons.MAX_PREFERRED_LENGTH, entriesRead, totalEntries, null); if (LMErr.NERR_Success != rc || bufptr.getValue() == Pointer.NULL) { throw new Win32Exception(rc); LMAccess.LOCALGROUP_INFO_1 group = new LMAccess.LOCALGROUP_INFO_1(bufptr.getValue()); LMAccess.LOCALGROUP_INFO_1[] groups = (LOCALGROUP_INFO_1[]) group.toArray(entriesRead.getValue()); LocalGroup lgp = new LocalGroup(); if (lgpi.lgrui1_name != null) { lgp.name = lgpi.lgrui1_name.toString(); lgp.comment = lgpi.lgrui1_comment.toString(); if (bufptr.getValue() != Pointer.NULL) { int rc = Netapi32.INSTANCE.NetApiBufferFree(bufptr.getValue()); if (LMErr.NERR_Success != rc) { throw new Win32Exception(rc);
/** * Return the domain/workgroup join status for a computer. * @param computerName Computer name. * @return Join status. */ public static int getJoinStatus(String computerName) { PointerByReference lpNameBuffer = new PointerByReference(); IntByReference bufferType = new IntByReference(); try { int rc = Netapi32.INSTANCE.NetGetJoinInformation(computerName, lpNameBuffer, bufferType); if (LMErr.NERR_Success != rc) { throw new Win32Exception(rc); } return bufferType.getValue(); } finally { if (lpNameBuffer.getPointer() != null) { int rc = Netapi32.INSTANCE.NetApiBufferFree(lpNameBuffer.getValue()); if (LMErr.NERR_Success != rc) { throw new Win32Exception(rc); } } } }
public NativeArgs(String progname, String[] args) { // // Allocate some native memory to pass the args down to the native layer // argsCopy = new Memory[args.length + 2]; argvMemory = new Memory(argsCopy.length * Pointer.SIZE); // // Insert the program name as argv[0] // Memory arg = new Memory(progname.getBytes().length + 4); arg.setString(0, progname, false); argsCopy[0] = arg; for (int i = 0; i < args.length; i++) { arg = new Memory(args[i].getBytes().length + 1); arg.setString(0, args[i], false); argsCopy[i + 1] = arg; } argvMemory.write(0, argsCopy, 0, argsCopy.length); argvRef = new PointerByReference(argvMemory); argcRef = new IntByReference(args.length + 1); } String[] toStringArray() {
byte[] buff = affinity.toByteArray(); final int cpuSetSizeInBytes = buff.length; final Memory cpusetArray = new Memory(cpuSetSizeInBytes); try { cpusetArray.write(0, buff, 0, buff.length); final int ret = lib.sched_setaffinity(0, cpuSetSizeInBytes, new PointerByReference(cpusetArray)); if (ret < 0) { throw new IllegalStateException("sched_setaffinity((" + cpuSetSizeInBytes + ") , &(" + affinity + ") ) return " + ret); if (e.getErrorCode() != 22 || !Arrays.equals(buff, cpusetArray.getByteArray(0, cpuSetSizeInBytes))) { throw new IllegalStateException("sched_setaffinity((" + cpuSetSizeInBytes + ") , &(" + affinity + ") ) errorNo=" + e.getErrorCode(), e); throw new IllegalArgumentException("Cannot set zero affinity"); final IntByReference cpuset32 = new IntByReference(0); cpuset32.setValue(value); try { final int ret = lib.sched_setaffinity(0, Integer.SIZE / 8, cpuset32); if (ret < 0) throw new IllegalStateException("sched_setaffinity((" + Integer.SIZE / 8 + ") , &(" + Integer.toHexString(cpuset32.getValue()) + ") ) return " + ret); } catch (LastErrorException e) { throw new IllegalStateException("sched_setaffinity((" + Integer.SIZE / 8 + ") , &(" + Integer.toHexString(cpuset32.getValue()) + ") ) errorNo=" + e.getErrorCode(), e);
@Override public JobInfo wait(String jobId, long timeout) throws DrmaaException { Memory jobIdOut = new Memory(LibDrmaa.DRMAA_JOBNAME_BUFFER); IntByReference stat = new IntByReference(); PointerByReference rusage = new PointerByReference(); IntByReference exited = new IntByReference(); IntByReference exitStatus = new IntByReference(); IntByReference signaled = new IntByReference(); Memory signal = new Memory(LibDrmaa.DRMAA_SIGNAL_BUFFER); IntByReference coreDumped = new IntByReference(); IntByReference aborted = new IntByReference(); checkError(LibDrmaa.drmaa_wifaborted(aborted, stat.getValue(), getError(), LibDrmaa.DRMAA_ERROR_STRING_BUFFER_LEN)); return new JnaJobInfo(jobIdOut.getString(0), rusageMap, exited.getValue() != 0, exitStatus.getValue(), signaled.getValue() != 0, signal.getString(0), coreDumped.getValue() != 0, aborted.getValue() != 0);
final Memory cpusetArray = new Memory(cpuSetSizeInBytes); final PointerByReference cpuset = new PointerByReference(cpusetArray); try { final int ret = lib.sched_getaffinity(0, cpuSetSizeInBytes, cpuset); throw new IllegalStateException("sched_getaffinity((" + cpuSetSizeInBytes + ") , &(" + cpusetArray + ") ) return " + ret); ByteBuffer buff = cpusetArray.getByteBuffer(0, cpuSetSizeInBytes); return BitSet.valueOf(buff.array()); } catch (LastErrorException e) { final IntByReference cpuset32 = new IntByReference(0); try { final int ret = lib.sched_getaffinity(0, Integer.SIZE / 8, cpuset32); longs[0] = cpuset32.getValue() & 0xFFFFFFFFL; return BitSet.valueOf(longs); } catch (LastErrorException e) {
String[] toStringArray() { // // Unpack the native arguments back into a String array // List<String> args = new ArrayList<String>(); Pointer argv = argvRef.getValue(); for (int i = 1; i < argcRef.getValue(); i++) { Pointer arg = argv.getPointer(i * Pointer.SIZE); if (arg != null) { args.add(arg.getString(0, false)); } } return args.toArray(new String[args.size()]); } }
@Override public void write(final List<ByteBuf> buffers) { byte[] message = createCompleteMessage(buffers); PointerByReference outputBufferReference = new PointerByReference(); IntByReference outputSize = new IntByReference(); MongoDBCAPIHelper.client_invoke(clientPointer, message, outputBufferReference, outputSize, clientStatusPointer); curResponse = outputBufferReference.getValue().getByteBuffer(0, outputSize.getValue()); }
/** * Get information about a computer. * @param computerName * @return Domain or workgroup name. */ public static String getDomainName(String computerName) { PointerByReference lpNameBuffer = new PointerByReference(); IntByReference bufferType = new IntByReference(); try { int rc = Netapi32.INSTANCE.NetGetJoinInformation(computerName, lpNameBuffer, bufferType); if (LMErr.NERR_Success != rc) { throw new Win32Exception(rc); } // type of domain: bufferType.getValue() return lpNameBuffer.getValue().getString(0, true); } finally { if (lpNameBuffer.getPointer() != null) { int rc = Netapi32.INSTANCE.NetApiBufferFree(lpNameBuffer.getValue()); if (LMErr.NERR_Success != rc) { throw new Win32Exception(rc); } } } }
@Override public void putPointer(long offset, Pointer value) { PointerByReference ref = new PointerByReference(value); if (Platform.getPlatform().longSize() == 32) { putInt(offset, ref.getPointer().getInt(0)); } else { putLong(offset, ref.getPointer().getLong(0)); } }
PointerByReference errorRef = new PointerByReference(); int ret = libc_mac.sandbox_init(rules.toAbsolutePath().toString(), SANDBOX_NAMED, errorRef); Pointer errorBuf = errorRef.getValue(); RuntimeException e = new UnsupportedOperationException("sandbox_init(): " + errorBuf.getString(0)); libc_mac.sandbox_free_error(errorBuf); throw e;