Java Code Examples for com.sun.jna.Pointer#NULL

The following examples show how to use com.sun.jna.Pointer#NULL . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JnaEventHandle.java    From jaybird with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Releases the native memory held by this event handle.
 *
 * @param clientLibrary The client library instance
 */
public synchronized void releaseMemory(FbClientLibrary clientLibrary) {
    if (size == -1) return;
    try {
        if (eventBuffer.getValue() != Pointer.NULL) {
            clientLibrary.isc_free(eventBuffer.getValue());
            eventBuffer.setValue(Pointer.NULL);
        }
        if (resultBuffer.getValue() != Pointer.NULL) {
            clientLibrary.isc_free(resultBuffer.getValue());
            resultBuffer.setValue(Pointer.NULL);
        }
    } finally {
        size = -1;
    }
}
 
Example 2
Source File: WindowsCryptUtils.java    From consulo with Apache License 2.0 6 votes vote down vote up
/**
 * Protect the specified byte range
 *
 * @param data the data to protect
 * @return the the protected form the data
 */
public static byte[] protect(byte[] data) throws MasterPasswordUnavailableException {
  if(data.length == 0) {
    return data;
  }
  Memory input = new Memory(data.length);
  input.write(0, data, 0, data.length);
  Crypt32.DATA_BLOB in = new Crypt32.DATA_BLOB();
  in.cbData = new W32API.DWORD(data.length);
  in.pbData = input;
  Crypt32.DATA_BLOB out = new Crypt32.DATA_BLOB();
  out.pbData = Pointer.NULL;
  Crypt32 crypt = Crypt32.INSTANCE;
  Kernel32 kernel = Kernel32.INSTANCE;
  boolean rc = crypt.CryptProtectData(in, "Master Key", Pointer.NULL, Pointer.NULL, Pointer.NULL, new W32API.DWORD(0), out);
  if (!rc) {
    W32API.DWORD drc = kernel.GetLastError();
    throw new MasterPasswordUnavailableException("CryptProtectData failed: " + drc.intValue());
  }
  else {
    byte[] output = new byte[out.cbData.intValue()];
    out.pbData.read(0, output, 0, output.length);
    kernel.LocalFree(out.pbData);
    return output;
  }
}
 
Example 3
Source File: WindowsCryptUtils.java    From consulo with Apache License 2.0 6 votes vote down vote up
/**
 * Unprotect the specified byte range
 *
 * @param data the data to protect
 * @return the the protected form the data
 */
public static byte[] unprotect(byte[] data) throws MasterPasswordUnavailableException {
  if(data.length == 0) {
    return data;
  }
  Memory input = new Memory(data.length);
  input.write(0, data, 0, data.length);
  Crypt32.DATA_BLOB in = new Crypt32.DATA_BLOB();
  in.cbData = new W32API.DWORD(data.length);
  in.pbData = input;
  Crypt32.DATA_BLOB out = new Crypt32.DATA_BLOB();
  out.pbData = Pointer.NULL;
  Crypt32 crypt = Crypt32.INSTANCE;
  Kernel32 kernel = Kernel32.INSTANCE;
  boolean rc = crypt.CryptUnprotectData(in, Pointer.NULL, Pointer.NULL, Pointer.NULL, Pointer.NULL, new W32API.DWORD(0), out);
  if (!rc) {
    W32API.DWORD drc = kernel.GetLastError();
    throw new MasterPasswordUnavailableException("CryptProtectData failed: " + drc.intValue());
  }
  else {
    byte[] output = new byte[out.cbData.intValue()];
    out.pbData.read(0, output, 0, output.length);
    kernel.LocalFree(out.pbData);
    return output;
  }
}
 
Example 4
Source File: OSXNotifier.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private Pointer[] createFSEventStream() throws IOException {
    final Pointer root = cf.CFStringCreateWithCString(Pointer.NULL,"/",ENC_MAC_ROMAN);  //NOI18N
    if (root == Pointer.NULL) {
        throw new IOException("Path creation failed.");     //NOI18N
    }
    final Pointer arr = cf.CFArrayCreateMutable(Pointer.NULL, new NativeLong(1), Pointer.NULL);
    if (arr == Pointer.NULL) {
        throw new IOException("Path list creation failed.");    //NOI18N
    }
    cf.CFArrayAppendValue(arr, root);

    final Pointer eventStream = cs.FSEventStreamCreate(Pointer.NULL, callback, Pointer.NULL, arr, kFSEventStreamEventIdSinceNow, LATENCY, kFSEventStreamCreateFlagNoDefer);
    if (eventStream == Pointer.NULL) {
        throw new IOException("Creation of FSEventStream failed."); //NOI18N
    }
    final Pointer loop = cf.CFRunLoopGetCurrent();
    if (eventStream == Pointer.NULL) {
        throw new IOException("Cannot find run loop for caller.");  //NOI18N
    }
    final Pointer kCFRunLoopDefaultMode = findDefaultMode(loop);
    if (kCFRunLoopDefaultMode == null) {
        throw new IOException("Caller has no defaul run loop mode.");   //NOI18N
    }
    cs.FSEventStreamScheduleWithRunLoop(eventStream, loop, kCFRunLoopDefaultMode);
    if (LOG.isLoggable(DEBUG_LOG_LEVEL)) {
        LOG.log(DEBUG_LOG_LEVEL, getStreamDescription(eventStream));
    }
    cs.FSEventStreamStart(eventStream);
    return new Pointer[] {eventStream, loop};
}
 
Example 5
Source File: OSXNotifier.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private Pointer findDefaultMode(final Pointer runLoop) {
    final Pointer modes = cf.CFRunLoopCopyAllModes(runLoop);
    if (modes != Pointer.NULL) {
        final int modesCount = cf.CFArrayGetCount(modes).intValue();
        for (int i=0; i< modesCount; i++) {
            final Pointer mode = cf.CFArrayGetValueAtIndex(modes, new NativeLong(i));
            if (mode != Pointer.NULL && DEFAULT_RUN_LOOP_MODE.equals(cf.CFStringGetCStringPtr(mode, ENC_MAC_ROMAN))) {
                return mode;
            }
        }
    }
    return null;
}
 
Example 6
Source File: Win7TaskBar.java    From consulo with Apache License 2.0 5 votes vote down vote up
static void setOverlayIcon(IdeFrame frame, Object icon, boolean dispose) {
  if (!isEnabled()) {
    return;
  }

  if (icon == null) {
    icon = Pointer.NULL;
  }
  mySetOverlayIcon.invokeInt(new Object[]{myInterfacePointer, getHandle(frame), icon, Pointer.NULL});
  if (dispose) {
    User32.INSTANCE.DestroyIcon((WinDef.HICON)icon);
  }
}
 
Example 7
Source File: Nc4prototypes.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public static byte[] contents(Vlen_t v) {
  if (v.p == Pointer.NULL)
    return null;
  return v.p.getByteArray(0, v.len);
}
 
Example 8
Source File: OSXNotifier.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private String getStreamDescription(final Pointer eventStream) {
    final Pointer desc = cs.FSEventStreamCopyDescription(eventStream);
    return desc == Pointer.NULL ? "" : cf.CFStringGetCStringPtr(desc, ENC_MAC_ROMAN);   //NOI18N
}