Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.0.17 #7

Merged
merged 3 commits into from
Jun 13, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ licenses += ("Apache-2.0", url("http://www.apache.org/licenses/LICENSE-2.0"))
publishMavenStyle := true

name := "asta4e"
version := "0.0.16"
version := "0.0.17"

scalaVersion := "2.11.12"
crossScalaVersions := Seq("2.11.12", "2.12.8" /*, "2.13.0"*/)
Expand Down
51 changes: 51 additions & 0 deletions src/main/scala/com/axtstar/asta4e/basic/CsvBasic.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,57 @@ trait CsvBasic extends DataCore with InitialCore [CsvBasic] {
this
}

def getColumnSize(iStream: FileInputStream)={
val parser = new CSVParserBuilder()
.withSeparator(separator)
.withQuoteChar(quoteChar)
.build()
val inputStreamReader = new InputStreamReader(iStream, encoding)
val reader = new CSVReaderBuilder(inputStreamReader)
.withCSVParser(parser)
.build()
try {

val oneLine = reader.readNext()
oneLine.size
} catch {
case ex:Throwable =>
throw ex
}
finally {
reader.close()
inputStreamReader.close()
iStream.close()
}

}

def getRowSize(iStream: FileInputStream)={
val parser = new CSVParserBuilder()
.withSeparator(separator)
.withQuoteChar(quoteChar)
.build()
val inputStreamReader = new InputStreamReader(iStream, encoding)
val reader = new CSVReaderBuilder(inputStreamReader)
.withCSVParser(parser)
.build()
try {

val oneLine = reader.readAll()
oneLine.size
} catch {
case ex:Throwable =>
throw ex
}
finally {
reader.close()
inputStreamReader.close()
iStream.close()
}

}


override def _getData(iStream: FileInputStream): IndexedSeq[(String, Map[String, Any])] = {
val parser = new CSVParserBuilder()
.withSeparator(separator)
Expand Down
16 changes: 16 additions & 0 deletions src/test/scala/com/axtstar/asta4e/csv/CsvTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,23 @@ class CsvTest extends Specification {

}

"column size" in {
val target = CsvMapper
.getColumnSize(
new FileInputStream(s"${currentDir}/src/test/resources/csv/data.csv")
)

target must be_==(3)
}

"row size" in {
val target = CsvMapper
.getRowSize(
new FileInputStream(s"${currentDir}/src/test/resources/csv/data.csv")
)

target must be_==(2)
}


}
Expand Down