Skip to content

Refactor CSVExporter writer handling#980

Open
PencilWarrior882 wants to merge 2 commits into
knowm:developfrom
PencilWarrior882:refactor/csv-exporter-resource-handling
Open

Refactor CSVExporter writer handling#980
PencilWarrior882 wants to merge 2 commits into
knowm:developfrom
PencilWarrior882:refactor/csv-exporter-resource-handling

Conversation

@PencilWarrior882

Copy link
Copy Markdown

Summary

Refactors CSVExporter writer handling while preserving the existing row-oriented and column-oriented CSV output formats.

Problem

CSVExporter manually managed Writer lifecycle in both export paths using duplicated try / finally blocks. The close path swallowed IOException with a // NOP comment, the UTF-8 charset was passed as a string literal, and the platform line separator lookup was repeated across the class.

Refactoring

This PR replaces the manual writer cleanup with try-with-resources, uses StandardCharsets.UTF_8, centralizes the platform line separator, and removes stale commented-out CSV construction code.

The public CSVExporter APIs are unchanged:

  • writeCSVRows(XYChart, String)
  • writeCSVRows(XYSeries, String)
  • writeCSVColumns(XYChart, String)
  • writeCSVColumns(XYSeries, String)

Impact Check

I checked the existing CSVExporter call sites:

  • xchart-demo/.../csv/Export2Rows.java
  • xchart-demo/.../csv/Export2Columns.java
  • XChartPanel.java CSV export path

The refactor keeps the same public signatures, same output orientation, same platform line separator behavior, and same broad exception handling. The removed commented-out CSV construction code referenced variables that are not present in the current method and was not a usable alternate implementation.

What This PR Adds

A focused CSVExporterTest with temporary-file based checks for both supported export formats:

  • row-oriented export writes X values and Y values as separate rows
  • column-oriented export writes X/Y pairs as rows

The tests read the generated CSV files as UTF-8 and verify exact content, so the refactor is covered against output-format regressions.

Validation

  • mvn -pl xchart "-Dtest=CSVExporterTest" test
  • mvn fmt:check
  • mvn clean verify --no-transfer-progress --batch-mode --settings etc/settings.xml "-Dmaven.javadoc.skip=true" "-Dfmt.skip=true"

Add focused CSVExporter tests that write row-oriented and column-oriented XY series data to temporary files and verify the exact CSV content using UTF-8 reads. These tests lock the current export format before refactoring the writer implementation, so the resource-handling cleanup can be shown to preserve behavior.
Replace manual CSV Writer lifecycle management with try-with-resources so each export path closes its output stream reliably without duplicated finally blocks. Use StandardCharsets.UTF_8 instead of the UTF8 string literal, centralize the platform line separator, and remove stale commented-out CSV construction code. Public CSVExporter APIs and output format remain unchanged.
@PencilWarrior882 PencilWarrior882 force-pushed the refactor/csv-exporter-resource-handling branch from ed43846 to 8fc50ea Compare June 22, 2026 22:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant