Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Find the size of an OutputStream  RSS feed

 
zoe ween
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
does anyone know a nice way to get the size of an outputStream? I gave it quite some thought already, but (sadly) could not come up with a nice way yet.
Thanks for your help,
*zoe*
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suppose that depends on what you mean by "size". I'm guessing that most likely you want the total number of bytes which have been writtenthrough the stream. If that's the case, I have a simple class for that:

To use, just wrap a CountingOutputStream around whatever other stream you want to keep count of.

CountingInputStream is a bit more complex, as there are a few more methods to handle (including skip(), mark(), reset()). Similar idea though.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!