java本地方法如何调用其他程序函数,方法详解2
| 分类: Java类文章 |
static{
System.loadLibrary("testdecompress");//加载动态库testdecompress.dll
}
public native byte[] decompress(byte[] inbs,int hh,int ww);
public byte[] inbs;
public byte[] outbs;
public InputByte() {
}
}
#include
/* Header for class com_cchongda_decompress_TestDecompress */
#define _Included_com_cchongda_decompress_TestDecompress
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: com_cchongda_decompress_TestDecompress
* Method: decompress
* Signature: ([BII)[B
*/
JNIEXPORT jbyteArray JNICALL Java_com_cchongda_decompress_TestDecompress_decompress
(JNIEnv *, jobject, jbyteArray, jint, jint);
}
#endif
#endif
(1)#include "com_cchongda_decompress_TestDecompress.h"
(2)extern "C" int _stdcall Decompress(unsigned char *outimg,char* ezwimg,int hh,int ww);
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}
{
int i =1;
unsigned char * buffer = new BYTE[92160];
jbyteArray temparr;
temparr = env->NewByteArray(92160);
char * parr;
jbyte *arr = env->GetByteArrayElements(barr,0);
parr = (char *)arr;
/*FILE *fp;
fp = fopen("C:\\11.dat","w");
fwrite(parr,1,4610,fp);
fclose(fp);*/
i=Decompress(buffer,parr,hh,ww);
//printf("%d",i);
env->SetByteArrayRegion(temparr, 0, 92160, (const signed char *)buffer);
env->ReleaseByteArrayElements(barr, (signed char *)parr, 0);
return temparr;
}
public class DbConnect {
public DbConnect() {
}
public Connection conn=null;
public Statement stat=null;
public PreparedStatement pstat=null;
public ResultSet rs=null;
private String Driver="com.mysql.jdbc.Driver";
private String url="jdbc:mysql://192.101.1.138:3306/fingerdb";
{
try{
Class.forName(Driver).newInstance();
}
catch(java.lang.IllegalAccessException iae){
iae.printStackTrace();
}
catch(java.lang.ClassNotFoundException cnf){
cnf.printStackTrace();
}
catch(java.lang.InstantiationException ie){
ie.printStackTrace();
}
}
try{
this.conn = java.sql.DriverManager.getConnection(url, "root", "");
}
catch(java.sql.SQLException e){
e.printStackTrace();
return conn;
}
public Statement getStat(){
Statement stat = null;
try{
stat = this.getConn().createStatement();
}
catch(SQLException sqle){
sqle.printStackTrace();
}
return stat;
}
public ResultSet getRs(String sql){
// String sql="select htzw1 from zwzpxxb where sbh=''";
ResultSet rs=null;
try{
rs = stat.executeQuery(sql);
}
catch(java.sql.SQLException sqle){
sqle.printStackTrace();
}
return rs;
}
}
(2)主类提供入口函数
import java.io.*;
public class Test {
public Test() {
}
public static void main(String[] args){
FileOutputStream fos = null;
TestDecompress td = new TestDecompress();
InputByte ib = new InputByte();
int hh = 360;
int ww = 256;
File file = new File("C:/uuu.bmp");
try{
fos = new FileOutputStream(file);
}
catch(Exception e){
e.printStackTrace();
}
DbConnect dbc = new DbConnect();
try{
dbc.stat = dbc.getConn().createStatement();
}catch(java.sql.SQLException sqle){
sqle.printStackTrace();
}
String sql1= "select wjt from wjt";
String sql2 = "select htzw1 from zwzpxxb where sbh='A026010239'";
Blob blob = null;
ResultSet rs1 = dbc.getRs(sql1);
try{
if (rs1.next()) {
blob = rs1.getBlob("wjt");
System.out.println("文件头的字节数:"+blob.length());
}
fos.write(blob.getBytes(1,(int)blob.length()),0,(int)blob.length());
}catch(Exception e){
e.printStackTrace();
}
blob =null;
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ResultSet rs2 = dbc.getRs(sql2);
try{
if (rs2.next()) {
blob = rs2.getBlob("htzw1");
System.out.println("文件体的字节数:"+blob.length());
bos.write(blob.getBytes(1,(int)blob.length()),0,(int)blob.length());
ib.inbs=bos.toByteArray();
System.out.println("进入的字节数"+ib.inbs.length);
// System.out.print(ib.outbs.length);
bos.close();
}
}catch(Exception e){
e.printStackTrace();
}
try{
System.out.println("解压缩后的字节数:"+ib.outbs.length);
fos.write(ib.outbs, 0, ib.outbs.length);
fos.flush();
fos.close();
}
catch(Exception e){
e.printStackTrace();
}
}
该过程是从数据库中读取一个未压缩的指纹数据文件头和压缩的指纹数据文件体,调用解压缩方法解压后将完整的指纹数据输出到c:\uuu.bmp,输出结果如图所示:
java本地方法如何调用其他程序函数,方法详解2的更多相关文章
- Python3调用C程序(超详解)
Python3调用C程序(超详解) Python为什么要调用C? 1.要提高代码的运算速度,C比Python快50倍以上 2.对于C语言里很多传统类库,不想用Python重写,想对从内存到文件接口这样 ...
- java本地方法如何调用其他程序函数,方法详解
JNI是Java Native Interface的缩写,中文为JAVA本地调用.从Java 1.1 开始,Java Native Interface (JNI)标准成为java平台的一部分,它允许J ...
- java 通过反射机制调用某个类的方法
package net.xsoftlab.baike; import java.lang.reflect.Method; public class TestReflect { public s ...
- java多态性方法的重写Overriding和重载Overloading详解
java多态性方法的重写Overriding和重载Overloading详解 方法的重写Overriding和重载Overloading是Java多态性的不同表现.重写Overriding是父类与子类 ...
- C#虚函数virtual详解
在面向对象编程中,有两种截然不同的继承方式:实现继承和接口继承.在实现继承时候,在Java中,所有函数默认都是virtual的,而在C#中所有函数并不默认为virtual的,但可以在基类中通过声明关键 ...
- Scala进阶之路-Scala函数篇详解
Scala进阶之路-Scala函数篇详解 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.传值调用和传名调用 /* @author :yinzhengjie Blog:http: ...
- 转载 LayoutInflater的inflate函数用法详解
http://www.open-open.com/lib/view/open1328837587484.html LayoutInflater的inflate函数用法详解 LayoutInflater ...
- Java NIO 的前生今世 之四 NIO Selector 详解
Selector Selector 允许一个单一的线程来操作多个 Channel. 如果我们的应用程序中使用了多个 Channel, 那么使用 Selector 很方便的实现这样的目的, 但是因为在一 ...
- php中的PDO函数库详解
PHP中的PDO函数库详解 PDO是一个“数据库访问抽象层”,作用是统一各种数据库的访问接口,与mysql和mysqli的函数库相比,PDO让跨数据库的使用更具有亲和力:与ADODB和MDB2相比,P ...
随机推荐
- UISwitch和UIActivity的使用
- (void)viewDidLoad{ [super viewDidLoad]; //创建一个开关控件,苹果给它固定的size(79*27),frame更改size无效 //继承于 ...
- android的adb详解(多设备时adb调用)
在多设备(模拟器)时,想要直接用logcat查看其中一台的状态,或者直接把应用安装到目标设备上时,需要指定设备号.adb devices这个指令可以得到当前设备的序列号(serialNumber).比 ...
- spark能否取代Hadoop?
大数据的浪潮风靡全球的时候,Spark火了.在国外 Yahoo!.Twitter.Intel.Amazon.Cloudera 等公司率先应用并推广 Spark 技术,在国内阿里巴巴.百度.淘宝.腾讯. ...
- WPF开发时光之痕日记本(二)—— MVVM基类
当我们用MVVM的时候要实现INotifyPropertyChanged,每次都要实现这个接口比较麻烦,所以基类的作用就体现出来了.代码如下: public class ViewModelBase : ...
- IE10访问apache 2.4会奇慢的解决办法
Windows版的apache 2.4. IE10访问apache 2.4会特别慢.有时Apache挂起了.只好重新开apache,但是重开后,也会好景不长,刚处理几个请求,就又变得奇慢了.Firef ...
- android之imgView插件的使用
在开发中我们经常要用到图片下载功能,但我们可以在github上淘一些比较好的插件,这里介绍一款叫smartImageView的插件. 这里是其地址https://github.com/loopj/an ...
- 第二章:javascript: 数组
数组是编程世界里最常见的数据结构.任何一种编程语言都包含数组,只是形式稍微有差异.数组是编程语言中的内建类型,通常效率都很高.可以满足不同需求的数据存储,本章将探索javascript中的数组工作原理 ...
- “耐撕”团队2016.03.28 站立会议
1. 时间:20:30--20:50 2. 成员: Z 郑蕊 * 组长 (博客:http://www.cnblogs.com/zhengrui0452/), P 濮成林(博客:http://www.c ...
- rational rose USE CASE
- Spring security 和 AOP 学习
1.Spring security 登录验证拦截器 资源管理拦截器 认证和授权: 认证:登录时候确实存在此用户. 登录要认证! 授权:登录后判断权限级别,然后赋予相应的操作权限. ...
转载▼