在输入流中搜索
有没有办法在输入流上有效搜索 2 个固定字节?
背景
我必须处理 Android 上的多部分 Http 流量。 (来自 IP 网络摄像头的动态 JPEG)。
我已经在 anddev.org 上找到了一些类来处理它。现在我做了一些性能改进。为了找到 JPEG 的开头,我需要在 InputStream 中找到 JPEG 的幻数 (SOI=FFD8)。
Is there a way to do a efficient search for 2 fix bytes on an InputStream?
Background
I have to deal with Multipart Http traffic on Android. (Motion JPEG from a IP Webcam).
I already found some Classes on anddev.org to deal with it. Now I do some performance improvements. To find the start of a JPEG, I need to find the magic number for JPEGs (SOI=FFD8) in the InputStream.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于您不知道这 2 个字节在流中的位置,因此您必须查看整个输入。这意味着,您的表现至少是线性的。线性查找两个字节很简单:
Since you've no idea where in the stream those 2 bytes are, you'll have to look at the entire input. That means, your performance will be at least linear. Two find two bytes linearly is straightforward: