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
TimeoutReader
request an underlying reader to read with the specified timeout.IOException
will be thrown, if timeout is reached. Clients may wrap aTimeoutReader
around 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 aTimeoutReader
that has a given timeout in milliseconds.TimeoutReader(Reader input, int timeout, TimeUnit timeUnit)
Creates aTimeoutReader
that has a given timeout.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
int
read(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 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
public TimeoutReader(Reader input, int timeout, TimeUnit timeUnit)
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 Detail
-
read
public int read(char[] cbuf, int off, int len) throws IOException
- Specified by:
read
in classReader
- Throws:
IOException
-
close
public void close() throws IOException
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in classReader
- Throws:
IOException
-
-