Package com.sun.jna

Examples of com.sun.jna.Memory


        if(Functions.isWindows())     return null;

        String filename = link.getAbsolutePath();
        try {
            for (int sz=512; sz < 65536; sz*=2) {
                Memory m = new Memory(sz);
                int r = LIBC.readlink(filename,m,new NativeLong(sz));
                if (r<0) {
                    int err = Native.getLastError();
                    if (err==22/*EINVAL --- but is this really portable?*/)
                        return null; // this means it's not a symlink
                    throw new IOException("Failed to readlink "+link+" error="+ err+" "+ LIBC.strerror(err));
                }
                if (r==sz)
                    continue;   // buffer too small

                byte[] buf = new byte[r];
                m.read(0,buf,0,r);
                return new String(buf);
            }
            // something is wrong. It can't be this long!
            throw new IOException("Symlink too long: "+link);
        } catch (LinkageError e) {
View Full Code Here


* <p>NOTE: this class would ideally be replaced by a generic.
*/
public abstract class ByReference extends PointerType {
   
    protected ByReference(int dataSize) {
        setPointer(new Memory(dataSize));
    }
View Full Code Here

    String accountName = "Administrator";
    assertFalse(Advapi32.INSTANCE.LookupAccountName(
        null, accountName, null, pSid, null, pDomain, peUse));
    assertEquals(W32Errors.ERROR_INSUFFICIENT_BUFFER, Kernel32.INSTANCE.GetLastError());
    assertTrue(pSid.getValue() > 0);
    Memory sidMemory = new Memory(pSid.getValue());
    PSID pSidMemory = new PSID(sidMemory);
    char[] referencedDomainName = new char[pDomain.getValue() + 1];
    assertTrue(Advapi32.INSTANCE.LookupAccountName(
        null, accountName, pSidMemory, pSid, referencedDomainName, pDomain, peUse));
    assertEquals(SID_NAME_USE.SidTypeUser, peUse.getPointer().getInt(0));
View Full Code Here

      HANDLE h = Advapi32.INSTANCE.RegisterEventSource(null, jnaEventSource);     
      IntByReference before = new IntByReference();
      assertTrue(Advapi32.INSTANCE.GetNumberOfEventLogRecords(h, before));
      assertNotNull(h);
      String s[] = { "JNA", "Event" };
      Memory m = new Memory(4);
      m.setByte(0, (byte) 1);
      m.setByte(1, (byte) 2);
      m.setByte(2, (byte) 3);
      m.setByte(3, (byte) 4);
      assertTrue(Advapi32.INSTANCE.ReportEvent(h, WinNT.EVENTLOG_ERROR_TYPE, 0, 0, null, 2, 4, s, m));
      IntByReference after = new IntByReference();
      assertTrue(Advapi32.INSTANCE.GetNumberOfEventLogRecords(h, after));
      assertTrue(before.getValue() < after.getValue());
      assertFalse(h.equals(WinBase.INVALID_HANDLE_VALUE));
View Full Code Here

   
    public void testReadEventLog() {
      HANDLE h = Advapi32.INSTANCE.OpenEventLog(null, "Application");
      IntByReference pnBytesRead = new IntByReference();
      IntByReference pnMinNumberOfBytesNeeded = new IntByReference();
      Memory buffer = new Memory(1);
      assertFalse(Advapi32.INSTANCE.ReadEventLog(h,
          WinNT.EVENTLOG_SEQUENTIAL_READ | WinNT.EVENTLOG_BACKWARDS_READ,
          0, buffer, (int) buffer.size(), pnBytesRead, pnMinNumberOfBytesNeeded));
      assertEquals(W32Errors.ERROR_INSUFFICIENT_BUFFER, Kernel32.INSTANCE.GetLastError());
      assertTrue(pnMinNumberOfBytesNeeded.getValue() > 0);
      assertTrue(Advapi32.INSTANCE.CloseEventLog(h));
    }
View Full Code Here

   
    public void testReadEventLogEntries() {
      HANDLE h = Advapi32.INSTANCE.OpenEventLog(null, "Application");
      IntByReference pnBytesRead = new IntByReference();
      IntByReference pnMinNumberOfBytesNeeded = new IntByReference();
      Memory buffer = new Memory(1024 * 64);
      // shorten test, avoid iterating through all events
      int maxReads = 3;      
      int rc = 0;
      while(true) {
            if (maxReads-- <= 0)
                break;     
            if (! Advapi32.INSTANCE.ReadEventLog(h,
                                                 WinNT.EVENTLOG_SEQUENTIAL_READ | WinNT.EVENTLOG_FORWARDS_READ,
                                                 0, buffer, (int) buffer.size(), pnBytesRead, pnMinNumberOfBytesNeeded)) {
                rc = Kernel32.INSTANCE.GetLastError();
                if (rc == W32Errors.ERROR_INSUFFICIENT_BUFFER) {
                    buffer = new Memory(pnMinNumberOfBytesNeeded.getValue());
                    rc = 0;
                    continue;
                }         
                break;
            }
View Full Code Here

        final GENERIC_MAPPING mapping = new GENERIC_MAPPING();
        mapping.genericRead = new DWORD(FILE_GENERIC_READ);
        mapping.genericWrite = new DWORD(FILE_GENERIC_WRITE);
        mapping.genericExecute = new DWORD(FILE_GENERIC_EXECUTE);
        mapping.genericAll = new DWORD(FILE_ALL_ACCESS);
        final Memory securityDescriptorMemoryPointer = new Memory(1);

        final PRIVILEGE_SET privileges = new PRIVILEGE_SET(1);
        privileges.PrivilegeCount = new DWORD(0);
        final DWORDByReference privilegeLength = new DWORDByReference(new DWORD(privileges.size()));
        final DWORDByReference grantedAccess = new DWORDByReference();
View Full Code Here

      return null;

    if (bufferLength == 0)
      return new ArrayList<String>(0);

    Memory valueBuffer = new Memory(bufferLength);
    long valueLength = XAttr.INSTANCE.listxattr(path, valueBuffer, bufferLength, 0);

    if (valueLength < 0)
      return null;

    return decodeStringSequence(valueBuffer.getByteBuffer(0, valueLength));
  }
View Full Code Here

    long bufferLength = XAttr.INSTANCE.getxattr(path, name, null, 0, 0, 0);

    if (bufferLength < 0)
      return null;

    Memory valueBuffer = new Memory(bufferLength);
    long valueLength = XAttr.INSTANCE.getxattr(path, name, valueBuffer, bufferLength, 0, 0);

    if (valueLength < 0)
      return null;

    return decodeString(valueBuffer.getByteBuffer(0, valueLength - 1));
  }
View Full Code Here

    return decodeString(valueBuffer.getByteBuffer(0, valueLength - 1));
  }

  public static int setXAttr(String path, String name, String value) {
    Memory valueBuffer = encodeString(value);
    return XAttr.INSTANCE.setxattr(path, name, valueBuffer, valueBuffer.size(), 0, 0);
  }
View Full Code Here

TOP

Related Classes of com.sun.jna.Memory

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.