BAEL-2659 - Reading a file in Groovy - corrected variable names
This commit is contained in:
parent
50a8870d4f
commit
b48f77cf6e
|
@ -70,6 +70,7 @@ class ReadFile {
|
||||||
*/
|
*/
|
||||||
def moreExamples() {
|
def moreExamples() {
|
||||||
|
|
||||||
|
//with reader with utf-8
|
||||||
new File("src/main/resources/utf8Content.html").withReader('UTF-8') { reader ->
|
new File("src/main/resources/utf8Content.html").withReader('UTF-8') { reader ->
|
||||||
def line
|
def line
|
||||||
while ((line = reader.readLine())!=null) {
|
while ((line = reader.readLine())!=null) {
|
||||||
|
@ -77,20 +78,25 @@ class ReadFile {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//collect api
|
||||||
def list = new File("src/main/resources/fileContent.txt").collect {it}
|
def list = new File("src/main/resources/fileContent.txt").collect {it}
|
||||||
|
|
||||||
|
//as operator
|
||||||
def array = new File("src/main/resources/fileContent.txt") as String[]
|
def array = new File("src/main/resources/fileContent.txt") as String[]
|
||||||
|
|
||||||
|
//eachline
|
||||||
new File("src/main/resources/fileContent.txt").eachLine { line ->
|
new File("src/main/resources/fileContent.txt").eachLine { line ->
|
||||||
println line
|
println line
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//newInputStream with eachLine
|
||||||
def is = new File("src/main/resources/fileContent.txt").newInputStream()
|
def is = new File("src/main/resources/fileContent.txt").newInputStream()
|
||||||
is.eachLine {
|
is.eachLine {
|
||||||
println it
|
println it
|
||||||
}
|
}
|
||||||
is.close()
|
is.close()
|
||||||
|
|
||||||
|
//withInputStream
|
||||||
new File("src/main/resources/fileContent.txt").withInputStream { stream ->
|
new File("src/main/resources/fileContent.txt").withInputStream { stream ->
|
||||||
stream.eachLine { line ->
|
stream.eachLine { line ->
|
||||||
println line
|
println line
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
ᚠᛇᚻ᛫ᛒᛦᚦ᛫ᚠᚱᚩᚠᚢᚱ᛫ᚠᛁᚱᚪ᛫ᚷᛖᚻᚹᛦᛚᚳᚢᛗ
|
ᚠᛇᚻ᛫ᛒᛦᚦ᛫ᚠᚱᚩᚠᚢᚱ᛫ᚠᛁᚱᚪ᛫ᚷᛖᚻᚹᛦᛚᚳᚢᛗ
|
||||||
ᛋᚳᛖᚪᛚ᛫ᚦᛖᚪᚻ᛫ᛗᚪᚾᚾᚪ᛫ᚷᛖᚻᚹᛦᛚᚳ᛫ᛗᛁᚳᛚᚢᚾ᛫ᚻᛦᛏ᛫ᛞᚫᛚᚪᚾ
|
ᛋᚳᛖᚪᛚ᛫ᚦᛖᚪᚻ᛫ᛗᚪᚾᚾᚪ᛫ᚷᛖᚻᚹᛦᛚᚳ᛫ᛗᛁᚳᛚᚢᚾ᛫ᚻᛦᛏ᛫ᛞᚫᛚᚪᚾ
|
||||||
ᚷᛁᚠ᛫ᚻᛖ᛫ᚹᛁᛚᛖ᛫ᚠᚩᚱ᛫ᛞᚱᛁᚻᛏᚾᛖ᛫ᛞᚩᛗᛖᛋ᛫ᚻᛚᛇᛏᚪᚾ
|
ᚷᛁᚠ᛫ᚻᛖ᛫ᚹᛁᛚᛖ᛫ᚠᚩᚱ᛫ᛞᚱᛁᚻᛏᚾᛖ᛫ᛞᚩᛗᛖᛋ᛫ᚻᛚᛇᛏᚪᚾ
|
||||||
|
|
||||||
¥ · £ · € · $ · ¢ · ₡ · ₢ · ₣ · ₤ · ₥ · ₦ · ₧ · ₨ · ₩ · ₪ · ₫ · ₭ · ₮ · ₯ · ₹
|
|
|
@ -50,19 +50,21 @@ Line 3 : String content""")
|
||||||
given:
|
given:
|
||||||
def filePath = "src/main/resources/utf8Content.html"
|
def filePath = "src/main/resources/utf8Content.html"
|
||||||
when:
|
when:
|
||||||
def noOfLines = readFile.readFileStringWithCharset(filePath)
|
def encodedContent = readFile.readFileStringWithCharset(filePath)
|
||||||
then:
|
then:
|
||||||
noOfLines
|
encodedContent
|
||||||
noOfLines instanceof String
|
encodedContent instanceof String
|
||||||
}
|
}
|
||||||
|
|
||||||
def 'Should return binary file content in byte arry using ReadFile.readBinaryFile given filePath' () {
|
def 'Should return binary file content in byte arry using ReadFile.readBinaryFile given filePath' () {
|
||||||
given:
|
given:
|
||||||
def filePath = "src/main/resources/sample.png"
|
def filePath = "src/main/resources/sample.png"
|
||||||
when:
|
when:
|
||||||
def noOfLines = readFile.readBinaryFile(filePath)
|
def binaryContent = readFile.readBinaryFile(filePath)
|
||||||
then:
|
then:
|
||||||
noOfLines
|
binaryContent
|
||||||
noOfLines instanceof byte[]
|
binaryContent instanceof byte[]
|
||||||
|
binaryContent.length == 329
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue