package com.aigyun.util; import com.aigyun.constant.BusinessException; import org.springframework.web.multipart.MultipartFile; import java.io.DataInputStream; import java.io.IOException; import java.util.*; /** * Created by Administrator on 2019/6/3. */ public class IoUtil { /** * 分析字节流转换为map * @param file * @return */ public static List<Map> buileFlyRealTimeData(MultipartFile file) { List<Map> flyRealTimeData = new ArrayList<>(); DataInputStream in = null; try { in = new DataInputStream(file.getInputStream()); int length = in.available(); if (length <= 0) { return flyRealTimeData; } //索引读取 char index = (char)in.readByte(); //读取头信息 byte header [] = new byte[84]; in.read(header,0,84); //机型注册号 String uav_no = new String(Arrays.copyOfRange(header,1,20)).trim(); //任务 String order_no = new String(Arrays.copyOfRange(header,21,40)).trim(); //版本 String app_ver_no = new String(Arrays.copyOfRange(header,41,60)).trim(); //序列 String flight_control = new String(Arrays.copyOfRange(header,61,84)).trim(); int n = 1 + (length -85) / 74; //循环次数 for (int i=0; i< n;i++){ Map realTimeEntity = new HashMap(); realTimeEntity.put("uav_no", uav_no); realTimeEntity.put("order_no", order_no); realTimeEntity.put("app_ver_no", app_ver_no); realTimeEntity.put("flight_control", flight_control); System.out.println("-----------------------===========第"+i+"行"); if (i == 522) { ; } //架次 realTimeEntity.put("flight_seq", in.readInt()); //时间戳 realTimeEntity.put("now_time", in.readInt()); //状态 realTimeEntity.put("state", in.readByte()); //飞行时间 realTimeEntity.put("flight_time", in.readLong()); //经度 realTimeEntity.put("longitude", in.readInt()); //纬度 realTimeEntity.put("latitude", in.readInt()); //相对高度 realTimeEntity.put("height", in.readInt()); //绝对高度 realTimeEntity.put("altitude", in.readInt()); //偏航角 realTimeEntity.put("path_angle", (short)in.readChar()); //仰俯角 realTimeEntity.put("pitch_angle", (short)in.readChar()); //横滚角 realTimeEntity.put("roll_angle", (short)in.readChar()); //地速 realTimeEntity.put("horizontal_velocity", in.readInt()); //喷嘴是否工作 realTimeEntity.put("is_nozzle_work", in.readByte()); //喷嘴口径 realTimeEntity.put("nozzle_diameter", (short)in.readChar()); //喷嘴角度 realTimeEntity.put("nozzle_angle", (short)in.readChar()); //喷嘴压力 realTimeEntity.put("nozzle_pressure", (short)in.readChar()); //喷幅 realTimeEntity.put("spray_range", in.readInt()); //剩余药量 realTimeEntity.put("remain_dose", in.readInt()); //使用药量 realTimeEntity.put("used_dose", in.readInt()); //喷洒流速 realTimeEntity.put("cur_flow", in.readInt()); //喷洒面积 realTimeEntity.put("flight_area", in.readInt()); //飞行距离 realTimeEntity.put("flight_length_section", in.readInt()); flyRealTimeData.add(realTimeEntity); } }catch (Exception e){ e.printStackTrace(); throw new BusinessException(200000,"上传失败," + e.getMessage()); }finally { try { in.close(); } catch (IOException ioe){ ioe.printStackTrace(); throw new BusinessException(200000,"上传失败," + ioe.getMessage()); } } return flyRealTimeData; } }
转载于:https://my.oschina.net/u/1763091/blog/3058156