Filter (search and replace) array of bytes in an InputStream

后端 未结 6 1687
清歌不尽
清歌不尽 2020-11-30 05:49

I have an InputStream which takes the html file as input parameter. I have to get the bytes from the input stream .

I have a string: \"XYZ\". I\'d like

6条回答
  •  暖寄归人
    2020-11-30 06:30

    The following approach will work but I don't how big the impact is on the performance.

    1. Wrap the InputStream with a InputStreamReader,
    2. wrap the InputStreamReader with a FilterReader that replaces the strings, then
    3. wrap the FilterReader with a ReaderInputStream.

    It is crucial to choose the appropriate encoding, otherwise the content of the stream will become corrupted.

    If you want to use regular expressions to replace the strings, then you can use Streamflyer, a tool of mine, which is a convenient alternative to FilterReader. You will find an example for byte streams on the webpage of Streamflyer. Hope this helps.

提交回复
热议问题