From d6119c2d7fe2f802dd224d77bf2d95eeeedb4526 Mon Sep 17 00:00:00 2001 From: xuxiuxi <xuxiuxi@454eff88-639b-444f-9e54-f578c98de674> Date: 星期一, 10 七月 2017 16:08:15 +0800 Subject: [PATCH] --- VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/fragment/RegisterFragment.java | 419 +++++------------------------------------------------------ 1 files changed, 36 insertions(+), 383 deletions(-) diff --git a/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/fragment/RegisterFragment.java b/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/fragment/RegisterFragment.java index 5a6a0bd..be628d5 100644 --- a/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/fragment/RegisterFragment.java +++ b/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/fragment/RegisterFragment.java @@ -41,6 +41,11 @@ import cn.com.basic.face.service.SurveillanceMng; import cn.com.basic.face.util.BitmapUtil; import cn.com.basic.face.util.Constant; +import cn.com.basic.face.util.FileUtil; +import static cn.com.basic.face.util.FileUtil.*; + +import cn.com.basic.face.util.IdCard; +import cn.com.basic.face.util.IdCardReaderThread; import cn.com.basic.face.util.NativeImg; import cn.com.basic.face.util.OkClickedListener; @@ -53,13 +58,10 @@ import cn.com.basic.face.widget.register.RegisterRightFieldTextView; import cn.com.basic.face.dialog.SelectDialog; -import com.facebook.common.file.FileUtils; import com.ivsign.android.IDCReader.IDCReaderSDK; import com.lidroid.xutils.view.annotation.ViewInject; import com.lidroid.xutils.view.annotation.event.OnClick; -import org.xutils.common.util.FileUtil; -import org.xutils.common.util.IOUtil; import org.xutils.http.RequestParams; import java.io.BufferedOutputStream; @@ -137,7 +139,9 @@ private File idCardImageCaptureFile = null; - private String idCardHeadPhotoPath = ""; + private IdCardReaderThread idCardReaderThread = null; + + private String idCardHeadPath = ""; private static RegisterFragment instance = new RegisterFragment(); @@ -152,26 +156,6 @@ @OnClick(R.id.fragment_register_add) public void fragment_register_add_click(View view) { resetForm(); - } - - private File writeToFile(String fileName, byte[] fileBytes) { - try { - String dir = MainActivity.getInstance().getFilesDir().getAbsolutePath(); - - File file = new File(dir, fileName); - if (file.exists()) { - file.delete(); - } - file.createNewFile(); - BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(new File(dir, fileName))); - bos.write(fileBytes); - bos.flush(); - bos.close(); - return new File(dir, fileName); - }catch (Exception e) { - e.printStackTrace(); - } - return null; } @OnClick(R.id.fragment_register_save) @@ -190,77 +174,29 @@ fragment_register_phone.requestFocus(); return; } - String gender = fragment_register_gender.getValue(); - if (gender.trim().length() <= 0) { - Toast.makeText(MainActivity.getInstance(), "鎬у埆涓嶈兘涓虹┖", Toast.LENGTH_SHORT).show(); - fragment_register_gender.callOnClick(); - return; - } - String id_class = fragment_register_id_class.getValue(); - if (id_class.trim().length() <= 0) { - Toast.makeText(MainActivity.getInstance(), "璇佷欢绫诲瀷涓嶈兘涓虹┖", Toast.LENGTH_SHORT).show(); - fragment_register_id_class.callOnClick(); - return; - } - String country = fragment_register_country.getValue(); - if (country.trim().length() <= 0) { - Toast.makeText(MainActivity.getInstance(), "鍥界睄涓嶈兘涓虹┖", Toast.LENGTH_SHORT).show(); - fragment_register_country.callOnClick(); - return; - } - String id_num = fragment_register_id_num.getValue(); - if (id_num.trim().length() <= 0) { - Toast.makeText(MainActivity.getInstance(), "璇佷欢缂栧彿涓嶈兘涓虹┖", Toast.LENGTH_SHORT).show(); - fragment_register_id_num.requestFocus(); - return; - } - String birthday = fragment_register_birthday.getValue(); - if (birthday.trim().length() <= 0) { - Toast.makeText(MainActivity.getInstance(), "鍑虹敓鏃ユ湡涓嶈兘涓虹┖", Toast.LENGTH_SHORT).show(); - fragment_register_birthday.callOnClick(); - return; - } String company = fragment_register_company.getValue(); if (company.trim().length() <= 0) { Toast.makeText(MainActivity.getInstance(), "鍏徃鍚嶇О涓嶈兘涓虹┖", Toast.LENGTH_SHORT).show(); fragment_register_company.requestFocus(); return; } - String remark = fragment_register_remark.getValue(); - if (remark.trim().length() <= 0) { - Toast.makeText(MainActivity.getInstance(), "澶囨敞涓嶈兘涓虹┖", Toast.LENGTH_SHORT).show(); - fragment_register_remark.requestFocus(); - return; - } - String visitor_class = fragment_register_visitor_class.getValue(); - if (visitor_class.trim().length() <= 0) { + String visitor_type = fragment_register_visitor_class.getValue(); + if (visitor_type.trim().length() <= 0) { Toast.makeText(MainActivity.getInstance(), "璁垮绫诲瀷涓嶈兘涓虹┖", Toast.LENGTH_SHORT).show(); fragment_register_visitor_class.callOnClick(); return; } - final PostData pd = new PostData(); - - pd.addValue(Register.FieldNames.username, name); - pd.addValue(Register.FieldNames.mobilePhone, phone); - pd.addValue(Register.FieldNames.genderId, DictionaryMng.getInstance().getId(gender)); - pd.addValue(Register.FieldNames.identityTypeId, DictionaryMng.getInstance().getId(id_class)); - pd.addValue(Register.FieldNames.countryId, DictionaryMng.getInstance().getId(country)); - pd.addValue(Register.FieldNames.visitorTypeId, DictionaryMng.getInstance().getId(visitor_class)); - pd.addValue(Register.FieldNames.identifyNum, id_num); - pd.addValue(Register.FieldNames.companyId, company); - pd.addValue(Register.FieldNames.birthday, birthday); - params.addBodyParameter(Register.FieldNames.username, name); params.addBodyParameter(Register.FieldNames.mobilePhone, phone); - params.addBodyParameter(Register.FieldNames.genderId, DictionaryMng.getInstance().getId(gender)); - params.addBodyParameter(Register.FieldNames.identityTypeId, DictionaryMng.getInstance().getId(id_class)); - params.addBodyParameter(Register.FieldNames.countryId, DictionaryMng.getInstance().getId(country)); - params.addBodyParameter(Register.FieldNames.visitorTypeId, DictionaryMng.getInstance().getId(visitor_class)); - params.addBodyParameter(Register.FieldNames.identifyNum, id_num); + params.addBodyParameter(Register.FieldNames.genderId, DictionaryMng.getInstance().getId(fragment_register_gender.getValue())); + params.addBodyParameter(Register.FieldNames.identityTypeId, DictionaryMng.getInstance().getId(fragment_register_id_class.getValue())); + params.addBodyParameter(Register.FieldNames.countryId, DictionaryMng.getInstance().getId(fragment_register_country.getValue())); + params.addBodyParameter(Register.FieldNames.visitorTypeId, DictionaryMng.getInstance().getId(visitor_type)); + params.addBodyParameter(Register.FieldNames.identifyNum, fragment_register_id_num.getValue()); params.addBodyParameter(Register.FieldNames.companyId, company); - params.addBodyParameter(Register.FieldNames.birthday, birthday); - + params.addBodyParameter(Register.FieldNames.birthday, fragment_register_birthday.getValue()); + params.addBodyParameter(Register.FieldNames.remark, fragment_register_remark.getValue()); if (surveillanceQueryItem_selectPhoto != null) { params.addBodyParameter("width", surveillanceQueryItem_selectPhoto.getWidth()); @@ -272,46 +208,41 @@ for (int i = 0; i < nativeImg.size; i++) { imageBytes[i] = nativeImg.image[i]; } - pd.addData("rawSurveillancePhoto", "application/octet-stream", imageBytes); - - params.addBodyParameter("rawSurveillancePhoto", writeToFile("rawSurveillancePhoto", imageBytes)); + params.addBodyParameter("rawSurveillancePhoto", FileUtil.writeToFile("rawSurveillancePhoto", imageBytes)); } else { - params.addBodyParameter("rawSurveillancePhoto", writeToFile("rawSurveillancePhoto", new byte[]{})); + params.addBodyParameter("rawSurveillancePhoto", FileUtil.writeToFile("rawSurveillancePhoto", new byte[]{})); } if (fragment_register_surveillance_photo_img != null) { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); fragment_register_surveillance_photo_img.compress(Bitmap.CompressFormat.JPEG, 100, byteArrayOutputStream); byte[] imageBytes = byteArrayOutputStream.toByteArray(); - pd.addData(Register.FieldNames.surveillancePhoto, "application/octet-stream", imageBytes); - params.addBodyParameter("surveillancePhoto", writeToFile("surveillancePhoto", imageBytes)); + params.addBodyParameter("surveillancePhoto", FileUtil.writeToFile("surveillancePhoto", imageBytes)); } else { - params.addBodyParameter("surveillancePhoto", writeToFile("surveillancePhoto", new byte[]{})); + params.addBodyParameter("surveillancePhoto", FileUtil.writeToFile("surveillancePhoto", new byte[]{})); } if (fragment_register_upload_custom_photo_img != null) { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); fragment_register_upload_custom_photo_img.compress(Bitmap.CompressFormat.JPEG, 100, byteArrayOutputStream); byte[] imageBytes = byteArrayOutputStream.toByteArray(); - pd.addData(Register.FieldNames.uploadCustomPhoto, "application/octet-stream", imageBytes); - params.addBodyParameter("uploadCustomPhoto", writeToFile("uploadCustomPhoto", imageBytes)); + params.addBodyParameter("uploadCustomPhoto", FileUtil.writeToFile("uploadCustomPhoto", imageBytes)); } else { - params.addBodyParameter("uploadCustomPhoto", writeToFile("uploadCustomPhoto", new byte[]{})); + params.addBodyParameter("uploadCustomPhoto", FileUtil.writeToFile("uploadCustomPhoto", new byte[]{})); } if (fragment_register_id_card_photo_img != null) { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); fragment_register_id_card_photo_img.compress(Bitmap.CompressFormat.JPEG, 100, byteArrayOutputStream); byte[] imageBytes = byteArrayOutputStream.toByteArray(); - pd.addData(Register.FieldNames.idCardPhoto, "application/octet-stream", imageBytes); - params.addBodyParameter("idCardPhoto", writeToFile("idCardPhoto", imageBytes)); + params.addBodyParameter("idCardPhoto", FileUtil.writeToFile("idCardPhoto", imageBytes)); } else { - params.addBodyParameter("idCardPhoto", writeToFile("idCardPhoto", new byte[]{})); + params.addBodyParameter("idCardPhoto", FileUtil.writeToFile("idCardPhoto", new byte[]{})); } - RegisterMng.getInstance().add(params, idCardHeadPhotoPath); + RegisterMng.getInstance().add(params, idCardHeadPath); } public void set_fragment_register_surveillance_photo(SurveillanceQueryItem item) { @@ -432,7 +363,7 @@ selectedCustomPhotoId = -1; selectedSurveillancePhotoId = -1; - idCardHeadPhotoPath = ""; + idCardHeadPath = ""; fragment_register_name.setValue("寰愪慨婧�"+Math.random()); fragment_register_phone.setValue("13691348767"); @@ -579,100 +510,28 @@ @Override protected void initData() { resetForm(); - new ReadIdCardThread().start(); + idCardReaderThread = new IdCardReaderThread(); + idCardReaderThread.start(); } - public void fillFormWithIdCard() { + public void fillFormWithIdCard(IdCard idCard) { try { - fragment_register_name.setValue(idCard_name); - fragment_register_id_num.setValue(idCard_idNumber); + fragment_register_name.setValue(idCard.getName()); + fragment_register_id_num.setValue(idCard.getCardNumber()); SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd"); - fragment_register_birthday.setValue(sdf1.format(sdf.parse(idCard_birth))); - fragment_register_gender.setValue(idCard_sex); + fragment_register_birthday.setValue(sdf1.format(sdf.parse(idCard.getBirthday()))); + fragment_register_gender.setValue(idCard.getGender()); fragment_register_id_class.setValue("韬唤璇�"); BitmapFactory.Options options = new BitmapFactory.Options(); options.inPreferredConfig = Bitmap.Config.ARGB_8888; - Bitmap bitmap = BitmapFactory.decodeFile(idCardHeadPhotoPath, options); + Bitmap bitmap = BitmapFactory.decodeFile(idCard.getHeadPath(), options); fragment_register_id_card_photo.setImageBitmap(bitmap); fragment_register_id_card_photo_placeholder_image.setVisibility(View.INVISIBLE); fragment_register_id_card_photo_placeholder_text_view.setVisibility(View.INVISIBLE); - } catch (Exception e) { - e.printStackTrace(); - } - } - - private String idCard_name = ""; - private String idCard_idNumber = ""; - private String idCard_birth = ""; - private String idCard_sex = ""; - - class ReadIdCardThread extends Thread { - - @Override - public void run() { - while(true) { - try{ - Thread.sleep(1000); - readIdCard(); - } catch (Exception e) { - e.printStackTrace(); - } - } - } - } - - public void readIdCard() { - try { - if (!registerFragmentVisible) { - return; - } - - RFIDReader idCardReader = RFIDReader.getInstance(BaseApplication.getInstance(), "uart"); - idCardReader.setUartDeviceName("/dev/ttyS1"); - ByteArrayInputStream type = new ByteArrayInputStream("uart".getBytes()); - idCardReader.control(ReaderExtra.CONNECT, type); - - idCardReader.open("id_card"); - String cardId = byteArrayToHexString(idCardReader.getUid()); - - idCardReader.open("id_sam"); - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - idCardReader.control(ReaderExtra.ID_READ_TEXT_PHOTO, baos); - String textPhoto = byteArrayToHexString(baos.toByteArray()); - if (textPhoto != null) { - final String[] decodeInfo = new String[10]; - final StringBuilder imagePath = new StringBuilder(); - String path = MainActivity.getInstance().getFilesDir().getAbsolutePath(); - IDCReaderSDK.initialize(path); - IDCReaderSDK.decodeSamAck(textPhoto, decodeInfo, imagePath); - idCard_name = decodeInfo[0]; - idCard_sex = decodeInfo[1]; - idCard_idNumber = decodeInfo[5]; - idCard_birth = decodeInfo[3]; -// final String idCardNation = decodeInfo[2]; -// final String idCardAddress = decodeInfo[4]; -// final String idCardIssuingAuthority = decodeInfo[6]; -// final String idCardValidBegin = decodeInfo[7]; -// final String idCardValidEnd = decodeInfo[8]; - - idCardHeadPhotoPath = imagePath.toString(); - - if (fragment_register_surveillance_photo_img == null) { -// MainActivity.getInstance().runOnUiThread(new Runnable() { -// @Override -// public void run() { -// Toast.makeText(BaseApplication.getInstance(),"璇峰厛閫夋嫨浜虹墿鐓х墖", Toast.LENGTH_SHORT).show(); -// } -// }); - //return; - testComparePicturesWithJpeg(); - } else { - testComparePicturesWithJpeg(); - } - } + idCardHeadPath = idCard.getHeadPath(); } catch (Exception e) { e.printStackTrace(); } @@ -686,213 +545,7 @@ registerFragmentVisible = menuVisible; } - private void testComparePicturesWithJpeg() { - RequestParams params = new RequestParams(); - - if (idCardHeadPhotoPath != null && !"".equals(idCardHeadPhotoPath)) { - BitmapFactory.Options options = new BitmapFactory.Options(); - options.inPreferredConfig = Bitmap.Config.ARGB_8888; - Bitmap bitmap = BitmapFactory.decodeFile(idCardHeadPhotoPath, options); - - ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); - bitmap.compress(Bitmap.CompressFormat.JPEG, 100, byteArrayOutputStream); - byte[] imageBytes = byteArrayOutputStream.toByteArray(); - - params.addBodyParameter("surveillancePhotoW",bitmap.getWidth()+""); - params.addBodyParameter("surveillancePhotoH",bitmap.getWidth()+""); - params.addBodyParameter("surveillancePhoto", writeToFile("surveillancePhoto", imageBytes)); - } else { - params.addBodyParameter("surveillancePhotoW", "0"); - params.addBodyParameter("surveillancePhotoH", "0"); - params.addBodyParameter("surveillancePhoto", writeToFile("surveillancePhoto", new byte[]{})); - } - - - if (idCardHeadPhotoPath != null && !"".equals(idCardHeadPhotoPath)) { - - BitmapFactory.Options options = new BitmapFactory.Options(); - options.inPreferredConfig = Bitmap.Config.ARGB_8888; - Bitmap bitmap = BitmapFactory.decodeFile(idCardHeadPhotoPath, options); - - ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); - bitmap.compress(Bitmap.CompressFormat.JPEG, 100, byteArrayOutputStream); - byte[] imageBytes = byteArrayOutputStream.toByteArray(); - - params.addBodyParameter("idCardPhotoW",bitmap.getWidth()+""); - params.addBodyParameter("idCardPhotoH",bitmap.getWidth()+""); - params.addBodyParameter("idCardPhoto", writeToFile("idCardPhoto", imageBytes)); - } else { - params.addBodyParameter("idCardPhotoW","0"); - params.addBodyParameter("idCardPhotoH","0"); - params.addBodyParameter("idCardPhoto", writeToFile("idCardHeadPhoto", new byte[]{})); - } - - RegisterMng.getInstance().compareSurveillancePhotoAndIdCardPhoto(params); - } - - private void testComparePicturesWithBmp() { - - RequestParams params = new RequestParams(); - - if (idCardHeadPhotoPath != null && !"".equals(idCardHeadPhotoPath)) { - BitmapFactory.Options options = new BitmapFactory.Options(); - options.inPreferredConfig = Bitmap.Config.ARGB_8888; - Bitmap bitmap = BitmapFactory.decodeFile(idCardHeadPhotoPath, options); - params.addBodyParameter("surveillancePhotoW", bitmap.getWidth() + ""); - params.addBodyParameter("surveillancePhotoH", bitmap.getWidth() + ""); - params.addBodyParameter("surveillancePhoto", writeToFile("surveillancePhoto", readFile(new File(idCardHeadPhotoPath)))); - } else { - params.addBodyParameter("surveillancePhotoW", "0"); - params.addBodyParameter("surveillancePhotoH", "0"); - params.addBodyParameter("surveillancePhoto", writeToFile("surveillancePhoto", new byte[]{})); - } - - - if (idCardHeadPhotoPath != null && !"".equals(idCardHeadPhotoPath)) { - BitmapFactory.Options options = new BitmapFactory.Options(); - options.inPreferredConfig = Bitmap.Config.ARGB_8888; - Bitmap bitmap = BitmapFactory.decodeFile(idCardHeadPhotoPath, options); - - - params.addBodyParameter("idCardPhotoW",bitmap.getWidth()+""); - params.addBodyParameter("idCardPhotoH",bitmap.getWidth()+""); - params.addBodyParameter("idCardPhoto", writeToFile("idCardPhoto", readFile(new File(idCardHeadPhotoPath)))); - } else { - params.addBodyParameter("idCardPhotoW","0"); - params.addBodyParameter("idCardPhotoH","0"); - params.addBodyParameter("idCardPhoto", writeToFile("idCardPhoto", new byte[]{})); - } - - RegisterMng.getInstance().compareSurveillancePhotoAndIdCardPhoto(params); - } - - private void comparePictures() { - - RequestParams params = new RequestParams(); - -// if (fragment_register_surveillance_photo_img != null) { -// ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); -// fragment_register_surveillance_photo_img.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream); -// byte[] imageBytes = byteArrayOutputStream.toByteArray(); -// -// params.addBodyParameter("surveillancePhotoW",fragment_register_surveillance_photo_img.getWidth()+""); -// params.addBodyParameter("surveillancePhotoH",fragment_register_surveillance_photo_img.getHeight()+""); -// -// params.addBodyParameter("surveillancePhoto", writeToFile("surveillancePhoto", imageBytes)); -// } else { -// params.addBodyParameter("surveillancePhotoW","0"); -// params.addBodyParameter("surveillancePhotoH","0"); -// params.addBodyParameter("surveillancePhoto", writeToFile("surveillancePhoto", new byte[]{})); -// } - - if (idCardHeadPhotoPath != null && !"".equals(idCardHeadPhotoPath)) { - BitmapFactory.Options options = new BitmapFactory.Options(); - options.inPreferredConfig = Bitmap.Config.ARGB_8888; - Bitmap bitmap = BitmapFactory.decodeFile(idCardHeadPhotoPath, options); - - ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); - bitmap.compress(Bitmap.CompressFormat.JPEG, 100, byteArrayOutputStream); - byte[] imageBytes = byteArrayOutputStream.toByteArray(); - - params.addBodyParameter("surveillancePhotoW",bitmap.getWidth()+""); - params.addBodyParameter("surveillancePhotoH",bitmap.getWidth()+""); - params.addBodyParameter("surveillancePhoto", writeToFile("surveillancePhoto", imageBytes)); - - - /////////////////////////////////// - - - - ///////////////////////////////// -// BitmapFactory.Options options = new BitmapFactory.Options(); -// options.inPreferredConfig = Bitmap.Config.ARGB_8888; -// Bitmap bitmap = BitmapFactory.decodeFile(idCardHeadPhotoPath, options); -// params.addBodyParameter("surveillancePhotoW", bitmap.getWidth() + ""); -// params.addBodyParameter("surveillancePhotoH", bitmap.getWidth() + ""); -// params.addBodyParameter("surveillancePhoto", writeToFile("surveillancePhoto", readFile(new File(idCardHeadPhotoPath)))); - } else { - params.addBodyParameter("surveillancePhotoW", "0"); - params.addBodyParameter("surveillancePhotoH", "0"); - params.addBodyParameter("surveillancePhoto", writeToFile("surveillancePhoto", new byte[]{})); - } - - - if (idCardHeadPhotoPath != null && !"".equals(idCardHeadPhotoPath)) { - - BitmapFactory.Options options = new BitmapFactory.Options(); - options.inPreferredConfig = Bitmap.Config.ARGB_8888; - Bitmap bitmap = BitmapFactory.decodeFile(idCardHeadPhotoPath, options); - - ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); - bitmap.compress(Bitmap.CompressFormat.JPEG, 100, byteArrayOutputStream); - byte[] imageBytes = byteArrayOutputStream.toByteArray(); - - params.addBodyParameter("idCardPhotoW",bitmap.getWidth()+""); - params.addBodyParameter("idCardPhotoH",bitmap.getWidth()+""); - params.addBodyParameter("idCardPhoto", writeToFile("idCardPhoto", imageBytes)); - - - /////////////////////////////////// - -// BitmapFactory.Options options = new BitmapFactory.Options(); -// options.inPreferredConfig = Bitmap.Config.ARGB_8888; -// Bitmap bitmap = BitmapFactory.decodeFile(idCardHeadPhotoPath, options); -// -// -// params.addBodyParameter("idCardPhotoW",bitmap.getWidth()+""); -// params.addBodyParameter("idCardPhotoH",bitmap.getWidth()+""); -// params.addBodyParameter("idCardPhoto", writeToFile("idCardPhoto", readFile(new File(idCardHeadPhotoPath)))); - } else { - params.addBodyParameter("idCardPhotoW","0"); - params.addBodyParameter("idCardPhotoH","0"); - params.addBodyParameter("idCardPhoto", writeToFile("idCardPhoto", new byte[]{})); - } - - RegisterMng.getInstance().compareSurveillancePhotoAndIdCardPhoto(params); - } - - protected static final char[] a = new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; - public static String byteArrayToHexString(byte[] bytes) { - if(bytes == null) { - return null; - } else { - char[] hexChars = new char[bytes.length * 2]; - - for(int j = 0; j < bytes.length; ++j) { - int v = bytes[j] & 255; - hexChars[j * 2] = a[v >>> 4]; - hexChars[j * 2 + 1] = a[v & 15]; - } - - return new String(hexChars); - } - } - public static byte[] readFile(File file) { - // Open file - RandomAccessFile f = null; - try { - f = new RandomAccessFile(file, "r"); - // Get and check length - long longlength = f.length(); - int length = (int) longlength; - if (length != longlength) - throw new IOException("File size >= 2 GB"); - // Read file and return data - byte[] data = new byte[length]; - f.readFully(data); - return data; - } catch (Exception e){ - e.printStackTrace(); - } finally { - try { - f.close(); - }catch (Exception e) { - e.printStackTrace(); - } - } - return new byte[]{}; - } } -- Gitblit v1.8.0