Link to home
Start Free TrialLog in
Avatar of nirma
nirma

asked on

TimeOut in Inputstream

Hi, I am looking for an efficient implementation of InputStream whit timeout, like in sockets

The constructor of this Inputstream should get a timeout parameter
The read method should throw IOException if waiting on read exceeds this timeout.
Avatar of Venci75
Venci75

What kind of data will return this input stream?

Normally - you should do this by starting a thread that reads the data. The main thread will start the it and sleep for the period of the timeout (for example using 'this.sleep(timeout)'. If the second thread reads data - it will notify the first thread about this - for example 'mainThread.notify()'
ASKER CERTIFIED SOLUTION
Avatar of antons061400
antons061400

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mick Barry
One problem may be that many IO call will block, and cannot be interrupted making it difficult to achieve what you require.
Can I ask why you need this?