FileDocCategorySizeDatePackage
MemoryCacheImageInputStream.javaAPI DocAndroid 1.5 API3136Wed May 06 22:41:54 BST 2009javax.imageio.stream

MemoryCacheImageInputStream

public class MemoryCacheImageInputStream extends ImageInputStreamImpl
The MemoryCacheImageInputStream class implements ImageInputStream using a memory buffer for caching the data.
since
Android 1.0

Fields Summary
private InputStream
is
The is.
private org.apache.harmony.x.imageio.stream.RandomAccessMemoryCache
ramc
The ramc.
Constructors Summary
public MemoryCacheImageInputStream(InputStream stream)
Instantiates a new MemoryCacheImageInputStream which reads from the specified InputStream.

param
stream the InputStream to be read.


                                      
       
        if (stream == null) {
            throw new IllegalArgumentException("stream == null!");
        }
        is = stream;
    
Methods Summary
public voidclose()

        super.close();
        ramc.close();
    
public voidflushBefore(long pos)

        super.flushBefore(pos);
        ramc.freeBefore(getFlushedPosition());
    
public booleanisCached()

        return true;
    
public booleanisCachedFile()

        return false;
    
public booleanisCachedMemory()

        return true;
    
public intread()

        bitOffset = 0;

        if (streamPos >= ramc.length()) {
            int count = (int)(streamPos - ramc.length() + 1);
            int bytesAppended = ramc.appendData(is, count);

            if (bytesAppended < count) {
                return -1;
            }
        }

        int res = ramc.getData(streamPos);
        if (res >= 0) {
            streamPos++;
        }
        return res;
    
public intread(byte[] b, int off, int len)

        bitOffset = 0;

        if (streamPos >= ramc.length()) {
            int count = (int)(streamPos - ramc.length() + len);
            ramc.appendData(is, count);
        }

        int res = ramc.getData(b, off, len, streamPos);
        if (res > 0) {
            streamPos += res;
        }
        return res;