I seek an example of applying a regular expression to a Java I/O stream that doesn't simply convert the stream to a string as I would like to preserve binary data. Most of the examples on the Internet focus on text data...
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
The needed functionality is not present on Java Standard. You will have to use jakarta regexp, and specifically, the StreamCharacterIterator class. This class encapsulates a InputStream for use in regexp operations.
If you want to use the standard regular expression package, I would suggest take a the source from the previous class here and change the contract by implementing CharSequence instead of CharacterIterator.
回答2:
Convert the stream to a byte array.
回答3:
Try to use Ragel - regular expression tool with transitions callbacks.
Can applied to streams and chunks.
回答4:
Regex operations must be performed on strings, which are encoded bytes of binary data. You can't perform regex operations on bytes of data you have no idea what they represent.