/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* An implementation of <code>ImageInputStream</code> that gets its
* input from a regular <code>InputStream</code>. A memory buffer is
* used to cache at least the data between the discard position and
* the current read position.
*
* <p> In general, it is preferable to use a
* <code>FileCacheImageInputStream</code> when reading from a regular
* <code>InputStream</code>. This class is provided for cases where
* it is not possible to create a writable temporary file.
*
*/
/** The referent to be registered with the Disposer. */
/** The DisposerRecord that resets the underlying MemoryCache. */
/**
* Constructs a <code>MemoryCacheImageInputStream</code> that will read
* from a given <code>InputStream</code>.
*
* @param stream an <code>InputStream</code> to read from.
*
* @exception IllegalArgumentException if <code>stream</code> is
* <code>null</code>.
*/
throw new IllegalArgumentException("stream == null!");
}
if (getClass() == MemoryCacheImageInputStream.class) {
disposerReferent = new Object();
} else {
disposerReferent = new StreamFinalizer(this);
}
}
checkClosed();
bitOffset = 0;
} else {
return -1;
}
}
checkClosed();
if (b == null) {
throw new NullPointerException("b == null!");
}
throw new IndexOutOfBoundsException
("off < 0 || len < 0 || off+len > b.length || off+len < 0!");
}
bitOffset = 0;
if (len == 0) {
return 0;
}
if (len > 0) {
return len;
} else {
return -1;
}
}
}
/**
* Returns <code>true</code> since this
* <code>ImageInputStream</code> caches data in order to allow
* seeking backwards.
*
* @return <code>true</code>.
*
* @see #isCachedMemory
* @see #isCachedFile
*/
public boolean isCached() {
return true;
}
/**
* Returns <code>false</code> since this
* <code>ImageInputStream</code> does not maintain a file cache.
*
* @return <code>false</code>.
*
* @see #isCached
* @see #isCachedMemory
*/
public boolean isCachedFile() {
return false;
}
/**
* Returns <code>true</code> since this
* <code>ImageInputStream</code> maintains a main memory cache.
*
* @return <code>true</code>.
*
* @see #isCached
* @see #isCachedFile
*/
public boolean isCachedMemory() {
return true;
}
/**
* Closes this <code>MemoryCacheImageInputStream</code>, freeing
* the cache. The source <code>InputStream</code> is not closed.
*/
super.close();
}
/**
* {@inheritDoc}
*/
// Empty finalizer: for performance reasons we instead use the
// Disposer mechanism for ensuring that the underlying
// MemoryCache is reset prior to garbage collection
}
}
public synchronized void dispose() {
}
}
}
}