I am trying to encode an XML to Base64 and then, write this Base64 to a JSON file. When i do it, the Base64 is complete, but the JSON is incomplete, there is no trailing }
at the end of string and it is incomplete, I do not know what could be do.
Here is my code:
This is the Xml to Base64 encoder
public static String fileEncoderBase64() throws IOException {
File file = new File("/root/EntradaN1.xml");
BufferedReader bufferedReader = null;
String linea;
String lineas = null;
try {
bufferedReader = new BufferedReader(new FileReader(file));
while ((linea = bufferedReader.readLine()) != null) {
lineas += linea;
}
bufferedReader.close();
} catch (Exception e) {
e.printStackTrace();
} finally {
bufferedReader.close();
}
return encodeBase64(lineas);
}
public static String encodeBase64(String mensaje) throws UnsupportedEncodingException {
byte[] bytes = mensaje.getBytes("UTF-8");
return Base64.getEncoder().encodeToString(bytes);
}
And this is the JSON parser:
public static void jsonCreator(JsonModelAgent jsonModelAgent) throws IOException {
Gson gson = new Gson();
gson.toJson(jsonModelAgent, new BufferedWriter(new FileWriter("/root/datos.json")));
}
And this is de diferences between mongo's Base64 length and json's length.
JSON: ==============>65176
MONGO: =============>76592
Thanks for help.
只需添加接近jsonCreator的fileWriter即可
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.