Java com.sun.jna.ptr.PointerByReference 代码实例

・12 分钟阅读

以下是展示如何使用com.sun.jna.ptr.PointerByReference的最佳示例。 我们使用了代码质量辨别算法从开源项目中提取出了最佳的优秀示例。

实例 1


/**
 * Gets the pointer to the the value of the specified property.
 *
 * @param property The name of the property to get.
 *
 * @return A java pointer.
 */    
public Pointer getPointer(String property) {
    logger.entering("GObject", "getPointer", new Object[] { property });
    GObjectAPI.GParamSpec propertySpec = findProperty(property);
    if (propertySpec == null) {
        throw new IllegalArgumentException("Unknown property: " + property);
    }
    PointerByReference refPtr = new PointerByReference();
    GOBJECT_API.g_object_get(this, property, refPtr, null);
    Pointer ptr = refPtr.getValue();
    return ptr;
}
 

实例 2


/**
 * Unprotect a blob of data.
 * @param data
 *  Data to unprotect.
 * @param entropy
 *  Optional entropy.
 * @param flags
 *  Optional flags.
 * @param prompt
 *  Optional prompt structure.
 * @return
 *  Unprotected blob of data.
 */
public static byte[] cryptUnprotectData(byte[] data, byte[] entropy, int flags, 
                CRYPTPROTECT_PROMPTSTRUCT prompt) {
        DATA_BLOB pDataIn = new DATA_BLOB(data);
        DATA_BLOB pDataUnprotected = new DATA_BLOB();
        DATA_BLOB pEntropy = (entropy == null) ? null : new DATA_BLOB(entropy);
        PointerByReference pDescription = new PointerByReference();
        try {
        if (! Crypt32.INSTANCE.CryptUnprotectData(pDataIn, pDescription, 
                        pEntropy, null, prompt, flags, pDataUnprotected)) {
                throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
        }
        return pDataUnprotected.getData();
        } finally {
                if (pDataUnprotected.pbData != null) {
                        Kernel32.INSTANCE.LocalFree(pDataUnprotected.pbData);
                }
                if (pDescription.getValue() != null) {
                        Kernel32.INSTANCE.LocalFree(pDescription.getValue());
                }
        }
}
 

实例 3


public HlStream packageCreateStream(DirectoryItem item) {
    PointerByReference temp = new PointerByReference();
    if (lib.packageCreateStream(item, temp)) {
        return new HlStream(HlLib.getLibrary().getCurrentlyBoundPackage(), temp.getValue());
    } else {
        logger.error("Failed creating a stream for package of item: {}", this.itemGetPath(item));
        return null;
    }
}
 

实例 4


private void register(OSXHotKey hotKey) {
    KeyStroke keyCode = hotKey.keyStroke;
    EventHotKeyID.ByValue hotKeyReference = new EventHotKeyID.ByValue();
    int id = idSeq++;
    hotKeyReference.id = id;
    hotKeyReference.signature = OS_TYPE("hk" + String.format("%02d", id));
    PointerByReference gMyHotKeyRef = new PointerByReference();
    int status = Lib.RegisterEventHotKey(KeyMap.getKeyCode(keyCode), KeyMap.getModifier(keyCode), hotKeyReference, Lib.GetEventDispatcherTarget(), 0, gMyHotKeyRef);
    if (status != 0) {
        logger.warning("Could not register HotKey: " + keyCode + ". Error code: " + status);
        return;
    }
    if (gMyHotKeyRef.getValue() == null) {
        logger.warning("HotKey returned null handler reference");
        return;
    }
    hotKey.handler = gMyHotKeyRef;
    logger.info("Registered hotkey: " + keyCode);
    hotKeys.put(id, hotKey);
}
 

实例 5


public static List<ProvisioningProfileInfo> read(PointerByReference ptr, int count)
    throws Exception {
  Pointer ptrs = ptr.getValue();
  ByReference profileRef = (ByReference) Structure.newInstance(ByReference.class, ptrs);
  profileRef.read();
  ByReference[] profilesArray = (ByReference[]) profileRef.toArray(count);
  List<ProvisioningProfileInfo> res = new ArrayList<ProvisioningProfileInfo>();
  for (sdk_idevice_provisioning_profile_info_t profile : profilesArray) {
    ProvisioningProfileInfo info = new ProvisioningProfileInfo(profile);
    res.add(info);
  }
  return res;
}
 

实例 6


/**
 * Creates a new authenticator.
 *
 * @param serviceName
 *      PAM service name. This corresponds to the service name that shows up
 *      in the PAM configuration,
 */
public PAM(String serviceName) throws PAMException {
    pam_conv conv = new pam_conv(new PamCallback() {
        public int callback(int num_msg, Pointer msg, Pointer resp, Pointer _) {
            LOGGER.fine("pam_conv num_msg="+num_msg);
            if(password==null)
                return PAM_CONV_ERR;
            // allocates pam_response[num_msg]. the caller will free this
            Pointer m = libc.calloc(pam_response.SIZE,num_msg);
            resp.setPointer(0,m);
            for( int i=0; i<num_msg; i++ ) {
                pam_message pm = new pam_message(msg.getPointer(POINTER_SIZE*i));
                LOGGER.fine(pm.msg_style+":"+pm.msg);
                if(pm.msg_style==PAM_PROMPT_ECHO_OFF) {
                    pam_response r = new pam_response(m.share(pam_response.SIZE*i));
                    r.setResp(password);
                    r.write(); // write to (*resp)[i]
                }
            }
            return PAM_SUCCESS;
        }
    });
    PointerByReference phtr = new PointerByReference();
    check(libpam.pam_start(serviceName,null,conv,phtr), "pam_start failed");
    pht = new pam_handle_t(phtr.getValue());
}
 

实例 7


public void writeMovie(ImagePlus image, String path, int frameRate, int bitRate) throws IOException {
        final int STREAM_PIX_FMT = AVUTIL.PIX_FMT_YUV420P;
        //int swsFlags = SWScaleLibrary.SWS_BICUBIC;
        AVOutputFormat fmt = null;
        int i;
        ImageStack stack;
        stack = image.getStack();
        start("Writing " + path);
        /* initialize libavcodec, and register all codecs and formats */
        avFormat.av_register_all();
        /* auto detect the output format from the name. default is
           mpeg. */
        fmt = avFormat.guess_format(null, new File(path).getName(), null);
        if (fmt == null) {
                IJ.log("Could not deduce output format from file extension: using MPEG.");
                fmt = avFormat.guess_format("mpeg2video", null, null);
        }
        if (fmt == null)
                throw new IOException("Could not find suitable output format");
        /* allocate the output media context */
        formatContext = avFormat.av_alloc_format_context();
        if (formatContext == null)
                throw new OutOfMemoryError("Could not allocate format context");
        formatContext.oformat = fmt.getPointer();
        strncpy(formatContext.filename, path);
        /* add the video stream using the default format
         * codec and initialize the codec */
        if (fmt.video_codec == AVCODEC.CODEC_ID_NONE)
                throw new IOException("Could not determine codec for " + path);
        AVStream videoSt = addVideoStream(fmt.video_codec, stack.getWidth(), stack.getHeight(), frameRate, bitRate, STREAM_PIX_FMT);
        if (videoSt == null)
                throw new IOException("Could not add a video stream");
        /* set the output parameters (mustbe done even if no
         * parameters). */
        if (avFormat.av_set_parameters(formatContext, null) < 0)
                throw new IOException("Invalid output format parameters.");
        /* now that all the parameters are set, we can open the
         * video codec and allocate the necessary encode buffer */
        openVideo();
        // Dump the format to stderr
        avFormat.dump_format(formatContext, 0, path, 1);
        AVOutputFormat tmpFmt = new AVOutputFormat(formatContext.oformat);
        if ((tmpFmt.flags & AVFORMAT.AVFMT_RAWPICTURE) == 0) {
                /* allocate output buffer */
                /* buffers passed into lav* can be allocated any way you prefer,
                   as long as they're aligned enough for the architecture, and
                   they're freed appropriately (such as using av_free for buffers
                   allocated with av_malloc) */
                videoOutbut = new byte[200000];
        }
        /* open the output file, if needed */
        if ((fmt.flags & AVFORMAT.AVFMT_NOFILE) == 0) {
                final PointerByReference p = new PointerByReference();
                if (avFormat.url_fopen(p, path, AVFORMAT.URL_WRONLY) < 0)
                        throw new IOException("Could not open " + path);
                formatContext.pb = p.getValue();
        }
        bufferFramePixelFormat = AVUTIL.PIX_FMT_RGB24;
        switch (image.getType()) {
        case ImagePlus.GRAY8:
                bufferFramePixelFormat = AVUTIL.PIX_FMT_PAL8;
                break;
        case ImagePlus.GRAY16:
                bufferFramePixelFormat = AVUTIL.PIX_FMT_GRAY16BE;
                break;
        }
        allocateFrames(true);
        avFormat.av_write_header(formatContext);
        // videoPts = (double)videoSt.pts.val * videoSt.time_base.num / videoSt.time_base.den;
        for (int frameCount = 1; frameCount <= stack.getSize(); frameCount++) {
                /* write video frame */
                step(null, frameCount / (double)stack.getSize());
                writeVideoFrame(stack.getProcessor(frameCount), videoSt);
        }
        // flush last frame
        //writeVideoFrame(null, formatContext, videoSt);
        /* write the trailer, if any */
        avFormat.av_write_trailer(formatContext);
        /* close codec */
        //closeVideo(formatContext, videoSt);
        /* free the streams */
        for (i = 0; i < formatContext.nb_streams; i++) {
                AVStream tmpStream = new AVStream(formatContext.streams[i]);
                avUtil.av_free(tmpStream.codec);
                avUtil.av_free(formatContext.streams[i]);
        }
        if ((fmt.flags & AVFORMAT.AVFMT_NOFILE) == 0) {
                /* close the output file */
                avFormat.url_fclose(formatContext.pb);
        }
        free();
}
 
讨论
淘淘あ西西 profile image