class DataFrameWriter {

  private final WriterRegistry registry;
  private final Table table;

  public DataFrameWriter(WriterRegistry registry, Table table) {
    this.registry = registry;
    this.table = table;
  }

  public void toFile(String file) {
    toFile(new File(file));
  }

  public void toFile(File file) {<FILL_FUNCTION_BODY>}

  public void toStream(OutputStream stream, String extension) {
    DataWriter<?> dataWriter = registry.getWriterForExtension(extension);
    dataWriter.write(table, new Destination(stream));
  }

  public void toWriter(Writer writer, String extension) {
    DataWriter<?> dataWriter = registry.getWriterForExtension(extension);
    dataWriter.write(table, new Destination(writer));
  }

  public <T extends WriteOptions> void usingOptions(T options) {
    DataWriter<T> dataWriter = registry.getWriterForOptions(options);
    dataWriter.write(table, options);
  }

  public String toString(String extension) {
    StringWriter writer = new StringWriter();
    DataWriter<?> dataWriter = registry.getWriterForExtension(extension);
    dataWriter.write(table, new Destination(writer));
    return writer.toString();
  }

  // legacy methods left for backwards compatibility

  public void csv(String file) {
    CsvWriteOptions options = CsvWriteOptions.builder(file).build();
    new CsvWriter().write(table, options);
  }

  public void csv(File file) {
    CsvWriteOptions options = CsvWriteOptions.builder(file).build();
    new CsvWriter().write(table, options);
  }

  public void csv(CsvWriteOptions options) {
    new CsvWriter().write(table, options);
  }

  public void csv(OutputStream stream) {
    CsvWriteOptions options = CsvWriteOptions.builder(stream).build();
    new CsvWriter().write(table, options);
  }

  public void csv(Writer writer) {
    CsvWriteOptions options = CsvWriteOptions.builder(writer).build();
    new CsvWriter().write(table, options);
  }
}

    String extension = null;
    try {
      extension = Files.getFileExtension(file.getCanonicalPath());
    } catch (IOException e) {
      throw new RuntimeIOException(e);
    }
    DataWriter<?> dataWriter = registry.getWriterForExtension(extension);
    dataWriter.write(table, new Destination(file));
  
<no_super_class>