Skip to content

Commit b7b00b6

Browse files
committed
Merge branch 'master' of https://github.com/ashwanthkumar/scala-csv into ashwanthkumar-master
2 parents 9243989 + c6cd9fe commit b7b00b6

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/main/scala/com/github/tototoshi/csv/CSVWriter.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ object CSVWriter {
102102

103103
def open(file: File, append: Boolean, encoding: String)(implicit format: CSVFormat): CSVWriter = {
104104
val fos = new FileOutputStream(file, append)
105+
open(fos, encoding)(format)
106+
}
107+
108+
def open(fos: OutputStream)(implicit format: CSVFormat): CSVWriter = open(fos, "UTF-8")(format)
109+
110+
def open(fos: OutputStream, encoding: String)(implicit format: CSVFormat): CSVWriter = {
105111
try {
106112
val writer = new OutputStreamWriter(fos, encoding)
107113
open(writer)(format)

src/test/scala/com/github/tototoshi/csv/CSVWriterSpec.scala

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.github.tototoshi.csv
22

3-
import java.io.{UnsupportedEncodingException, FileWriter, File}
3+
import java.io.{FileOutputStream, UnsupportedEncodingException, FileWriter, File}
44

55
import org.scalatest.{ FunSpec, BeforeAndAfter }
66
import org.scalatest.matchers._
@@ -21,6 +21,19 @@ class CSVWriterSpec extends FunSpec with ShouldMatchers with BeforeAndAfter with
2121
describe("CSVWriter") {
2222

2323
describe ("#open") {
24+
25+
it("should be constructed with OutputStream") {
26+
using (CSVWriter.open(new FileOutputStream("test.csv"))) { writer =>
27+
writer.writeAll(List(List("a", "b", "c"), List("d", "e", "f")))
28+
}
29+
}
30+
31+
it("should be constructed with OutputStream and encoding") {
32+
using (CSVWriter.open(new FileOutputStream("test.csv"), "UTF-8")) { writer =>
33+
writer.writeAll(List(List("a", "b", "c"), List("d", "e", "f")))
34+
}
35+
}
36+
2437
it("should be constructed with java.io.File") {
2538
using (CSVWriter.open(new File("test.csv"))) { writer =>
2639
writer.writeAll(List(List("a", "b", "c"), List("d", "e", "f")))

0 commit comments

Comments
 (0)