Package com._1c.g5.v8.dt.common.io
Class TimeoutReader
java.lang.Object
java.io.Reader
com._1c.g5.v8.dt.common.io.TimeoutReader
- All Implemented Interfaces:
Closeable
,AutoCloseable
,Readable
Reads text from a parent reader with the given timeout.
Each read request causes a TimeoutReader
request an underlying reader to read with
the specified timeout. IOException
will be thrown, if timeout is reached.
Clients may wrap a TimeoutReader
around any input stream reader whose read()
operations may hang out, such as Process.getInputStream()
.
Example of usage:
// reads process input with 10 seconds timeout try (TimeoutReader reader = new TimeoutReader( new InputStreamReader(process.getInputStream(), StandardCharsets.UTF_8), 10 * 1000)) { ... }
-
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionTimeoutReader
(Reader input, int timeout) Creates aTimeoutReader
that has a given timeout in milliseconds.TimeoutReader
(Reader input, int timeout, TimeUnit timeUnit) Creates aTimeoutReader
that has a given timeout. -
Method Summary
Methods inherited from class java.io.Reader
mark, markSupported, nullReader, read, read, read, ready, reset, skip, transferTo
-
Constructor Details
-
TimeoutReader
Creates aTimeoutReader
that has a given timeout in milliseconds.- Parameters:
input
- the parent reader to wrap, cannot benull
timeout
- the maximum time to wait in milliseconds
-
TimeoutReader
Creates aTimeoutReader
that has a given timeout.- Parameters:
input
- the parent reader to wrap, cannot benull
timeout
- the maximum time to waittimeUnit
- the time unit of thetimeout
argument
-
-
Method Details
-
read
- Specified by:
read
in classReader
- Throws:
IOException
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in classReader
- Throws:
IOException
-