将正则表达式应用于 Java I/O 流 [英] Applying a regular expression to a Java I/O Stream

查看:25
本文介绍了将正则表达式应用于 Java I/O 流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我寻找一个将正则表达式应用于 Java I/O 流的示例,该示例不会像我想保留二进制数据那样简单地将流转换为字符串.网上的例子大部分都是针对文本数据的...

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 标准中不存在.您将不得不使用 jakarta regexp,特别是 StreamCharacterIterator 类.该类封装了一个 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆