Wanted to create an easy interface for reading lines from a stream. It should take care of all the annoying Java IO nitty-gritty for me and I wanted to use it simply by throwing it into a for loop.
Tag Archives: IO
Java: How to deal with the BOM in a Unicode InputStream
Ok, so I was happily reading CSV files from an SFTP server. The file content is returned as an InputStream and I I used a BufferedReader to read it line by line. Each line contained either a header or an order. The header lines started with the string “HDR”.
However, I suddenly discovered that my code was consistently skipping the first header (and as a result the orders belonging to it). The reason, I found, was simple. The first header, on the first line, didn’t start with “HDR”, it started with “â–¡HDR”! And that undisplayable square turned out to be a Unicode Byte Order Mark (BOM).
Continue reading Java: How to deal with the BOM in a Unicode InputStream