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

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

问题描述

我喜欢类似于通用的,可重复使用的 getPosition()方法,它会告诉我从流的起始点读取的字节数。理想情况下,我更喜欢使用它来处理所有的InputStream,所以当我从不同的来源获取它们时,我不必包装它们中的每一个。

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天全站免登陆