kongdeqiang
2022-09-19 a9862e81851bbe037edc6bb1c7f562c1e55c0d7f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
//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)
//        {
//        }
//    }
//}