timeout « API « Java I/O Q&A





1. Is it possible to read from a Java InputStream with a timeout?    stackoverflow.com

Specifically, the problem is to write a method like this:

int maybeRead(InputStream in, long timeout)
where the return value is the same as in.read() if data is available within 'timeout' milliseconds, and -2 ...

2. Can I set a timeout for a InputStream's read() function?    stackoverflow.com

I have a DataInputStream that I obtained from a Socket. Is there any way I can set a timeout for dis.read(...)? Currently I spawn a new thread to do the read. ...

3. Java serial comm API - what does inputstream.read() return if a timeout occurs?    stackoverflow.com

Anyone know the exact value returned when the serial driver times out? I'm running Java1.5 on Win XP.

4. setting a timeout for an InputStreamreader variable    stackoverflow.com

I have a server running that accepts connections made through client sockets, I need to read the input from this client socket, now suppose the client opened a connection to ...

5. Is setting a timeout on ObjectInputStream.readObject() safe?    stackoverflow.com

I have an ObjectInputStream connected to an ObjectOutputStream through a socket, and I've been using Socket.setSoTimeout() to make ObjectInputStream.readObject() only block for 100ms. Since I started doing this I've been getting ...

6. InputStream & timeout    coderanch.com

Hi, I want to set timeout on InputStream. After some search I have the following: import java.io.InputStream; import java.io.IOException; public class TimeoutInputStream extends InputStream { InputStream is; int timeout; public TimeoutInputStream(InputStream is, int timeout) { this.is = is; this.timeout = timeout; } public int read() throws IOException { long starttime = System.currentTimeMillis(); while(is.available() < 1) { long time = System.currentTimeMillis(); if((time ...

7. HttpRequest InputStream read timeout    coderanch.com

Hi, I am getting a java.io.InterruptedIOException: Read timed out when trying to read the input stream from the HttpRequest object. This is done to get the form parameter values for content-type=multipart/form-data This application is deployed on a Websphere Application server and working fine as a standalone application (Say Server 1). Another box (Say Server 2) is hosting a single servlet application ...

8. Timeout for InputStream    coderanch.com

No, as far as I know, a blocking read() blocks forever, if there is no data available, but the end of stream has not been reached. You can't have a time-out. You can't interrupt it. Closing the stream, from another thread, might work for some types of stream, but if it does work, it's an undocumented and unreliable feature. Rubbish, ain't ...

9. FileReader TimeOut help    coderanch.com

Hello! I could think of the only way to add pause to FileReader - to create separate thread, which will watch reading time and report timeouts. For example, like this (for simplicity i overrode only read() method): public class MyReader extends FileReader { public static class TimeoutException extends Exception {} private Lock readLock = new ReentrantLock(); private Condition readCondition = readLock.newCondition(); ...





11. timeout for inputstream.read?    forums.oracle.com

Im using a socket application, and i have a big problem. Some people like to try to "crash" my application, and ive discovered a large glitch in my design. first ill walk through the connection process. 1. connection is accepted by the socket thread. 2. socket is handed to another thread, which handles the queque. 3. the last thread starts a ...

12. I add a timeout for InputStream read().    forums.oracle.com

I am looking for a timeout for InputStream read() since Java doesn't support it. I use a Timer class to handle the timeout value and put the InputStream.read() into another thread. When the time is up, the Timer object will stop the thread of reading. What do you think about this solution? Do you have any other better solution? thanks