FileDocCategorySizeDatePackage
FullRequestInputStream.javaAPI DocJaudiotagger 2.0.42112Wed Mar 30 16:11:50 BST 2011org.jaudiotagger.audio.asf.io

FullRequestInputStream

public class FullRequestInputStream extends FilterInputStream
This implementation repeatedly reads from the wrapped input stream until the requested amount of bytes are read.
author
Christian Laireiter

Fields Summary
Constructors Summary
public FullRequestInputStream(InputStream source)
Creates an instance.

param
source stream to read from.

        super(source);
    
Methods Summary
public intread(byte[] buffer)
{@inheritDoc}

        return read(buffer, 0, buffer.length);
    
public intread(byte[] buffer, int off, int len)
{@inheritDoc}

        int totalRead = 0;
        int read;
        while (totalRead < len) {
            read = super.read(buffer, off + totalRead, len - totalRead);
            if (read >= 0) {
                totalRead += read;
            }
            if (read == -1) {
                throw new IOException((len - totalRead)
                        + " more bytes expected.");
            }
        }
        return totalRead;
    
public longskip(long amount)
{@inheritDoc}

        long skipped = 0;
        int zeroSkipCnt = 0;
        long currSkipped;
        while (skipped < amount) {
            currSkipped = super.skip(amount - skipped);
            if (currSkipped == 0) {
                zeroSkipCnt++;
                if (zeroSkipCnt == 2) {
                    // If the skip value exceeds streams size, this and the
                    // number is extremely large, this can lead to a very long
                    // running loop.
                    break;
                }
            }
            skipped += currSkipped;
        }
        return skipped;