@@ -33,6 +33,7 @@ import java.io.FileInputStream
3333import java .io .IOException
3434import java .io .InputStream
3535import java .net .JarURLConnection
36+ import java .nio .charset .Charset
3637import java .nio .charset .StandardCharsets
3738import java .nio .file .Files
3839import java .nio .file .Path
@@ -42,6 +43,8 @@ import java.util.zip.ZipFile
4243import javax .mail .internet .MimeMultipart
4344import javax .mail .util .ByteArrayDataSource
4445import scala .collection .JavaConverters ._
46+ import scala .io .BufferedSource
47+ import scala .io .Source
4548import scala .io .Source .fromFile
4649import scala .util .Try
4750
@@ -254,40 +257,40 @@ class NativeCliRuntimeIT extends FunSpec
254257 case " json" =>
255258 val actual : String = new String (bytes, encoding)
256259 val actualNormalized = actual.stripMarginAndNormalizeEOL.replace(" \\ r\\ n" , " \\ n" )
257- actualNormalized should matchJson(readFile(expectedFile))
260+ actualNormalized should matchJson(readFile(expectedFile, encoding ))
258261 case " xml" =>
259262 val actual : String = new String (bytes, encoding)
260- actual.stripMarginAndNormalizeEOL should matchXml(readFile(expectedFile))
263+ actual.stripMarginAndNormalizeEOL should matchXml(readFile(expectedFile, encoding ))
261264 case " dwl" =>
262265 val actual : String = new String (bytes, " UTF-8" )
263- actual should matchString(readFile(expectedFile))(after being whiteSpaceNormalised)
266+ actual should matchString(readFile(expectedFile, encoding ))(after being whiteSpaceNormalised)
264267 case " csv" =>
265268 val actual : String = new String (bytes, encoding).trim
266269 val actualNormalized = actual.stripMarginAndNormalizeEOL
267- val expected = readFile(expectedFile).trim
270+ val expected = readFile(expectedFile, encoding ).trim
268271 val expectedNormalized = expected.stripMarginAndNormalizeEOL
269272 actualNormalized should matchString(expectedNormalized)
270273 case " txt" =>
271274 val actual : String = new String (bytes, encoding).trim
272275 val actualNormalized = actual.stripMarginAndNormalizeEOL
273- val expected = readFile(expectedFile).trim
276+ val expected = readFile(expectedFile, encoding ).trim
274277 val expectedNormalized = expected.stripMarginAndNormalizeEOL
275278 actualNormalized should matchString(expectedNormalized)
276279 case " bin" =>
277280 assertBinaryFile(bytes, expectedFile)
278281 case " urlencoded" =>
279282 val actual : String = new String (bytes, " UTF-8" )
280- actual should matchString(readFile(expectedFile).trim)
283+ actual should matchString(readFile(expectedFile, encoding ).trim)
281284 case " properties" =>
282285 val actual : String = new String (bytes, " UTF-8" )
283- actual should matchProperties(readFile(expectedFile).trim)
286+ actual should matchProperties(readFile(expectedFile, encoding ).trim)
284287
285288 case " multipart" =>
286289 matchMultipart(expectedFile, bytes)
287290
288291 case " yml" | " yaml" =>
289292 val actual : String = new String (bytes, " UTF-8" )
290- actual.trim should matchString(readFile(expectedFile).trim)
293+ actual.trim should matchString(readFile(expectedFile, encoding ).trim)
291294 }
292295 }
293296
@@ -331,19 +334,20 @@ class NativeCliRuntimeIT extends FunSpec
331334 }
332335 }
333336
334- private def readFile (expectedFile : File ): String = {
337+ private def readFile (expectedFile : File , charset : String ): String = {
335338 val expectedText : String = {
336339 if (expectedFile.getName endsWith " .bin" )
337340 " "
338- else
339- Try (fileToString(expectedFile)).getOrElse({
340- val source = fromFile(expectedFile)(scala.io.Codec (" UTF-16" ))
341- try {
342- source.mkString
343- } finally {
344- source.close()
345- }
346- })
341+ else {
342+ var value1 : BufferedSource = null
343+ try {
344+ value1 = Source .fromFile(expectedFile, charset)
345+ value1.mkString
346+ } finally {
347+ value1.close()
348+ }
349+ }
350+
347351 }
348352 expectedText
349353 }
0 commit comments