/** * Fills the class's internal buffer with a DSV line */ private void fillBuffer(CsvListWriter writer, Rows.Row row) { String[] vals = row.values; try { writer.write(vals); writer.flush(); } catch (Exception e) { beeLine.error(e); } }
@Override public void flush() throws IOException { if (writer != null) { writer.flush(); } }
private synchronized void writeCsvRow(List<Object> row) { try { csvWriter.write(row); csvWriter.flush(); } catch (IOException e) { throw new RuntimeException(e); } }
@Override public void allDone() { try { csvWriter.flush(); super.allDone(); List<File> batch = ExternalSort.sortInBatch( new File(tmpFile), defaultcomparator, ExternalSort.DEFAULTMAXTEMPFILES, Charset.forName("utf8"), null, true); ExternalSort.mergeSortedFiles(batch, new File(outFile), defaultcomparator, Charset.forName("utf-8"), true, false, false, getHeaderString()); new File(tmpFile).delete(); } catch (IOException e) { throw new RuntimeException(e); } }
private String getHeaderString() { if(this.header == null) { return null; } ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { CsvListWriter csvListWriter = new CsvListWriter(new OutputStreamWriter(baos), CsvPreference.TAB_PREFERENCE); csvListWriter.write(this.header); csvListWriter.flush(); csvListWriter.close(); return baos.toString("utf-8"); } catch (Exception e) { throw new RuntimeException(e); } }
/** * Fills the class's internal buffer with a DSV line */ private void fillBuffer(CsvListWriter writer, Rows.Row row) { String[] vals = row.values; try { writer.write(vals); writer.flush(); } catch (Exception e) { beeLine.error(e); } }
writer.flush(); writer.close();
/** * Close the reader, then close the shadow writer and replace the original * file if necessary. */ @Override public void close() throws IOException { try { if (reader != null) { reader.close(); } } finally { if (writer != null) { // dump the last row to the writer try { writeRow(); writer.flush(); } finally { try { writer.close(); } finally { renameFiles(); } } } } }