|
|
|
@ -33,8 +33,9 @@ import java.util.List;
|
|
|
|
|
* Proof-Reading, unclustering, refactoring,
|
|
|
|
|
* naming adoption to https://wiki.openzim.org/wiki/ZIM_file_format,
|
|
|
|
|
* change of Exception handling,
|
|
|
|
|
* extension to more attributes as defined in spec (bugfix for mime type loading)
|
|
|
|
|
* int/long bugfix (did reading of long values with int variables, causing negative offsets)
|
|
|
|
|
* extension to more attributes as defined in spec (bugfix for mime type loading),
|
|
|
|
|
* int/long bugfix (did reading of long values with int variables, causing negative offsets),
|
|
|
|
|
* added url pointer, title pointer and cluster pointer caches
|
|
|
|
|
*/
|
|
|
|
|
public class ZIMFile extends File {
|
|
|
|
|
|
|
|
|
@ -45,10 +46,10 @@ public class ZIMFile extends File {
|
|
|
|
|
public final int header_majorVersion;
|
|
|
|
|
public final int header_minorVersion;
|
|
|
|
|
public final int header_entryCount;
|
|
|
|
|
public final int header_clusterCount;
|
|
|
|
|
private final int header_clusterCount;
|
|
|
|
|
public final long header_urlPtrPos;
|
|
|
|
|
public final long header_titlePtrPos;
|
|
|
|
|
public final long header_clusterPtrPos;
|
|
|
|
|
private final long header_clusterPtrPos;
|
|
|
|
|
public final long header_mimeListPos;
|
|
|
|
|
public final int header_mainPage;
|
|
|
|
|
public final int header_layoutPage;
|
|
|
|
@ -61,6 +62,7 @@ public class ZIMFile extends File {
|
|
|
|
|
private final String[] mimeTypeList;
|
|
|
|
|
private final byte[] urlPtrListBlob;
|
|
|
|
|
private final byte[] titlePtrListBlob;
|
|
|
|
|
private final byte[] clusterPtrListBlob;
|
|
|
|
|
|
|
|
|
|
public ZIMFile(final String path) throws IOException {
|
|
|
|
|
super(path);
|
|
|
|
@ -120,6 +122,11 @@ public class ZIMFile extends File {
|
|
|
|
|
this.titlePtrListBlob = new byte[this.header_entryCount * 4];
|
|
|
|
|
mReader.seek(this.header_titlePtrPos);
|
|
|
|
|
RandomAccessFileZIMInputStream.readFully(mReader, this.titlePtrListBlob);
|
|
|
|
|
|
|
|
|
|
// Initialize the Cluster Pointer List
|
|
|
|
|
this.clusterPtrListBlob = new byte[this.header_clusterCount * 8];
|
|
|
|
|
mReader.seek(this.header_clusterPtrPos);
|
|
|
|
|
RandomAccessFileZIMInputStream.readFully(mReader, this.clusterPtrListBlob);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public final String getMimeType(int idx) {
|
|
|
|
@ -133,4 +140,8 @@ public class ZIMFile extends File {
|
|
|
|
|
public final int getTitlePtr(final int idx) {
|
|
|
|
|
return RandomAccessFileZIMInputStream.toFourLittleEndianInteger(this.titlePtrListBlob, idx * 4);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public final long geClusterPtr(final int idx) {
|
|
|
|
|
return RandomAccessFileZIMInputStream.toEightLittleEndianLong(this.clusterPtrListBlob, idx * 8);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|