@Override public void serialize(List<SerializedData> data, SerializerType serializer) { String filename = serializer.getFilename()+FILE_EXTENSION; BufferedWriter writer = this.openFile(filename); if (writer != null) { try { for (SerializedData oneData : data) { writer.write(oneData.getAsJson().toString()); writer.newLine(); writer.flush(); } writer.close(); } catch (IOException e) { logger.error("Error while writing json serialization", e); } } } }
@Override public void serialize(List<SerializedData> data, SerializerType serializer) { String filename = serializer.getFilename()+FILE_EXTENSION; BufferedWriter writer = this.openFile(filename); if (writer != null) { for (SerializedData row : data) { String rowStr = StringUtils.join(row.getAsList(), SEPARATOR); this.writeNewLine(writer, rowStr); } try { writer.close(); } catch (IOException e) { logger.error("Error while clonse file", e); } } } }
@Override public void serialize(List<SerializedData> data, SerializerType serializer) { if (this.mongoDatabase != null) { MongoCollection<Document> collection = this.mongoDatabase.getCollection(serializer.getFilename()); List<Document> listDocuments = new ArrayList<>(); for (SerializedData oneData : data) { Document doc = Document.parse(oneData.getAsJson().toString()); /*try { collection.insertOne(doc); } catch (Exception e) { logger.error("Error while inserting doc",e); }*/ listDocuments.add(doc); } try { collection.insertMany(listDocuments); } catch (Exception e) { logger.error("Error while inserting all documents", e); } } else { logger.error("Mongo connection is null, there was certainly a problem with the connection."); } } }