FullRequestInputStreampublic class FullRequestInputStream extends FilterInputStream This implementation repeatedly reads from the wrapped input stream until the
requested amount of bytes are read.
|
Constructors Summary |
---|
public FullRequestInputStream(InputStream source)Creates an instance.
super(source);
|
Methods Summary |
---|
public int | read(byte[] buffer){@inheritDoc}
return read(buffer, 0, buffer.length);
| public int | read(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 long | skip(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;
|
|