javamaventestingmaven-3geotagging

Why is fileToString not reading the contents of the file properly?


I was following the instructions for CLAVIN installation. When I tried to build the CLAVIN package, it would display a 'Build Failure' after the TextUtilsTest, which checks that the contents extracted from a file are exactly the same as an expected String. Here's the code of the TEST, and here's the method that reads contents from file. These are the details behind its failure:

<failure message="wrong output from fileToString expected:&lt;Line1 word2[&#10;Line2 word2 word3]&#10;Line3&gt; but was:&lt;Line1 word2[&#10;Line2 word2 word3&#13;]&#10;Line3&gt;" type="org.junit.ComparisonFailure"><![CDATA[org.junit.ComparisonFailure: wrong output from fileToString expected:<Line1 word2[
Line2 word2 word3]
Line3> but was:<Line1 word2[
Line2 word2 word3
]
Line3>
    at org.junit.Assert.assertEquals(Assert.java:115)
    at com.bericotech.clavin.util.TextUtilsTest.testFileToString(TextUtilsTest.java:56)
]]></failure>

I checked the input file, and the contents are exactly the same as the provided string. I suspected that the problem is due to the encoding of the text file, I tried all other encodes, but it only made things worst. Would you suggest I ignore the exception, and move on to the next installation step?


Solution

  • There is an unexpected &#13; or CR, carriage return, \r. For the rest &#10; or LF, \n is used as newline. Now Windows uses \r\n as newline char, so maybe there is some mess of handing newlines. As a text area on Windows yielding a CR+LF containing text, where LFs were removed, and then pasted into a LF-only XML.

    (The &#13; being a numeric entity for XML. Old MacOS had \r as newline.)

    The solution is some line-ending replace of multi-line input text of merely \n.