As the title says, I need to know how many bytes the file has that’s “behind” an InputStream.
I don’t want to download all bytes and count (takes to long). I just need to know how many bytes the file has.
Like this:
int numberOfBytes = countBytes(inputStream);
So, I need an implementation for countBytes(InputStream inputStream)
Other than by consuming the entire stream and counting the bytes, you can’t (there’s no API for it).
There’s the
available()method, but it quite explicitly doesn’t do what you’re asking:If the
InputStreamis associated with a file (and not, say, a socket), perhaps you could use a different API to get its size?