I am reading from Database using Jooq and dumping the records in File.
I want to dump the records in CSV format and new line between each records. I looked into Jooq Docs and researched on Google but didn't find any help. Jooq support CSV format but how do I incorporate the feature in my use case.
I am using the following code to dump the record in File:
SelectQuery<Record> query = getDslContext().selectQuery();
try {
@Cleanup FileOutputStream fileOutputStream = new FileOutputStream(FILE);
@Cleanup GZIPOutputStream gzipOutputStream = new GZIPOutputStream(fileOutputStream);
@Cleanup OutputStreamWriter outputStreamWriter = new OutputStreamWriter(gzipOutputStream, charsetName);
@Cleanup BufferedWriter writer = new BufferedWriter(outputStreamWriter);
@Cleanup Cursor<Record> cursor = query.fetchSize(MAX_FETCH_SIZE).fetchLazy();
while(cursor.hasNext()){
Result<Record> results = cursor.fetchNext(MAX_FETCH_SIZE);
for (Record record : results){
writer.write(record.formatJSON());
writer.newLine();
}
}