java.lang.Object
java.io.InputStream
java.io.PipedInputStream
net.i2p.util.TimeoutPipedInputStream
- All Implemented Interfaces:
Closeable, AutoCloseable
Adds
setReadTimeout(int). Must be used with a TimeoutPipedOutputStream. To support InternalSocket.setSoTimeout(int). Package private, not a part of the public API, not for general use.
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanTrue once the reading end has closed.private booleanTrue once the writing end has closed.private intMilliseconds a read waits for data.Fields inherited from class PipedInputStream
buffer, in, out, PIPE_SIZEConstructor Summary
ConstructorsConstructorDescriptionTimeoutPipedInputStream(int pipeSize) Creates the pipe with the requested buffer size.Method Summary
Public MethodsModifier and TypeMethodDescriptionvoidclose()Overridden to save state.intread()Read the next byte, blocking until available or the timeout is reached.voidsetReadTimeout(int ms) Must be called before blocking read call.(package private) voidTo save state.Methods inherited from class PipedInputStream
available, connect, read, receiveMethods inherited from class InputStream
mark, markSupported, nullInputStream, read, readAllBytes, readNBytes, readNBytes, reset, skip, skipNBytes, transferTo
Field Details
timeout
private int timeoutMilliseconds a read waits for data._closedByWriter
private boolean _closedByWriterTrue once the writing end has closed._closedByReader
private volatile boolean _closedByReaderTrue once the reading end has closed.
Constructor Details
TimeoutPipedInputStream
public TimeoutPipedInputStream(int pipeSize) Creates the pipe with the requested buffer size.- Parameters:
pipeSize- the pipe buffer size in bytes, as passed to the superclass
Method Details
read
Read the next byte, blocking until available or the timeout is reached.- Overrides:
readin classPipedInputStream- Throws:
SocketTimeoutException- if timeout is reachedIOException
setReadTimeout
public void setReadTimeout(int ms) Must be called before blocking read call.- Parameters:
ms- less than or equal to zero means forever
x_receivedLast
void x_receivedLast()To save state. We have to do this because can't get to closedByWriter in super.close
Overridden to save state. We have to do this because can't get to closedByReader in super.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classPipedInputStream- Throws:
IOException