//package com.boying.controller.car;
|
//
|
//import com.google.gson.JsonIOException;
|
//import com.google.gson.JsonObject;
|
//import com.google.gson.JsonParser;
|
//import com.google.gson.JsonSyntaxException;
|
//import org.springframework.stereotype.Controller;
|
//import org.springframework.web.bind.annotation.RequestMapping;
|
//
|
//import javax.servlet.ServletException;
|
//import javax.servlet.annotation.WebServlet;
|
//import javax.servlet.http.HttpServlet;
|
//import javax.servlet.http.HttpServletRequest;
|
//import javax.servlet.http.HttpServletResponse;
|
//import java.io.*;
|
//import java.util.Base64;
|
//
|
///**
|
// * Servlet implementation class PlateServlet
|
// */
|
//@WebServlet("/PlateServlet")
|
////@Controller
|
////@RequestMapping("/PlateServlet")
|
//public class PlateServlet extends HttpServlet {
|
// private static final long serialVersionUID = 1L;
|
//
|
// /**
|
// * @see HttpServlet#HttpServlet()
|
// */
|
// public PlateServlet() {
|
// super();
|
// // TODO Auto-generated constructor stub
|
// }
|
//
|
// /**
|
// * 回复开闸
|
// * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
|
// */
|
// protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
// // TODO Auto-generated method stub
|
// // response.getWriter().append("Served at: ").append(request.getContextPath());
|
//
|
// // �ظ���������豸��բ
|
// response.setContentType("text/json");
|
// PrintWriter out = response.getWriter();
|
// out.println("{\"Response_AlarmInfoPlate\":{\"info\":\"ok\",\"content\":\"...\",\"is_pay\":\"true\"}}");
|
// out.flush();
|
// out.close();
|
// }
|
//
|
// //转码
|
// public static String deCode(String str) {
|
// try {
|
// byte[] b = str.getBytes("UTF-8");//����
|
// String sa = new String(b);//����:��ʲô�ַ����������ʲô�ַ�������
|
// //String sa = new String(str.getBytes());
|
//
|
// return sa;
|
// } catch (Exception e) {
|
// e.printStackTrace();
|
// return "";
|
// }
|
// }
|
//
|
// //保存文件
|
// private static boolean SaveFile(byte[] content, String path, String imgName) {
|
// FileOutputStream writer = null;
|
// boolean result = false;
|
// try {
|
// File dir = new File(path);
|
// if (!dir.exists()) {
|
// dir.mkdirs();
|
// }
|
// writer = new FileOutputStream(new File(path, imgName));
|
// writer.write(content);
|
// result = true;
|
// } catch (IOException ex) {
|
// ex.printStackTrace();
|
// } finally {
|
// try {
|
// writer.flush();
|
// writer.close();
|
// } catch (IOException ex) {
|
// ex.printStackTrace();
|
// }
|
// }
|
// return result;
|
// }
|
//
|
// /**
|
// * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
|
// */
|
// protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
// // TODO Auto-generated method stub
|
//
|
// StringBuffer jb = new StringBuffer();
|
// // JSONObject jsonObject;
|
// String line = null;
|
// char [] lineChars = new char[1024 * 1024];
|
// char [] totalChars = new char[1024 * 1024];
|
// int readLen = 0;
|
// int totalLen = 0;
|
// try {
|
// BufferedReader reader = request.getReader();
|
// while ((readLen = reader.read(lineChars)) > 0) {
|
// for (int i = 0; i < readLen; i++) {
|
// totalChars[totalLen + i] = lineChars[i];
|
// }
|
// totalLen += readLen;
|
// }
|
// } catch (Exception e) { /*report an error*/ }
|
//
|
// byte[] lineBytes = new byte[totalLen];
|
// for(int i = 0; i < totalLen; i++) {
|
// lineBytes[i] = (byte)totalChars[i];
|
// }
|
// String lineStr = new String(lineBytes, "UTF-8");
|
// //System.out.println(lineStr);
|
// WriteTxt("d:\\parkLog1\\plate_result.txt", lineStr);//这里应该是心跳
|
//
|
// try {
|
// JsonParser parser=new JsonParser();
|
// do {
|
// JsonObject jsonObject=(JsonObject) parser.parse(lineStr);
|
// if( jsonObject == null || jsonObject.isJsonNull() ) {
|
// break;
|
// }
|
//
|
// JsonObject jsonInfoPlate = jsonObject.get("AlarmInfoPlate").getAsJsonObject();
|
// if( jsonInfoPlate == null || jsonInfoPlate.isJsonNull() ) {
|
// break;
|
// }
|
//
|
// JsonObject jsonResult = jsonInfoPlate.get("result").getAsJsonObject();
|
// if( jsonResult == null || jsonResult.isJsonNull() ) {
|
// break;
|
// }
|
//
|
// JsonObject jsonPlateResult = jsonResult.get("PlateResult").getAsJsonObject();
|
// if( jsonPlateResult == null || jsonPlateResult.isJsonNull() ) {
|
// break;
|
// }
|
//
|
// String license = jsonPlateResult.get("license").getAsString();//车牌号
|
// if( license == null || license == "" || license.length()<5) {
|
// break;
|
// }
|
//
|
// String serialno = jsonInfoPlate.get("serialno").getAsString();//摄像机序列号
|
// if( license == null || license == "" ) {
|
// break;
|
// }
|
// //System.out.println("编号:"+serialno+"设备识别到了:"+license);
|
//
|
//
|
// //String decode_license = deCode(license);
|
// WriteTxt("d:\\parkLog1\\plate_num.txt", license);
|
//
|
// String imageData = jsonPlateResult.get("imageFile").getAsString();
|
// if (imageData == null || imageData == "") {
|
// break;
|
// }
|
//
|
// byte[] decoderBytes = Base64.getDecoder().decode(imageData);
|
// SaveFile(decoderBytes, "d:\\parkLog2\\", "img_full.jpg");
|
//
|
// String plateImageData = jsonPlateResult.get("imageFragmentFile").getAsString();
|
// if (plateImageData == null || plateImageData == "") {
|
// break;
|
// }
|
//
|
// byte[] plateImgBytes = Base64.getDecoder().decode(plateImageData);
|
// SaveFile(plateImgBytes, "d:\\parkLog2\\", "img_clip.jpg");
|
//
|
// }while(false);
|
// }
|
// catch (JsonIOException e) {
|
// e.printStackTrace();
|
// }
|
// catch (JsonSyntaxException e) {
|
// e.printStackTrace();
|
// }
|
// catch (Exception e) {
|
//
|
// }
|
//
|
// doGet(request, response);//抬杆
|
// }
|
//
|
// protected void WriteTxt( String path, String txt)
|
// {
|
// try
|
// {
|
// FileWriter f = new FileWriter(path);
|
// BufferedWriter bw=new BufferedWriter(f);
|
// bw.write(txt);
|
// bw.close();
|
// }
|
// catch(Exception e)
|
// {
|
// }
|
// }
|
//}
|