• BlackBerry Dynamics
  • Runtime library for Android applications
  • 12.0.1.79
EofSensorInputStream Class Reference

A stream wrapper that triggers actions on close() and EOF. More...

Inheritance diagram for EofSensorInputStream:
InputStream ConnectionReleaseTrigger

Description

Primarily used to auto-release an underlying connection when the response body is consumed or no longer needed.

This class is based on AutoCloseInputStream in HttpClient 3.1, but has notable differences. It does not allow mark/reset, distinguishes different kinds of event, and does not always close the underlying stream on EOF. That decision is left to the watcher .

See also
EofSensorWatcher EofSensorWatcher
Author
Roland Weber
Ortwin Glueck
Eric Johnson
Mike Bowler
Version
Revision
672367
Since
4.0

Notice

The following notice applies to the original API on which this API is based, and to its documentation. The documentation of this API has been revised from the original.

/*
 * Copyright (C) 2006 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

Public Member Functions

 EofSensorInputStream (final InputStream in, final EofSensorWatcher watcher)
 Creates a new EOF sensor. More...
 
void close () throws IOException
 non-javadoc, see base class java.io.InputStream
 
void releaseConnection () throws IOException
 Same as close().
 
void abortConnection () throws IOException
 Aborts this stream. More...
 

Protected Member Functions

boolean isReadAllowed () throws IOException
 Checks whether the underlying stream can be read from. More...
 
void checkEOF (int eof) throws IOException
 Detects EOF and notifies the watcher. More...
 
void checkClose () throws IOException
 Detects stream close and notifies the watcher. More...
 
void checkAbort () throws IOException
 Detects stream abort and notifies the watcher. More...
 

Protected Attributes

InputStream wrappedStream
 The wrapped input stream, while accessible. More...
 

Constructor & Destructor Documentation

◆ EofSensorInputStream()

EofSensorInputStream ( final InputStream  in,
final EofSensorWatcher  watcher 
)

If no watcher is passed, the underlying stream will simply be closed when EOF is detected or close is called. Otherwise, the watcher decides whether the underlying stream should be closed before detaching from it.

Parameters
inthe wrapped stream
watcherthe watcher for events, or null for auto-close behavior without notification

Member Function Documentation

◆ isReadAllowed()

boolean isReadAllowed ( ) throws IOException
protected
Returns
true if the underlying stream is accessible, false if this stream is in EOF mode and detached from the underlying stream
Exceptions
IOExceptionif this stream is already closed

◆ checkEOF()

void checkEOF ( int  eof) throws IOException
protected

This method should only be called while the underlying stream is still accessible. Use 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.

Parameters
eofthe result of the calling read operation. A negative value indicates that EOF is reached.
Exceptions
IOExceptionin case of an IO problem on closing the underlying stream

◆ checkClose()

void checkClose ( ) throws IOException
protected

There's not much to detect since this is called by 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.

Exceptions
IOExceptionin case of an IO problem on closing the underlying stream

◆ checkAbort()

void checkAbort ( ) throws IOException
protected

There's not much to detect since this is called by 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 closed gracefully. This stream will be detached from the underlying stream to prevent multiple notifications to the watcher.

Exceptions
IOExceptionin case of an IO problem on closing the underlying stream

◆ abortConnection()

void abortConnection ( ) throws IOException

This is a special version of 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.

Implements ConnectionReleaseTrigger.

Member Data Documentation

◆ wrappedStream

InputStream wrappedStream
protected

The value changes to null when the wrapped stream becomes inaccessible.