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
public class TimeoutReader extends Reader
Reads text from a parent reader with the given timeout.Each read request causes a
TimeoutReaderrequest an underlying reader to read with the specified timeout.IOExceptionwill be thrown, if timeout is reached. Clients may wrap aTimeoutReaderaround any input stream reader whoseread()operations may hang out, such asProcess.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)) { ... }
-
-
Constructor Summary
Constructors Constructor Description TimeoutReader(Reader input, int timeout)Creates aTimeoutReaderthat has a given timeout in milliseconds.TimeoutReader(Reader input, int timeout, TimeUnit timeUnit)Creates aTimeoutReaderthat has a given timeout.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()intread(char[] cbuf, int off, int len)-
Methods inherited from class java.io.Reader
mark, markSupported, nullReader, read, read, read, ready, reset, skip, transferTo
-
-
-
-
Constructor Detail
-
TimeoutReader
public TimeoutReader(Reader input, int timeout)
Creates aTimeoutReaderthat has a given timeout in milliseconds.- Parameters:
input- the parent reader to wrap, cannot benulltimeout- the maximum time to wait in milliseconds
-
TimeoutReader
public TimeoutReader(Reader input, int timeout, TimeUnit timeUnit)
Creates aTimeoutReaderthat has a given timeout.- Parameters:
input- the parent reader to wrap, cannot benulltimeout- the maximum time to waittimeUnit- the time unit of thetimeoutargument
-
-
Method Detail
-
read
public int read(char[] cbuf, int off, int len) throws IOException- Specified by:
readin classReader- Throws:
IOException
-
close
public void close() throws IOException- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein classReader- Throws:
IOException
-
-