Methods Summary |
---|
public void | abortConnection()Aborts this stream.
This is a special version of {@link #close close()} which prevents
re-use of the underlying connection, if any. Calling this method
indicates that there should be no attempt to read until the end of
the stream.
// tolerate multiple calls
selfClosed = true;
checkAbort();
|
public int | available()
int a = 0; // not -1
if (isReadAllowed()) {
try {
a = wrappedStream.available();
// no checkEOF() here, available() can't trigger EOF
} catch (IOException ex) {
checkAbort();
throw ex;
}
}
return a;
|
protected void | checkAbort()Detects stream abort and notifies the watcher.
There's not much to detect since this is called by
{@link #abortConnection abortConnection}.
The watcher will only be notified if this stream is aborted
for the first time and before EOF has been detected or the
stream has been {@link #close closed} gracefully.
This stream will be detached from the underlying stream to prevent
multiple notifications to the watcher.
if (wrappedStream != null) {
try {
boolean scws = true; // should close wrapped stream?
if (eofWatcher != null)
scws = eofWatcher.streamAbort(wrappedStream);
if (scws)
wrappedStream.close();
} finally {
wrappedStream = null;
}
}
|
protected void | checkClose()Detects stream close and notifies the watcher.
There's not much to detect since this is called by {@link #close close}.
The watcher will only be notified if this stream is closed
for the first time and before EOF has been detected.
This stream will be detached from the underlying stream to prevent
multiple notifications to the watcher.
if (wrappedStream != null) {
try {
boolean scws = true; // should close wrapped stream?
if (eofWatcher != null)
scws = eofWatcher.streamClosed(wrappedStream);
if (scws)
wrappedStream.close();
} finally {
wrappedStream = null;
}
}
|
protected void | checkEOF(int eof)Detects EOF and notifies the watcher.
This method should only be called while the underlying stream is
still accessible. Use {@link #isReadAllowed isReadAllowed} to
check that condition.
If EOF is detected, the watcher will be notified and this stream
is detached from the underlying stream. This prevents multiple
notifications from this stream.
if ((wrappedStream != null) && (eof < 0)) {
try {
boolean scws = true; // should close wrapped stream?
if (eofWatcher != null)
scws = eofWatcher.eofDetected(wrappedStream);
if (scws)
wrappedStream.close();
} finally {
wrappedStream = null;
}
}
|
public void | close()
// tolerate multiple calls to close()
selfClosed = true;
checkClose();
|
protected boolean | isReadAllowed()Checks whether the underlying stream can be read from.
if (selfClosed) {
throw new IOException("Attempted read on closed stream.");
}
return (wrappedStream != null);
|
public int | read()
int l = -1;
if (isReadAllowed()) {
try {
l = wrappedStream.read();
checkEOF(l);
} catch (IOException ex) {
checkAbort();
throw ex;
}
}
return l;
|
public int | read(byte[] b, int off, int len)
int l = -1;
if (isReadAllowed()) {
try {
l = wrappedStream.read(b, off, len);
checkEOF(l);
} catch (IOException ex) {
checkAbort();
throw ex;
}
}
return l;
|
public int | read(byte[] b)
int l = -1;
if (isReadAllowed()) {
try {
l = wrappedStream.read(b);
checkEOF(l);
} catch (IOException ex) {
checkAbort();
throw ex;
}
}
return l;
|
public void | releaseConnection()Same as {@link #close close()}.
this.close();
|