将正则表达式应用于Java I / O流 [英] Applying a regular expression to a Java I/O Stream
问题描述
我寻找一个将正则表达式应用于Java I / O流的示例,该流不会简单地将流转换为字符串,因为我希望保留二进制数据。 Internet上的大多数示例都集中在文本数据上......
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...
推荐答案
Java Standard上不存在所需的功能。你必须使用 jakarta regexp ,特别是 StreamCharacterIterator 类。这个类封装了一个用于regexp操作的InputStream。
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.
如果你想使用标准正则表达式包,我建议你从上一个类中获取一个来源这里并通过实施 CharSequence 来更改合同而不是 CharacterIterator 。
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.
这篇关于将正则表达式应用于Java I / O流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!