• 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

reading a stream twice but download it only once

 
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,

following problem:
i have an audio player which retrieves a stream from a website and plays it, which works pretty good.
i want the user to be able to play forward. But i dont want the user to be able to play too far forward, so i have to detect how many bytes has been transfered. And thats where i get stuck, because i have a "wrapped" player class which plays the song from an EofSensorInputStream (thats an InputStream from apache which i cannot change to another InputStream) and i have the SliderUI which also uses the stream (passed as constructor argument) which should now detect how many bytes has been transfered.

I can read the the stream only once, so either in my SliderUI, but then the data is lost for the player. Or i play the song, but then the data is lost for the SliderUI.

Does anyone have an idea how to do this?
 
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't quite get your problem.

As far as google says, EofSensorInputStream class is not final, so you can easily create its descendants and implement there any check you want.

And if you still want to read one stream several times, one of the possible solutions is to read data once in a 'buffer', and then read this buffer as many times as you want, like this:

Of course if your initial stream is too large or you need to read it simultaneously, this solution will not do.
 
olze oli
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm using htmlunit and i think it would be overkill to create a new class and change the whole htmlunit code.
i think i got a solution or workaround:
download the stream as tmp file, play the song from it and get the filesize and compare it with the content length given by the http server
 
He was expelled for perverse baking experiments. This tiny ad is a model student:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic