Reading from InputStreamReader does not work #37

Closed
robert-bor opened this Issue Jul 15, 2013 · 2 comments

Comments

Projects
None yet
1 participant
@robert-bor
Owner

robert-bor commented Jul 15, 2013

Source: Kazeem Akinrinde

"I have been unable to load CSV from a file, it has only been working only for StringReader and not reader from InputStream. It may be Charset issue, but other CSV readers have no problem reading the same set of files."

Verified to be correct

@robert-bor

This comment has been minimized.

Show comment
Hide comment
@robert-bor

robert-bor Jul 15, 2013

Owner
    @Test
    public void WindowsCRLF0x0d0x0a() throws IOException {
        char[] file = new char[] {
            'n', 'a', 'm', 'e', 0x0d, 0x0a,
            'A', 'l', 'p', 'h', 'a', 0x0d, 0x0a,
            'B', 'e', 't', 'a', 0x0d, 0x0a,
            'G', 'a', 'm', 'm', 'a'
        };
        String fileText = new String(file);
        Reader reader = new StringReader(fileText);
        CsvReader<BeanSimple> csvReader = new CsvReaderImpl<BeanSimple>(reader, BeanSimple.class);
        final List<BeanSimple> beans = csvReader.readBeans();
        assertEquals(3, beans.size());
    }
Owner

robert-bor commented Jul 15, 2013

    @Test
    public void WindowsCRLF0x0d0x0a() throws IOException {
        char[] file = new char[] {
            'n', 'a', 'm', 'e', 0x0d, 0x0a,
            'A', 'l', 'p', 'h', 'a', 0x0d, 0x0a,
            'B', 'e', 't', 'a', 0x0d, 0x0a,
            'G', 'a', 'm', 'm', 'a'
        };
        String fileText = new String(file);
        Reader reader = new StringReader(fileText);
        CsvReader<BeanSimple> csvReader = new CsvReaderImpl<BeanSimple>(reader, BeanSimple.class);
        final List<BeanSimple> beans = csvReader.readBeans();
        assertEquals(3, beans.size());
    }

robert-bor added a commit that referenced this issue Jul 15, 2013

Issue #37 - problem was that a Windows CRLF sequence was not read cor…
…rectly. The first character was interpreted as the line-break, but the second character was still added to the new line. The second character is now dropped completely.

@ghost ghost assigned robert-bor Jul 15, 2013

@robert-bor robert-bor closed this Jul 15, 2013

@robert-bor

This comment has been minimized.

Show comment
Hide comment
@robert-bor

robert-bor Jul 15, 2013

Owner

The problem was not reading from file, but reading from files with a Windows CRLF notation. The problem has been fixed and a test has been added to check the fix.

Owner

robert-bor commented Jul 15, 2013

The problem was not reading from file, but reading from files with a Windows CRLF notation. The problem has been fixed and a test has been added to check the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment