Tabnine Logo
Pointer
Code IndexAdd Tabnine to your IDE (free)

How to use
Pointer
in
com.sun.jna

Best Java code snippets using com.sun.jna.Pointer (Showing top 20 results out of 1,125)

Refine searchRefine arrow

  • PointerByReference
  • Native
  • Memory
  • Function
  • NativeLong
origin: MovingBlocks/Terasology

/**
 * Turn on the keyboard overlay. This is a keyboard that hovers in front of the user, that can be typed upon by
 * pointing the ray extending from the top of the controller at the key the user wants to press.
 * @param showingState - true or false
 * @return - true if successful. If this call fails, an error is logged.
 */
public static boolean setKeyboardOverlayShowing(boolean showingState) {
  int ret;
  if (showingState) {
    Pointer pointer = new Memory(3);
    pointer.setString(0, "mc");
    Pointer empty = new Memory(1);
    empty.setString(0, "");
    ret = vrOverlay.ShowKeyboard.apply(0, 0, pointer, 256, empty, (byte) 1, 0);
    keyboardShowing = 0 == ret; //0 = no error, > 0 see EVROverlayError
    if (ret != 0) {
      logger.error("VR Overlay Error: " + vrOverlay.GetOverlayErrorNameFromEnum.apply(ret).getString(0));
    }
  } else {
    try {
      vrOverlay.HideKeyboard.apply();
    } catch (Error e) {
      logger.error("Error bringing up keyboard overlay: " + e.toString());
    }
    keyboardShowing = false;
  }
  return keyboardShowing;
}
origin: apache/rocketmq

public void destroy() {
  for (ByteBuffer byteBuffer : availableBuffers) {
    final long address = ((DirectBuffer) byteBuffer).address();
    Pointer pointer = new Pointer(address);
    LibC.INSTANCE.munlock(pointer, new NativeLong(fileSize));
  }
}
origin: languagetool-org/languagetool

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);
origin: voldemort/voldemort

/**
 * Map the given region of the given file descriptor into memory.
 * Returns a Pointer to the newly mapped memory throws an
 * IOException on error.
 */
public static Pointer mmap(long len, int prot, int flags, int fildes, long off)
    throws IOException {
  // we don't really have a need to change the recommended pointer.
  Pointer addr = new Pointer(0);
  Pointer result = Delegate.mmap(addr,
                  new NativeLong(len),
                  prot,
                  flags,
                  fildes,
                  new NativeLong(off));
  if(Pointer.nativeValue(result) == -1) {
    if(logger.isDebugEnabled())
      logger.debug(errno.strerror());
  throw new IOException("mmap failed: " + errno.strerror());
  }
  return result;
}
origin: apache/ignite

/**
 * 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);
}
origin: kaitoy/pcap4j

private MacAddress getMacAddress(String nifName) {
 Pointer lpAdapter = NativePacketDllMappings.PacketOpenAdapter(nifName);
 long hFile = -1;
 if (lpAdapter != null) {
  if (Native.POINTER_SIZE == 4) {
   hFile = lpAdapter.getInt(0);
  } else {
   hFile = lpAdapter.getLong(0);
  }
 }
 if (hFile == -1L) {
  int err = Native.getLastError();
  logger.error("Unable to open the NIF {}, Error Code: {}", nifName, err);
  return null;
 }
 Memory mem = new Memory(NativePacketDllMappings.PACKET_OID_DATA_SIZE);
 mem.clear();
 PACKET_OID_DATA oidData = new PACKET_OID_DATA(mem);
 oidData.Length = new NativeLong(6L);
 oidData.Oid = new NativeLong(0x01010102L);
 int status = NativePacketDllMappings.PacketRequest(lpAdapter, 0, oidData);
 NativePacketDllMappings.PacketCloseAdapter(lpAdapter);
 if (status == 0) {
  logger.error("Failed to retrieve the link layer address of the NIF: {}", nifName);
  return null;
 } else {
  return MacAddress.getByAddress(oidData.Data);
 }
}
origin: net.java.dev.jna/jna

  Structure s = (Structure)currentValue;
  if (Structure.ByReference.class.isAssignableFrom(type)) {
    s = Structure.updateStructureByReference((Class<Structure>) type, s, getPointer(offset));
  } else {
    s.useMemory(this, (int)offset, true);
  result = Function.valueOf(getInt(offset) != 0);
} else if (type == byte.class || type == Byte.class) {
  result =  Byte.valueOf(getByte(offset));
} else if (type == short.class || type == Short.class) {
  result = Short.valueOf(getShort(offset));
} else if (type == char.class || type == Character.class) {
  result = Character.valueOf(getChar(offset));
} else if (type == int.class || type == Integer.class) {
  result = Integer.valueOf(getInt(offset));
} else if (type == long.class || type == Long.class) {
  result = Long.valueOf(getLong(offset));
} else if (type == float.class || type == Float.class) {
  result = Float.valueOf(getFloat(offset));
} else if (type == double.class || type == Double.class) {
  result = Double.valueOf(getDouble(offset));
} else if (Pointer.class.isAssignableFrom(type)) {
  Pointer p = getPointer(offset);
  if (p != null) {
    Pointer oldp = currentValue instanceof Pointer
  Pointer p = getPointer(offset);
  result = p != null ? p.getString(0) : null;
} else if (type == WString.class) {
origin: org.elasticsearch/elasticsearch

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;
origin: jMonkeyEngine/jmonkeyengine

@Override
public HmdType getType() {
  if( vrsystemFunctions != null ) {      
    Pointer str1 = new Memory(128);
    Pointer str2 = new Memory(128);
    String completeName = "";
    vrsystemFunctions.GetStringTrackedDeviceProperty.apply(JOpenVRLibrary.k_unTrackedDeviceIndex_Hmd,
                                JOpenVRLibrary.ETrackedDeviceProperty.ETrackedDeviceProperty_Prop_ManufacturerName_String,
                                str1, 128, hmdErrorStore);
    if( hmdErrorStore.getValue() == 0 ) completeName += str1.getString(0);
    vrsystemFunctions.GetStringTrackedDeviceProperty.apply(JOpenVRLibrary.k_unTrackedDeviceIndex_Hmd,
                                JOpenVRLibrary.ETrackedDeviceProperty.ETrackedDeviceProperty_Prop_ModelNumber_String,
                                str2, 128, hmdErrorStore);
    if( hmdErrorStore.getValue() == 0 ) completeName += " " + str2.getString(0);
    if( completeName.length() > 0 ) {
      completeName = completeName.toLowerCase(Locale.ENGLISH).trim();
origin: com.sun.jna/jna

private static class MemberOrder {
  public int first;
  public int middle;
  public int last;
}

origin: apache/nifi

if (eventHandle.getPointer().getInt(0) == WEvtApi.EvtSubscribeErrors.ERROR_EVT_QUERY_RESULT_STALE) {
  logger.error(MISSING_EVENT_MESSAGE);
} else {
  logger.error(RECEIVED_THE_FOLLOWING_WIN32_ERROR + eventHandle.getPointer().getInt(0));
  int newMaxSize = used.getInt(0);
  buffer = new Memory(size);
  wEvtApi.EvtRender(null, eventHandle, WEvtApi.EvtRenderFlags.EVENT_XML, size, buffer, used, propertyCount);
  int usedBytes = used.getInt(0);
  String string = StandardCharsets.UTF_16LE.decode(buffer.getByteBuffer(0, usedBytes)).toString();
  if (string.endsWith("\u0000")) {
origin: net.java.dev.jna/platform

public HRESULT GetTypeComp(
/* [out] */ITypeComp.ByReference pTComp) {
  Pointer vptr = this.getPointer().getPointer(0);
  Function func = Function.getFunction(vptr.getPointer(32));
  PointerByReference ppTComp = new PointerByReference();
  int hr = func.invokeInt(new Object[] { this.getPointer(), ppTComp });
  pTComp.setPointer(ppTComp.getPointer());
  return new HRESULT(hr);
}
origin: net.java.dev.jna/platform

public HRESULT GetTypeInfo(
/* [in] */UINT index,
/* [out] */ITypeInfo.ByReference pTInfo) {
  Pointer vptr = this.getPointer().getPointer(0);
  Function func = Function.getFunction(vptr.getPointer(16));
  PointerByReference ppTInfo = new PointerByReference();
  int hr = func.invokeInt(new Object[] { this.getPointer(), index, ppTInfo });
  pTInfo.setPointer(ppTInfo.getValue());
  return new HRESULT(hr);
}
origin: kaitoy/pcap4j

PointerByReference headerPP = new PointerByReference();
PointerByReference dataPP = new PointerByReference();
int rc = NativeMappings.pcap_next_ex(handle, headerPP, dataPP);
switch (rc) {
  throw new TimeoutException();
 case 1:
  Pointer headerP = headerPP.getValue();
  Pointer dataP = dataPP.getValue();
  if (headerP == null || dataP == null) {
  return dataP.getByteArray(0, pcap_pkthdr.getCaplen(headerP));
 case -1:
  throw new PcapNativeException("Error occurred in pcap_next_ex(): " + getError(), rc);
origin: org.elasticsearch/elasticsearch

  throw new UnsupportedOperationException("seccomp unavailable: seccomp(BOGUS_OPERATION) returned " + ret);
} else {
  int errno = Native.getLastError();
  switch (errno) {
    case ENOSYS: break; // ok
  throw new UnsupportedOperationException("seccomp unavailable: seccomp(SECCOMP_SET_MODE_FILTER, BOGUS_FLAG) returned " + ret);
} else {
  int errno = Native.getLastError();
  switch (errno) {
    case ENOSYS: break; // ok
  throw new UnsupportedOperationException("seccomp unavailable: prctl(BOGUS_OPTION) returned " + ret);
} else {
  int errno = Native.getLastError();
  switch (errno) {
    case ENOSYS: break; // ok
long pointer = Pointer.nativeValue(prog.getPointer());
if (linux_syscall(arch.seccomp, SECCOMP_SET_MODE_FILTER, SECCOMP_FILTER_FLAG_TSYNC, new NativeLong(pointer)) != 0) {
  method = 0;
  int errno1 = Native.getLastError();
origin: net.java.dev.jna/jna

if (value instanceof Pointer) {
  if (dstType == String.class) {
    value = ((Pointer)value).getString(0, encoding);
    value = new WString(((Pointer)value).getWideString(0));
    value = ((Pointer)value).getStringArray(0, encoding);
    value = ((Pointer)value).getWideStringArray(0);
      Structure s = Structure.newInstance((Class<? extends Structure>) dstType);
      byte[] buf = new byte[s.size()];
      ((Pointer)value).read(0, buf, 0, buf.length);
      s.getPointer().write(0, buf, 0, buf.length);
      s.read();
      value = s;
  value = Function.valueOf(((Number)value).intValue() != 0);
origin: net.java.dev.jna/jna

/**
 * Indirect the native pointer as a pointer to <code>long</code>.  This is
 * equivalent to the expression
 * <code>*((long *)((char *)Pointer + offset))</code>.
 *
 * @param offset byte offset from pointer to perform the indirection
 * @return the <code>long</code> value being pointed to
 */
public NativeLong getNativeLong(long offset) {
  return new NativeLong(NativeLong.SIZE == 8 ? getLong(offset) : getInt(offset));
}
origin: org.elasticsearch/elasticsearch

  logger.warn("Unable to lock JVM memory. Failed to set working set size. Error code {}", Native.getLastError());
} else {
  JNAKernel32Library.MemoryBasicInformation memInfo = new JNAKernel32Library.MemoryBasicInformation();
  long address = 0;
  while (kernel.VirtualQueryEx(process, new Pointer(address), memInfo, memInfo.size()) != 0) {
    boolean lockable = memInfo.State.longValue() == JNAKernel32Library.MEM_COMMIT
        && (memInfo.Protect.longValue() & JNAKernel32Library.PAGE_NOACCESS) != JNAKernel32Library.PAGE_NOACCESS
        && (memInfo.Protect.longValue() & JNAKernel32Library.PAGE_GUARD) != JNAKernel32Library.PAGE_GUARD;
    if (lockable) {
      kernel.VirtualLock(memInfo.BaseAddress, new SizeT(memInfo.RegionSize.longValue()));
origin: MovingBlocks/Terasology

private static boolean initOpenVROverlay() {
  vrOverlay = new VR_IVROverlay_FnTable(JOpenVRLibrary.VR_GetGenericInterface(JOpenVRLibrary.IVROverlay_Version, hmdErrorStore));
  if (hmdErrorStore.get(0) == 0) {
    vrOverlay.setAutoSynch(false);
    vrOverlay.read();
    logger.info("OpenVR Overlay initialized OK.");
  } else {
    String errorString = jopenvr.JOpenVRLibrary.VR_GetVRInitErrorAsEnglishDescription(hmdErrorStore.get(0)).getString(0);
    logger.info("vrOverlay initialization failed:" + errorString);
    return false;
  }
  return true;
}
origin: net.java.dev.jna/jna

private void init(Pointer[] els) {
  elements = new Memory(Native.POINTER_SIZE * els.length);
  elements.write(0, els, 0, els.length);
  write();
}
com.sun.jnaPointer

Javadoc

An abstraction for a native pointer data type. A Pointer instance represents, on the Java side, a native pointer. The native pointer could be any type of native pointer. Methods such as write, read, getXXX, and setXXX, provide means to access memory underlying the native pointer.

While a constructor exists to create a Pointer from an integer value, it's not generally a good idea to be creating pointers that way.

Most used methods

  • getString
    Copy native memory to a Java String. If wide is true, access the memory as an array of wchar_t, othe
  • <init>
    Create from native pointer. Don't use this unless you know what you're doing.
  • getByteArray
    Read a native array of bytes of size arraySize from the given offset from this Pointer.
  • getInt
    Indirect the native pointer as a pointer to int. This is equivalent to the expression*((jint *)((cha
  • write
    Indirect the native pointer, copying into memory pointed to by native pointer, from the specified ar
  • nativeValue
    Set the native peer value. Use with caution.
  • getPointer
    Indirect the native pointer as a pointer to pointer. This is equivalent to the expression*((void **)
  • getLong
    Indirect the native pointer as a pointer to long. This is equivalent to the expression*((jlong *)((c
  • createConstant
    Convenience constant, equivalent to (void*)CONSTANT.
  • read
    Indirect the native pointer, copying from memory pointed to by native pointer, into the specified ar
  • setInt
    Set value at location being pointed to. This is equivalent to the expression *((jint *)((char *)Poin
  • equals
    Compares this Pointer to the specified object.
  • setInt,
  • equals,
  • setPointer,
  • setLong,
  • getByteBuffer,
  • setString,
  • getByte,
  • setByte,
  • share,
  • getIntArray

Popular in Java

  • Reading from database using SQL prepared statement
  • setContentView (Activity)
  • addToBackStack (FragmentTransaction)
  • scheduleAtFixedRate (Timer)
  • Graphics2D (java.awt)
    This Graphics2D class extends the Graphics class to provide more sophisticated control overgraphics
  • OutputStream (java.io)
    A writable sink for bytes.Most clients will use output streams that write data to the file system (
  • Path (java.nio.file)
  • Scanner (java.util)
    A parser that parses a text string of primitive types and strings with the help of regular expressio
  • Stream (java.util.stream)
    A sequence of elements supporting sequential and parallel aggregate operations. The following exampl
  • Options (org.apache.commons.cli)
    Main entry-point into the library. Options represents a collection of Option objects, which describ
  • Github Copilot alternatives
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now