| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
package org.tukaani.xz; |
| 6 |
|
| 7 |
import java.io.File; |
| 8 |
import java.io.RandomAccessFile; |
| 9 |
import java.io.IOException; |
| 10 |
import java.io.FileNotFoundException; |
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
public class SeekableFileInputStream extends SeekableInputStream { |
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
protected RandomAccessFile randomAccessFile; |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
public SeekableFileInputStream(File file) throws FileNotFoundException { |
| 27 |
randomAccessFile = new RandomAccessFile(file, "r"); |
| 28 |
} |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
public SeekableFileInputStream(String name) throws FileNotFoundException { |
| 35 |
randomAccessFile = new RandomAccessFile(name, "r"); |
| 36 |
} |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
public SeekableFileInputStream(RandomAccessFile randomAccessFile) { |
| 43 |
this.randomAccessFile = randomAccessFile; |
| 44 |
} |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
@Override |
| 50 |
public int read() throws IOException { |
| 51 |
return randomAccessFile.read(); |
| 52 |
} |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
@Override |
| 58 |
public int read(byte[] buf) throws IOException { |
| 59 |
return randomAccessFile.read(buf); |
| 60 |
} |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
@Override |
| 68 |
public int read(byte[] buf, int off, int len) throws IOException { |
| 69 |
return randomAccessFile.read(buf, off, len); |
| 70 |
} |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
@Override |
| 76 |
public void close() throws IOException { |
| 77 |
randomAccessFile.close(); |
| 78 |
} |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
@Override |
| 84 |
public long length() throws IOException { |
| 85 |
return randomAccessFile.length(); |
| 86 |
} |
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
@Override |
| 93 |
public long position() throws IOException { |
| 94 |
return randomAccessFile.getFilePointer(); |
| 95 |
} |
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
@Override |
| 101 |
public void seek(long pos) throws IOException { |
| 102 |
randomAccessFile.seek(pos); |
| 103 |
} |
| 104 |
} |