BAEL-2659 - Reading a file in Groovy - corrected variable names

This commit is contained in:
Anshul Bansal 2019-01-31 12:46:25 +02:00
parent 50a8870d4f
commit b48f77cf6e
3 changed files with 16 additions and 10 deletions

View File

@ -70,6 +70,7 @@ class ReadFile {
*/
def moreExamples() {
//with reader with utf-8
new File("src/main/resources/utf8Content.html").withReader('UTF-8') { reader ->
def line
while ((line = reader.readLine())!=null) {
@ -77,20 +78,25 @@ class ReadFile {
}
}
//collect api
def list = new File("src/main/resources/fileContent.txt").collect {it}
//as operator
def array = new File("src/main/resources/fileContent.txt") as String[]
//eachline
new File("src/main/resources/fileContent.txt").eachLine { line ->
println line
}
//newInputStream with eachLine
def is = new File("src/main/resources/fileContent.txt").newInputStream()
is.eachLine {
println it
}
is.close()
//withInputStream
new File("src/main/resources/fileContent.txt").withInputStream { stream ->
stream.eachLine { line ->
println line

View File

@ -1,5 +1,3 @@
ᚠᛇᚻ᛫ᛒᛦᚦ᛫ᚠᚱᚩᚠᚢᚱ᛫ᚠᛁᚱᚪ᛫ᚷᛖᚻᚹᛦᛚᚳᚢᛗ
ᛋᚳᛖᚪᛚ᛫ᚦᛖᚪᚻ᛫ᛗᚪᚾᚾᚪ᛫ᚷᛖᚻᚹᛦᛚᚳ᛫ᛗᛁᚳᛚᚢᚾ᛫ᚻᛦᛏ᛫ᛞᚫᛚᚪᚾ
ᚷᛁᚠ᛫ᚻᛖ᛫ᚹᛁᛚᛖ᛫ᚠᚩᚱ᛫ᛞᚱᛁᚻᛏᚾᛖ᛫ᛞᚩᛗᛖᛋ᛫ᚻᛚᛇᛏᚪᚾ
¥ · £ · € · $ · ¢ · ₡ · ₢ · ₣ · ₤ · ₥ · ₦ · ₧ · ₨ · ₩ · ₪ · ₫ · ₭ · ₮ · ₯ · ₹
ᚷᛁᚠ᛫ᚻᛖ᛫ᚹᛁᛚᛖ᛫ᚠᚩᚱ᛫ᛞᚱᛁᚻᛏᚾᛖ᛫ᛞᚩᛗᛖᛋ᛫ᚻᛚᛇᛏᚪᚾ

View File

@ -50,19 +50,21 @@ Line 3 : String content""")
given:
def filePath = "src/main/resources/utf8Content.html"
when:
def noOfLines = readFile.readFileStringWithCharset(filePath)
def encodedContent = readFile.readFileStringWithCharset(filePath)
then:
noOfLines
noOfLines instanceof String
encodedContent
encodedContent instanceof String
}
def 'Should return binary file content in byte arry using ReadFile.readBinaryFile given filePath' () {
given:
def filePath = "src/main/resources/sample.png"
when:
def noOfLines = readFile.readBinaryFile(filePath)
def binaryContent = readFile.readBinaryFile(filePath)
then:
noOfLines
noOfLines instanceof byte[]
binaryContent
binaryContent instanceof byte[]
binaryContent.length == 329
}
}