From a common InputStream ? You will just need to read and read (for example, in the same buffer, again and again), counting how many bytes you read until you reach the end of the stream.
Of course, you will not be able to read the data yourself ... if you want to do this, you will need to store the data while reading, for example. by copying it to ByteArrayOutputStream .
(If you can process the data at the same time as developing the length, just do it - when you read it with a loop, each time reading it into the same buffer, just increase the counter to record how you read. You did not provide us no information on what you want to do with the stream.)
source share