给定 Java InputStream,如何确定流中的当前偏移量? [英] Given a Java InputStream, how can I determine the current offset in the stream?

查看:16
本文介绍了给定 Java InputStream,如何确定流中的当前偏移量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要一个通用的、可重复使用的 getPosition() 方法,它会告诉我从流的起点读取的字节数.理想情况下,我希望它与所有 InputStreams 一起使用,这样我就不必在从不同来源获取它们时将它们中的每一个都包装起来.

I'd like something like a generic, re-usable getPosition() method that will tell me the number of bytes read from the starting point of the stream. Ideally, I would prefer this to work with all InputStreams, so that I don't have to wrap each and every one of them as I get them from disparate sources.

这样的野兽存在吗?如果没有,有人可以推荐一个计数 InputStream 的现有实现吗?

Does such a beast exist? If not, can anyone recommend an existing implementation of a counting InputStream?

推荐答案

看一看 CountingInputStream 在 Commons IO 包中.他们也有很多其他有用的 InputStream 变体.

Take a look at CountingInputStream in the Commons IO package. They have a pretty good collection of other useful InputStream variants as well.

这篇关于给定 Java InputStream,如何确定流中的当前偏移量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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