Newer
Older
irisDatabase / src / com / casic / birmm / util / RecIrisUtil.java
TAN YUE on 9 Oct 2020 1 KB 20201008 初始建立
package com.casic.birmm.util;

import sun.misc.BASE64Decoder;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

public class RecIrisUtil {
    /**
     * 与C#通信,获取虹膜编码
     * @param image 虹膜图片
     * @return 成功返回虹膜编码,失败返回null
     */
    public static byte[] getIrisCode(byte[] imageBytes) throws IOException {
        byte[] irisCode = new byte[1024];

        InputStream fis = new ByteArrayInputStream(imageBytes);

        //1.创建客户端Socket,指定服务器地址和端口
        Socket socket=new Socket("localhost", 20004);
        //2.获取输出流,向服务器端发送信息
        OutputStream os=socket.getOutputStream();//字节输出流
        byte[] buf = new byte[4096];
        int len=0;
        while((len = fis.read(buf))!=-1) {
            os.write(buf, 0, len);
        }
        socket.shutdownOutput();//关闭输出流
        //3.获取输入流,读取服务器端的响应信息
        InputStream is=socket.getInputStream();
        byte[] bufIn = new byte[1024];
        int num =0;
        int totalNum=0;
        while ((num = is.read(bufIn))!=-1){
            System.arraycopy(bufIn,0,irisCode,totalNum,num);
            totalNum = totalNum+num;
        }
        //4.关闭资源
        is.close();
        os.close();
        socket.close();
        if(totalNum==1024){
            return irisCode;
        }
        else return null;
    }
}