Android Open Source - HorizontalImageScroller-Modified Flushed Input Stream






From Project

Back to project page HorizontalImageScroller-Modified.

License

The source code is released under:

Apache License

If you think the Android project HorizontalImageScroller-Modified listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * Copied from comment #12 on http://code.google.com/p/android/issues/detail?id=6066
 *///from  w w w  .  ja  va2 s  . c o m
package com.twotoasters.android.horizontalimagescroller.io;


import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;


class FlushedInputStream extends FilterInputStream {
   
    /**
     * The constructor that takes in the InputStream reference.
     *
     * @param inputStream the input stream reference.
     */
    public FlushedInputStream(final InputStream inputStream) {
        super(inputStream);
    }
 
    /**
     * Overriding the skip method to actually skip n bytes.
     * This implementation makes sure that we actually skip 
     * the n bytes no matter what.
     * {@inheritDoc}
     */
    @Override
    public long skip(final long n) throws IOException {
        long totalBytesSkipped = 0L;
        //If totalBytesSkipped is equal to the required number 
        //of bytes to be skipped i.e. "n"
        //then come out of the loop.
        while (totalBytesSkipped < n) {
            //Skipping the left out bytes.
            long bytesSkipped = in.skip(n - totalBytesSkipped);
            //If number of bytes skipped is zero then 
            //we need to check if we have reached the EOF
            if (bytesSkipped == 0L) {
                //Reading the next byte to find out whether we have reached EOF.
                int bytesRead = read();
                //If bytes read count is less than zero (-1) we have reached EOF.
                //Cant skip any more bytes.
                if (bytesRead < 0) {
                    break;  // we reached EOF
                } else {
                    //Since we read one byte we have actually 
                    //skipped that byte hence bytesSkipped = 1
                    bytesSkipped = 1; // we read one byte
                }
            }
            //Adding the bytesSkipped to totalBytesSkipped
            totalBytesSkipped += bytesSkipped;
        }        
        return totalBytesSkipped;
    }
}




Java Source Code List

com.twotoasters.android.horizontalimagescroller.image.BitmapHelper.java
com.twotoasters.android.horizontalimagescroller.image.ImageToLoadDrawableResource.java
com.twotoasters.android.horizontalimagescroller.image.ImageToLoadSD.java
com.twotoasters.android.horizontalimagescroller.image.ImageToLoadUrl.java
com.twotoasters.android.horizontalimagescroller.image.ImageToLoad.java
com.twotoasters.android.horizontalimagescroller.image.OnImageLoadedListener.java
com.twotoasters.android.horizontalimagescroller.io.ExternalStorageHelper.java
com.twotoasters.android.horizontalimagescroller.io.FlushedInputStream.java
com.twotoasters.android.horizontalimagescroller.io.ImageCacheManager.java
com.twotoasters.android.horizontalimagescroller.io.ImageUrlRequestCacheKey.java
com.twotoasters.android.horizontalimagescroller.io.ImageUrlRequest.java
com.twotoasters.android.horizontalimagescroller.io.MemoryCache.java
com.twotoasters.android.horizontalimagescroller.sample.MainActivity.java
com.twotoasters.android.horizontalimagescroller.widget.HorizontalImageScrollerAdapter.java
com.twotoasters.android.horizontalimagescroller.widget.HorizontalImageScroller.java
com.twotoasters.android.horizontalimagescroller.widget.HorizontalListView.java
com.twotoasters.android.horizontalimagescroller.widget.SelectionToggleOnItemClickListener.java
com.twotoasters.android.horizontalimagescroller.widget.VerticalScrollView.java