Top Description Fields Constructors Methods
org.eclipse.jgit.util.io

public Class TimeoutInputStream

extends FilterInputStream
Class Inheritance
Imports
java.io.FilterInputStream, .IOException, .InputStream, .InterruptedIOException, java.text.MessageFormat, org.eclipse.jgit.internal.JGitText

InputStream with a configurable timeout.

Field Summary

Modifier and TypeField and Description
private final InterruptTimer
private int
Inherited from java.io.FilterInputStream:
in

Constructor Summary

AccessConstructor and Description
public
TimeoutInputStream(final InputStream
base input stream (to read from). The stream must be interruptible (most socket streams are).
src
,
final InterruptTimer
timer to manage the timeouts during reads.
timer
)

Wrap an input stream with a timeout on all read operations.

Method Summary

Modifier and TypeMethod and Description
private void
private void
public int

Returns:

number of milliseconds before aborting a read.
getTimeout
()

Get number of milliseconds before aborting a read.

public int
read()

Overrides java.io.FilterInputStream.read.

Reads the next byte of data from the input stream.

public int
read(byte[]
the buffer into which the data is read.
buf
)

Overrides java.io.FilterInputStream.read.

Reads up to b.length bytes of data from this input stream into an array of bytes.

public int
read(byte[]
the buffer into which the data is read.
buf
,
int
the start offset in array b at which the data is written.
off
,
int
the maximum number of bytes to read.
cnt
)

Overrides java.io.FilterInputStream.read.

Reads up to len bytes of data from this input stream into an array of bytes.

private InterruptedIOException
public void
setTimeout(int
number of milliseconds before aborting a read. Must be > 0.
millis
)

Set number of milliseconds before aborting a read.

public long
skip(long
the number of bytes to be skipped.
cnt
)

Overrides java.io.FilterInputStream.skip.

Skips over and discards n bytes of data from the input stream.

Inherited from java.io.FilterInputStream:
availableclosemarkmarkSupportedreset

Field Detail

myTimerback to summary
private final InterruptTimer myTimer
timeoutback to summary
private int timeout

Constructor Detail

TimeoutInputStreamback to summary
public TimeoutInputStream(final InputStream src, final InterruptTimer timer)

Wrap an input stream with a timeout on all read operations.

Parameters
src:InputStream

base input stream (to read from). The stream must be interruptible (most socket streams are).

timer:InterruptTimer

timer to manage the timeouts during reads.

Method Detail

beginReadback to summary
private void beginRead()
endReadback to summary
private void endRead()
getTimeoutback to summary
public int getTimeout()

Get number of milliseconds before aborting a read.

Returns:int

number of milliseconds before aborting a read.

readback to summary
public int read() throws IOException

Overrides java.io.FilterInputStream.read.

Doc from java.io.FilterInputStream.read.

Reads the next byte of data from the input stream. The value byte is returned as an int in the range 0 to 255. If no byte is available because the end of the stream has been reached, the value -1 is returned. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown.

Returns:int

the next byte of data, or -1 if the end of the stream is reached.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
readback to summary
public int read(byte[] buf) throws IOException

Overrides java.io.FilterInputStream.read.

Doc from java.io.FilterInputStream.read.

Reads up to b.length bytes of data from this input stream into an array of bytes. This method blocks until some input is available.

Parameters
buf:byte[]

the buffer into which the data is read.

Returns:int

the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
readback to summary
public int read(byte[] buf, int off, int cnt) throws IOException

Overrides java.io.FilterInputStream.read.

Doc from java.io.FilterInputStream.read.

Reads up to len bytes of data from this input stream into an array of bytes. If len is not zero, the method blocks until some input is available; otherwise, no bytes are read and 0 is returned.

Parameters
buf:byte[]

the buffer into which the data is read.

off:int

the start offset in array b at which the data is written.

cnt:int

the maximum number of bytes to read.

Returns:int

the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
readTimedOutback to summary
private InterruptedIOException readTimedOut(InterruptedIOException e)
setTimeoutback to summary
public void setTimeout(int millis)

Set number of milliseconds before aborting a read.

Parameters
millis:int

number of milliseconds before aborting a read. Must be > 0.

skipback to summary
public long skip(long cnt) throws IOException

Overrides java.io.FilterInputStream.skip.

Doc from java.io.FilterInputStream.skip.

Skips over and discards n bytes of data from the input stream. The skip method may, for a variety of reasons, end up skipping over some smaller number of bytes, possibly 0. The actual number of bytes skipped is returned.

Parameters
cnt:long

the number of bytes to be skipped.

Returns:long

the actual number of bytes skipped.

Annotations
@Override
Exceptions
IOException:
if in.skip(n) throws an IOException.