@Override public void close() throws IOException { printer.close(); }
public void close() throws IOException { printer.close(); } }
@Override public void close() throws IOException { close(false); }
@Override public synchronized void close() throws IOException { if (csvPrinter != null) { csvPrinter.flush(); csvPrinter.close(); isClosed = true; } }
@Test public void testCloseWithFlushOff() throws IOException { final Writer writer = mock(Writer.class); final CSVFormat csvFormat = CSVFormat.DEFAULT; final CSVPrinter csvPrinter = new CSVPrinter(writer, csvFormat); csvPrinter.close(false); verify(writer, never()).flush(); verify(writer, times(1)).close(); }
@Test public void testCloseWithFlushOn() throws IOException { final Writer writer = mock(Writer.class); final CSVFormat csvFormat = CSVFormat.DEFAULT; final CSVPrinter csvPrinter = new CSVPrinter(writer, csvFormat); csvPrinter.close(true); verify(writer, times(1)).flush(); }
/** * Closes the printer instance. * * @throws IOException if closing failed */ @Override public void close() throws IOException { this.printer.close(); }
private CSVPrinter printWithHeaderComments(final StringWriter sw, final Date now, final CSVFormat baseFormat) throws IOException { CSVFormat format = baseFormat; // Use withHeaderComments first to test CSV-145 format = format.withHeaderComments("Generated by Apache Commons CSV 1.1", now); format = format.withCommentMarker('#'); format = format.withHeader("Col1", "Col2"); final CSVPrinter csvPrinter = format.print(sw); csvPrinter.printRecord("A", "B"); csvPrinter.printRecord("C", "D"); csvPrinter.close(); return csvPrinter; }
public String writeToFile() { try { fileWriter.flush(); fileWriter.close(); csv.close(); } catch (IOException e) { e.printStackTrace(); } context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(file))); return file.getPath(); } }
String outputFile = savePath+".csv"; CSVPrinter csvFilePrinter = null; CSVFormat csvFileFormat = CSVFormat.EXCEL.withHeader(); FileWriter fileWriter = new FileWriter(outputFile); csvFilePrinter = new CSVPrinter(fileWriter, csvFileFormat); csvFilePrinter.printRecords(excelParser.getRecords()); fileWriter.flush(); fileWriter.close(); csvFilePrinter.close();
@Override public void close() throws Exception { mapperInstance.release(); if (writer != null) { writer.close(); } }
@Override public void close() { if (csvPrinter != null) { try { csvPrinter.close(); } catch (IOException exception) { throw new OutputException(exception); } csvPrinter = null; } } }
@Override protected void finish() throws IOException { csvPrinter.flush(); csvPrinter.close(); }
final FileWriter sw = new FileWriter("myfile.csv"); final CSVPrinter printer = new CSVPrinter(sw, format); for (int i = 0; i < nLines; i++) { printer.printRecord(lines[i]); } printer.flush(); printer.close();
final FileWriter sw = new FileWriter("myfile.csv"); final CSVPrinter printer = new CSVPrinter(sw, format); for (int i = 0; i < nLines; i++) { printer.printRecord(lines[i]); } printer.flush(); printer.close()
CSVParser parser = CSVFormat.newFormat(',').parse( new InputStreamReader(new ByteArrayInputStream(bytes), "UTF8")); CSVPrinter printer = CSVFormat.newFormat(',').print(out); for (CSVRecord record : parser) { try { printer.printRecord(record); } catch (Exception e) { throw new RuntimeException("Error at line " + parser.getCurrentLineNumber(), e); } } parser.close(); printer.close();
@Override @SuppressFBWarnings("DM_DEFAULT_ENCODING") public void write(ContainerTranslationStatistics statistics) { try { OutputStreamWriter streamWriter = new OutputStreamWriter(System.out); try { CSVPrinter csvPrinter = new CSVPrinter(streamWriter, CSVFormat.DEFAULT.withRecordSeparator(NEW_LINE_SEPARATOR)); try { writeToCsv(statistics, csvPrinter); csvPrinter.flush(); } finally { csvPrinter.close(); } } finally { streamWriter.close(); } } catch (IOException e) { throw new RuntimeException(e); } }
public void outputSummaryToCsv( final OutputStream outputStream, final Locale locale ) throws IOException { final List<ReportSummaryData.PresentationRow> outputList = reportService.getSummaryData().asPresentableCollection( pwmApplication.getConfig(), locale ); final CSVPrinter csvPrinter = JavaHelper.makeCsvPrinter( outputStream ); for ( final ReportSummaryData.PresentationRow presentationRow : outputList ) { final List<String> headerRow = new ArrayList<>(); headerRow.add( presentationRow.getLabel() ); headerRow.add( presentationRow.getCount() ); headerRow.add( presentationRow.getPct() ); csvPrinter.printRecord( headerRow ); } csvPrinter.close(); }
private void printResult(DataFrame dataFrame) throws IOException { CSVFormat csvFormat = CSVFormat.DEFAULT; if (commandLine.hasOption("H")) { csvFormat = csvFormat.withHeader(columns); } CSVPrinter printer = csvFormat.print(System.out); printer.flush(); for (DataRow row : dataFrame) { if (System.out.checkError()) { break; } try { printer.printRecord(row); } catch (IOException e) { throw new RuntimeException(e); } }; printer.close(); }
public static void initializeDataDirectory(String rootDir) throws Exception { loadEntityData(rootDir); // Create app flow mapping file. CSVFormat format = CSVFormat.DEFAULT.withHeader("APP", "USER", "FLOW", "FLOWRUN"); String appFlowMappingFile = rootDir + File.separator + "entities" + File.separator + "cluster1" + File.separator + FileSystemTimelineReaderImpl.APP_FLOW_MAPPING_FILE; try (PrintWriter out = new PrintWriter(new BufferedWriter( new FileWriter(appFlowMappingFile, true))); CSVPrinter printer = new CSVPrinter(out, format)){ printer.printRecord("app1", "user1", "flow1", 1); printer.printRecord("app2", "user1", "flow1,flow", 1); printer.close(); } (new File(rootDir)).deleteOnExit(); }