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

Positions in Streams  RSS feed

 
Maheshwari Anuj
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I want to get the current position of the Input Stream in terms of byte. Can anyone help please.

Regards,
Anuj
 
Mike Simmons
Ranch Hand
Posts: 3090
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An InputStream doesn't really support this directly. If you need it, the best way would be to extend InputStream and keep count of how many bytes have been read so far. You can see an example of this here. That's for an OutputStream. But as the second poster says, a solution for InputStream is similar, just with more methods.
 
senthil kumar. J
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure if this is your requirement, Inpustream has methods like mark(int readlimit) and reset()

- mark( int readlimit) - marks the current position in the stream with readlimit argument specifying the number of bytes to be allowed before marking them.

- reset() - reposition to the point where it was marked.

but before using this need to make sure whether marking is supported by the inputstream or not
use markSupported() to confirm.

Correct me if i am wrong.
 
Maheshwari Anuj
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Mike.. Seems a bit traditional but if InputStream does not support this then we have to go like this only..
 
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!