|
|
@@ -1,14 +1,18 @@
|
|
|
package com.gis.common.proto.util;
|
|
|
|
|
|
import com.gis.common.proto.Visionmodeldata;
|
|
|
-import com.gis.common.proto.format.JsonFormat;
|
|
|
-import lombok.extern.log4j.Log4j2;
|
|
|
+//import com.gis.common.proto.format.JsonFormat;
|
|
|
+import com.google.protobuf.InvalidProtocolBufferException;
|
|
|
+import com.google.protobuf.util.JsonFormat;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
import java.io.*;
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
-@Log4j2
|
|
|
+@Slf4j
|
|
|
public class ConvertUtils {
|
|
|
|
|
|
public static void convertVisionModelDataToTxt(String srcPath, String desPath) throws Exception {
|
|
|
@@ -21,7 +25,8 @@ public class ConvertUtils {
|
|
|
|
|
|
Visionmodeldata.NavigationInfo data_NavigationInfo = Visionmodeldata.NavigationInfo.parseFrom(fis);
|
|
|
|
|
|
- String jsonFormat1 = JsonFormat.printToString(data_NavigationInfo);
|
|
|
+ // 包直接引入的不合适
|
|
|
+ String jsonFormat1 = com.gis.common.proto.format.JsonFormat.printToString(data_NavigationInfo);
|
|
|
ByteArrayInputStream stream = new ByteArrayInputStream(jsonFormat1.getBytes());
|
|
|
bos = new BufferedOutputStream(new FileOutputStream(desPath));//设置输出路径
|
|
|
bis = new BufferedInputStream(stream);
|
|
|
@@ -46,13 +51,14 @@ public class ConvertUtils {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
public static void convertTxtToVisionModelData(String srcPath, String desPath) throws Exception {
|
|
|
BufferedOutputStream bos = null;
|
|
|
BufferedInputStream bis = null;
|
|
|
try {
|
|
|
Visionmodeldata.NavigationInfo.Builder builder = Visionmodeldata.NavigationInfo.newBuilder();
|
|
|
String jsonFormat = readTxtFileToJson(srcPath);
|
|
|
- JsonFormat.merge(jsonFormat, builder);
|
|
|
+ com.gis.common.proto.format.JsonFormat.merge(jsonFormat, builder);
|
|
|
byte[] buf = builder.build().toByteArray();
|
|
|
|
|
|
//把序列化后的数据写入本地磁盘
|
|
|
@@ -159,61 +165,5 @@ public class ConvertUtils {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-// public static void convertTxtToVisionmodeldata(String srcpath,String despath)throws Exception
|
|
|
-// {
|
|
|
-// try
|
|
|
-// {
|
|
|
-// Visionmodeldata.NavigationInfo.Builder builder = Visionmodeldata.NavigationInfo.newBuilder();
|
|
|
-// String jsonFormat = readTxtFileToJson(srcpath);
|
|
|
-// JsonFormat.merge(jsonFormat, builder);
|
|
|
-// byte[] buf= builder.build().toByteArray();
|
|
|
-//
|
|
|
-// //把序列化后的数据写入本地磁盘
|
|
|
-// ByteArrayInputStream stream = new ByteArrayInputStream(buf);
|
|
|
-// BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(despath));//设置输出路径
|
|
|
-// BufferedInputStream bis = new BufferedInputStream(stream);
|
|
|
-// int b = -1;
|
|
|
-// while ((b = bis.read()) != -1) {
|
|
|
-// bos.write(b);
|
|
|
-// }
|
|
|
-// bis.close();
|
|
|
-// bos.close();
|
|
|
-// }
|
|
|
-// catch(Exception e)
|
|
|
-// {
|
|
|
-// StringWriter trace=new StringWriter();
|
|
|
-// e.printStackTrace(new PrintWriter(trace));
|
|
|
-// log.error(trace.toString());
|
|
|
-// }
|
|
|
-// }
|
|
|
-
|
|
|
-// public static void convertVisionmodeldataToTxt(String srcpath,String despath)throws Exception
|
|
|
-// {
|
|
|
-// try
|
|
|
-// {
|
|
|
-// File file = new File(srcpath);
|
|
|
-// FileInputStream fis=new FileInputStream(file);
|
|
|
-//
|
|
|
-// Visionmodeldata.NavigationInfo data_NavigationInfo = Visionmodeldata.NavigationInfo.parseFrom(fis);
|
|
|
-//
|
|
|
-// //PrintStream out = new PrintStream(despath);
|
|
|
-// String jsonFormat1 = JsonFormat.printToString(data_NavigationInfo);
|
|
|
-// ByteArrayInputStream stream = new ByteArrayInputStream(jsonFormat1.getBytes());
|
|
|
-// BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(despath));//设置输出路径
|
|
|
-// BufferedInputStream bis = new BufferedInputStream(stream);
|
|
|
-// int b = -1;
|
|
|
-// while ((b = bis.read()) != -1) {
|
|
|
-// bos.write(b);
|
|
|
-// }
|
|
|
-// //out.close();
|
|
|
-// bis.close();
|
|
|
-// bos.close();
|
|
|
-// }
|
|
|
-// catch(Exception e)
|
|
|
-// {
|
|
|
-// StringWriter trace=new StringWriter();
|
|
|
-// e.printStackTrace(new PrintWriter(trace));
|
|
|
-// log.error(trace.toString());
|
|
|
-// }
|
|
|
-// }
|
|
|
+
|
|
|
}
|