| 1 | |
package org.jaudiotagger.audio.asf.io; |
| 2 | |
|
| 3 | |
import java.io.IOException; |
| 4 | |
import java.io.InputStream; |
| 5 | |
import java.io.RandomAccessFile; |
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
public final class RandomAccessFileInputstream extends InputStream { |
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
private final RandomAccessFile source; |
| 18 | |
|
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
|
| 23 | |
|
| 24 | |
|
| 25 | |
|
| 26 | |
public RandomAccessFileInputstream(final RandomAccessFile file) { |
| 27 | 278 | super(); |
| 28 | 278 | if (file == null) { |
| 29 | 0 | throw new IllegalArgumentException("null"); |
| 30 | |
} |
| 31 | 278 | this.source = file; |
| 32 | 278 | } |
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
@Override |
| 38 | |
public int read() throws IOException { |
| 39 | 39956 | return this.source.read(); |
| 40 | |
} |
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
@Override |
| 46 | |
public int read(final byte[] buffer, final int off, final int len) |
| 47 | |
throws IOException { |
| 48 | 16956 | return this.source.read(buffer, off, len); |
| 49 | |
} |
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 53 | |
|
| 54 | |
@Override |
| 55 | |
public long skip(final long amount) throws IOException { |
| 56 | 256 | if (amount < 0) { |
| 57 | 0 | throw new IllegalArgumentException("invalid negative value"); |
| 58 | |
} |
| 59 | 256 | long left = amount; |
| 60 | 256 | while (left > Integer.MAX_VALUE) { |
| 61 | 0 | this.source.skipBytes(Integer.MAX_VALUE); |
| 62 | 0 | left -= Integer.MAX_VALUE; |
| 63 | |
} |
| 64 | 256 | return this.source.skipBytes((int) left); |
| 65 | |
} |
| 66 | |
|
| 67 | |
} |