InputStreamReader buffering issue

后端 未结 6 889
感情败类
感情败类 2021-02-05 21:18

I am reading data from a file that has, unfortunately, two types of character encoding.

There is a header and a body. The header is always in ASCII and defines the char

6条回答
  •  孤独总比滥情好
    2021-02-05 21:50

    Here is the pseudo code.

    1. Use InputStream, but do not wrap a Reader around it.
    2. Read bytes containing header and store them into ByteArrayOutputStream.
    3. Create ByteArrayInputStream from ByteArrayOutputStream and decode header, this time wrap ByteArrayInputStream into Reader with ASCII charset.
    4. Compute the length of non-ascii input, and read that number of bytes into another ByteArrayOutputStream.
    5. Create another ByteArrayInputStream from the second ByteArrayOutputStream and wrap it with Reader with charset from the header.

提交回复
热议问题