Skip to content

Commit

Permalink
Added MobiFileReader files.
Browse files Browse the repository at this point in the history
  • Loading branch information
andreban committed Oct 28, 2014
1 parent 721f990 commit 6c4e4d5
Show file tree
Hide file tree
Showing 11 changed files with 1,353 additions and 39 deletions.
21 changes: 4 additions & 17 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

239 changes: 218 additions & 21 deletions .idea/workspace.xml

Large diffs are not rendered by default.

114 changes: 114 additions & 0 deletions src/main/java/org/bandarra/mobireader/ExthHeader.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
package org.bandarra.mobireader;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

/**
*
* @author andreban
*/
public class ExthHeader {
public enum RecordType {
DRM_SERVER_ID(1, "drm_server_id"),
DRM_COMMERCE_ID(2, "drm_commerce_id"),
DRM_EBOOKBASE_BOOK_ID(3, "drm_ebookbase_book_id"),
AUTHOR(100, "Author"),
PUBLISHER(101, "Publisher"),
IMPRINT(102, "Imprint"),
DESCRIPTION(103, "Description"),
ISBN(104, "ISBN"),
SUBJECT(105, "Subject"),
PUBLISHING_DATE(106, "Publishing Date"),
REVIEW(107, "Review"),
CONTRIBUTOR(108, "Contributor"),
RIGHTS(109, "Rights"),
SUBJECT_CODE(110, "Subject Code"),
TYPE(111, "Type"),
SOURCE(112, "Source"),
ASIN(113, "asin"),
VERSION_NUMBER(114, "Version Number"),
SAMPLE(115, "0x0001 if the book content is only a sample of the full book"),
START_READING(116, "Position (4-byte offset) in file at which to open when first opened"),
ADULT(117, "Mobipocket Creator adds this if Adult only is checked on its GUI; contents: \"yes\""),
RETAIL_PRICE(118, "As text, e.g. \"4.99\""),
RETAIL_PRICE_CURRENCY(119, "As text, e.g. \"USD\""),
DICTIONARY_SHORT_NAME(200, "As text"),
COVER_OFFSET(201, "Add to first image field in Mobi Header to find PDB record containing the cover image"),
THUMB_OFFSET(202, "Add to first image field in Mobi Header to find PDB record containing the thumbnail cover image"),
HAS_FAKE_COVER(203, "hasfakecover"),
CREATOR_SOFTWARE(204, "Known Values: 1=mobigen, 2=Mobipocket Creator, 200=kindlegen (Windows), 201=kindlegen (Linux), 202=kindlegen (Mac).\n Warning: Calibre creates fake creator entries, pretending to be a Linux kindlegen 1.2 (201, 1, 2, 33307) for normal ebooks and a non-public Linux kindlegen 2.0 (201, 2, 0, 101) for periodicals."),
CREATOR_MAJOR_VERSION(205, "Creator Major Version"),
CREATOR_MINOR_VERSION(206, "Creator Minor Version"),
CREATOR_BUILD_NUMBER(207, "Creator Build Number"),
WATERMARK(208, "Watermark"),
TAMPER_PROOF_KEYS(209, "Used by the Kindle (and Android app) for generating book-specific PIDs."),
FONT_SIGNATURE(300, "font signature"),
CLIPPING_LIMIT(401, "Integer percentage of the text allowed to be clipped. Usually 10."),
PUBLISHER_LIMIT(402, "publisher limit"),
TTS_FLAG(404, "1 - Text to Speech disabled; 0 - Text to Speech enabled"),
CDE_TYPE(501, "PDOC - Personal Doc; EBOK - ebook; EBSP - ebook sample;"),
LAST_UPDATE_TIME(502, "last update time"),
UPDATED_TITLE(503, "updated title"),
ASIN_2(504, "a copy of ASIN in this record."),
LANGUAGE(524, "language");

private int id;
private String description;
private RecordType(int id, String description) {
this.id = id;
this.description = description;
}

public int getId() {
return id;
}

public String getDescription() {
return description;
}


}
private long headerLength;
private long recordCount;
private Map<Long, ExthHeaderRecord> records = new HashMap<>();

public long getHeaderLength() {
return headerLength;
}

public void setHeaderLength(long headerLength) {
this.headerLength = headerLength;
}

public long getRecordCount() {
return recordCount;
}

public void setRecordCount(long recordCount) {
this.recordCount = recordCount;
}

public void addRecord(ExthHeaderRecord record) {
records.put(record.getRecordType(), record);
}

public ExthHeaderRecord getRecord(RecordType type) {
return getRecord(type.getId());
}

public ExthHeaderRecord getRecord(long type) {
return records.get(type);
}

public Collection<ExthHeaderRecord> getRecords() {
return records.values();
}

@Override
public String toString() {
return "ExthHeader{" + "headerLength=" + headerLength + ", recordCount=" + recordCount + ", records=" + records + '}';
}

}
67 changes: 67 additions & 0 deletions src/main/java/org/bandarra/mobireader/ExthHeaderRecord.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package org.bandarra.mobireader;

import java.nio.ByteBuffer;

/**
*
* @author andreban
*/
public class ExthHeaderRecord {
private long recordType;
private long recordLength;
private byte[] rawRecordData;

public String getString() {
return new String(rawRecordData);
}

public int getInt() {
ByteBuffer buff = ByteBuffer.wrap(rawRecordData);
return buff.getInt();
}

public long getUnsignedInt() {
return getInt() & 0xFFFFFFFFL;
}

public int getUnsignedShort() {
return getShort() & 0xffff;
}

public short getShort() {
if (rawRecordData.length != 4) {
throw new IllegalArgumentException("Cannot convert to unsigned short. rawRecordData length != 2" );
}
ByteBuffer buff = ByteBuffer.wrap(rawRecordData);
return buff.getShort();
}

public long getRecordType() {
return recordType;
}

public void setRecordType(long recordType) {
this.recordType = recordType;
}

public long getRecordLength() {
return recordLength;
}

public void setRecordLength(long recordLength) {
this.recordLength = recordLength;
}

public byte[] getRawRecordData() {
return rawRecordData;
}

public void setRawRecordData(byte[] rawRecordData) {
this.rawRecordData = rawRecordData;
}

@Override
public String toString() {
return "ExthHeaderRecord{" + "recordType=" + recordType + ", recordLength=" + recordLength + ", rawRecordData=" + rawRecordData + '}';
}
}
59 changes: 59 additions & 0 deletions src/main/java/org/bandarra/mobireader/MobiBook.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package org.bandarra.mobireader;

/**
*
* @author andreban
*/
public class MobiBook {
private String title;
private PDBHeader pdbHeader;
private MobiHeader mobiHeader;
private ExthHeader exthHeader;
private PalmDocHeader palmDocHeader;

public PDBHeader getPdbHeader() {
return pdbHeader;
}

public void setPdbHeader(PDBHeader pdbHeader) {
this.pdbHeader = pdbHeader;
}

public MobiHeader getMobiHeader() {
return mobiHeader;
}

public void setMobiHeader(MobiHeader mobiHeader) {
this.mobiHeader = mobiHeader;
}

public ExthHeader getExthHeader() {
return exthHeader;
}

public void setExthHeader(ExthHeader exthHeader) {
this.exthHeader = exthHeader;
}

public PalmDocHeader getPalmDocHeader() {
return palmDocHeader;
}

public void setPalmDocHeader(PalmDocHeader palmDocHeader) {
this.palmDocHeader = palmDocHeader;
}

public String getTitle() {
return title;
}

public void setTitle(String title) {
this.title = title;
}

@Override
public String toString() {
return "MobiBook{" + "title=" + title + ", pdbHeader=" + pdbHeader + ", mobiHeader=" + mobiHeader + ", exthHeader=" + exthHeader + ", palmDocHeader=" + palmDocHeader + '}';
}

}
Loading

0 comments on commit 6c4e4d5

Please sign in to comment.