Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ val row2 = listOf("d", "e", "f")
csvWriter().open("test.csv") {
writeRow(row1)
writeRow(row2)
writeRow("g", "h", "i")
writeRows(listOf(row1, row2))
}
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package com.github.doyaaaaaken.kotlincsv.client
interface ICsvFileWriter {
fun writeRow(row: List<Any?>)

fun writeRow(vararg entry: Any?)

fun writeRows(rows: List<List<Any?>>)

fun writeRows(rows: Sequence<List<Any?>>)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ class CsvFileWriter internal constructor(
}
}

/**
* write one row
*/
override fun writeRow(vararg entry: Any?) {
writeRow(entry.toList())
Copy link
Contributor Author

@blackmo18 blackmo18 May 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think it is better to specify explicitly the implementation, so it would not look like cyclic?

   override fun writeRow(vararg entry: Any) {
        willWritePreTerminator()
        writeNext(entry.toList())
        willWriteEndTerminator()

        if (writer.checkError()) {
            throw IOException("Failed to write")
        }
    }

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I don't think. Leave this as it is.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for giving your thoughts.

}

/**
* write rows
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,24 @@ class CsvFileWriterTest : WordSpec() {
val actual = readTestFile()
actual shouldBe expected
}
"write row from variable arguments" {

val date1 = LocalDate.of(2019, 8, 19)
val date2 = LocalDateTime.of(2020, 9, 20, 14, 32, 21)

val expected = "a,b,c\r\n"+
"d,e,f\r\n"+
"1,2,3\r\n"+
"2019-08-19,2020-09-20T14:32:21\r\n"
csvWriter().open(testFileName) {
writeRow("a", "b", "c")
writeRow("d", "e", "f")
writeRow(1,2,3)
writeRow(date1, date2)
}
val actual = readTestFile()
actual shouldBe expected
}
}
"writeAll method" should {
"write Sequence data" {
Expand Down