| 1 | |
package org.jaudiotagger.audio.asf.io; |
| 2 | |
|
| 3 | |
import java.io.FilterInputStream; |
| 4 | |
import java.io.IOException; |
| 5 | |
import java.io.InputStream; |
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
public class FullRequestInputStream extends FilterInputStream { |
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
public FullRequestInputStream(InputStream source) { |
| 20 | 64 | super(source); |
| 21 | 64 | } |
| 22 | |
|
| 23 | |
|
| 24 | |
|
| 25 | |
|
| 26 | |
@Override |
| 27 | |
public int read(byte[] b) throws IOException { |
| 28 | 0 | return read(b, 0, b.length); |
| 29 | |
} |
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
@Override |
| 35 | |
public int read(byte[] b, int off, int len) throws IOException { |
| 36 | 3656 | int totalRead = 0; |
| 37 | 3656 | int read = -1; |
| 38 | 7322 | while (totalRead < len) { |
| 39 | 3666 | read = super.read(b, off + totalRead, len - totalRead); |
| 40 | 3666 | if (read >= 0) { |
| 41 | 3666 | totalRead += read; |
| 42 | |
} |
| 43 | 3666 | if (read == -1) |
| 44 | |
{ |
| 45 | 0 | throw new IOException((len - totalRead) + " more bytes expected."); |
| 46 | |
} |
| 47 | |
} |
| 48 | 3656 | return totalRead; |
| 49 | |
} |
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 53 | |
|
| 54 | |
@Override |
| 55 | |
public long skip(long n) throws IOException { |
| 56 | 648 | long skipped = 0; |
| 57 | 648 | int zeroSkipCnt = 0; |
| 58 | |
long currSkipped; |
| 59 | 1300 | while (skipped < n) { |
| 60 | 652 | currSkipped = super.skip(n - skipped); |
| 61 | 652 | if (currSkipped == 0) { |
| 62 | 0 | zeroSkipCnt++; |
| 63 | 0 | if (zeroSkipCnt == 2) { |
| 64 | |
|
| 65 | |
|
| 66 | |
|
| 67 | 0 | return skipped; |
| 68 | |
} |
| 69 | |
} |
| 70 | 652 | skipped += currSkipped; |
| 71 | |
} |
| 72 | 648 | return skipped; |
| 73 | |
} |
| 74 | |
|
| 75 | |
} |