• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Positions in Streams

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Master Rancher
Posts: 4806
72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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..
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic