You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@camel.apache.org by MakotoTheKnight <gi...@git.apache.org> on 2018/08/03 22:51:09 UTC

[GitHub] camel pull request #2454: CAMEL-12698: Use the Stream API to read files inst...

GitHub user MakotoTheKnight opened a pull request:

    https://github.com/apache/camel/pull/2454

    CAMEL-12698: Use the Stream API to read files instead of Scanner

    This change introduces a fix to the Bindy module to address what could be seen as surprising behavior from `java.util.Scanner` given certain Unicode code points.
    
    Previously, Bindy leveraged `Scanner` to read lines in a file.  However, `Scanner` does its own bit of whitespace parsing, and as such, given the right whitespace character, may not always read a complete line in.
    
    In the case identified, we came across a circumstance in which we received (in error) the [NEL character](http://www.fileformat.info/info/unicode/char/85/index.htm) in our data set.  Because `Scanner` honors the intent behind this character, it will break any line that it sees with this character in two.  This is not expected in Bindy; we expect to read whole lines instead.  The use of `Scanner` unintentionally brought this bug to light, as I'm not personally convinced that `Scannner` is technically *wrong*.
    
    The fix leverages a `BufferedReader` and `Stream`s instead to read lines, which [has the same expectations](http://hg.openjdk.java.net/jdk8/jdk8/jdk/file/687fd7c7986d/src/share/classes/java/io/BufferedReader.java#l561) of line termination as [`BufferedReader#readLine`](https://docs.oracle.com/javase/8/docs/api/java/io/BufferedReader.html#readLine--), which would be `\r`, `\n`, or `\r\n`.
    
    Note:  the peculiar exception handling inside of the stream is due to the fact that checked exceptions can't be propagated, so we have to wrap them in unchecked exceptions instead.

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/MakotoTheKnight/camel fix-bindy-parser

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/camel/pull/2454.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #2454
    
----
commit 08fe4e9092db446b07762436c9c0aa070cf680dd
Author: Jason Black <ma...@...>
Date:   2018-07-26T06:07:11Z

    CAMEL-12698: Use the Stream API to read files instead of Scanner

----


---

[GitHub] camel pull request #2454: CAMEL-12698: Use the Stream API to read files inst...

Posted by onderson <gi...@git.apache.org>.
Github user onderson closed the pull request at:

    https://github.com/apache/camel/pull/2454


---