am 7ec9db2c: Remove the code and comments about version 1 format.
* commit '7ec9db2c34ee6bec2cbff6cf05cee9bf3c2f7122': Remove the code and comments about version 1 format.main
commit
5d7b46343b
|
@ -235,7 +235,7 @@ final public class BinaryDictionaryGetter {
|
|||
new BinaryDictInputOutput.ByteBufferWrapper(inStream.getChannel().map(
|
||||
FileChannel.MapMode.READ_ONLY, 0, f.length()));
|
||||
final int magic = buffer.readInt();
|
||||
if (magic != FormatSpec.VERSION_2_MAGIC_NUMBER) {
|
||||
if (magic != FormatSpec.MAGIC_NUMBER) {
|
||||
return false;
|
||||
}
|
||||
final int formatVersion = buffer.readInt();
|
||||
|
|
|
@ -1210,27 +1210,19 @@ public final class BinaryDictInputOutput {
|
|||
ByteArrayOutputStream headerBuffer = new ByteArrayOutputStream(256);
|
||||
|
||||
// The magic number in big-endian order.
|
||||
if (version >= FormatSpec.FIRST_VERSION_WITH_HEADER_SIZE) {
|
||||
// Magic number for version 2+.
|
||||
headerBuffer.write((byte) (0xFF & (FormatSpec.VERSION_2_MAGIC_NUMBER >> 24)));
|
||||
headerBuffer.write((byte) (0xFF & (FormatSpec.VERSION_2_MAGIC_NUMBER >> 16)));
|
||||
headerBuffer.write((byte) (0xFF & (FormatSpec.VERSION_2_MAGIC_NUMBER >> 8)));
|
||||
headerBuffer.write((byte) (0xFF & FormatSpec.VERSION_2_MAGIC_NUMBER));
|
||||
// Magic number for all versions.
|
||||
headerBuffer.write((byte) (0xFF & (FormatSpec.MAGIC_NUMBER >> 24)));
|
||||
headerBuffer.write((byte) (0xFF & (FormatSpec.MAGIC_NUMBER >> 16)));
|
||||
headerBuffer.write((byte) (0xFF & (FormatSpec.MAGIC_NUMBER >> 8)));
|
||||
headerBuffer.write((byte) (0xFF & FormatSpec.MAGIC_NUMBER));
|
||||
// Dictionary version.
|
||||
headerBuffer.write((byte) (0xFF & (version >> 8)));
|
||||
headerBuffer.write((byte) (0xFF & version));
|
||||
} else {
|
||||
// Magic number for version 1.
|
||||
headerBuffer.write((byte) (0xFF & (FormatSpec.VERSION_1_MAGIC_NUMBER >> 8)));
|
||||
headerBuffer.write((byte) (0xFF & FormatSpec.VERSION_1_MAGIC_NUMBER));
|
||||
// Dictionary version.
|
||||
headerBuffer.write((byte) (0xFF & version));
|
||||
}
|
||||
|
||||
// Options flags
|
||||
final int options = makeOptionsValue(dict, formatOptions);
|
||||
headerBuffer.write((byte) (0xFF & (options >> 8)));
|
||||
headerBuffer.write((byte) (0xFF & options));
|
||||
if (version >= FormatSpec.FIRST_VERSION_WITH_HEADER_SIZE) {
|
||||
final int headerSizeOffset = headerBuffer.size();
|
||||
// Placeholder to be written later with header size.
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
|
@ -1250,9 +1242,6 @@ public final class BinaryDictInputOutput {
|
|||
bytes[headerSizeOffset + 2] = (byte) (0xFF & (size >> 8));
|
||||
bytes[headerSizeOffset + 3] = (byte) (0xFF & (size >> 0));
|
||||
destination.write(bytes);
|
||||
} else {
|
||||
headerBuffer.writeTo(destination);
|
||||
}
|
||||
|
||||
headerBuffer.close();
|
||||
|
||||
|
@ -1658,10 +1647,8 @@ public final class BinaryDictInputOutput {
|
|||
*/
|
||||
private static int getFormatVersion(final FusionDictionaryBufferInterface buffer)
|
||||
throws IOException {
|
||||
final int magic_v1 = buffer.readUnsignedShort();
|
||||
if (FormatSpec.VERSION_1_MAGIC_NUMBER == magic_v1) return buffer.readUnsignedByte();
|
||||
final int magic_v2 = (magic_v1 << 16) + buffer.readUnsignedShort();
|
||||
if (FormatSpec.VERSION_2_MAGIC_NUMBER == magic_v2) return buffer.readUnsignedShort();
|
||||
final int magic = buffer.readInt();
|
||||
if (FormatSpec.MAGIC_NUMBER == magic) return buffer.readUnsignedShort();
|
||||
return FormatSpec.NOT_A_VERSION_NUMBER;
|
||||
}
|
||||
|
||||
|
@ -1695,13 +1682,9 @@ public final class BinaryDictInputOutput {
|
|||
|
||||
final HashMap<String, String> attributes = new HashMap<String, String>();
|
||||
final int headerSize;
|
||||
if (version < FormatSpec.FIRST_VERSION_WITH_HEADER_SIZE) {
|
||||
headerSize = buffer.position();
|
||||
} else {
|
||||
headerSize = buffer.readInt();
|
||||
populateOptions(buffer, headerSize, attributes);
|
||||
buffer.position(headerSize);
|
||||
}
|
||||
|
||||
if (headerSize < 0) {
|
||||
throw new UnsupportedFormatException("header size can't be negative.");
|
||||
|
|
|
@ -25,6 +25,40 @@ import com.android.inputmethod.latin.makedict.FusionDictionary.DictionaryOptions
|
|||
*/
|
||||
public final class FormatSpec {
|
||||
|
||||
/*
|
||||
* File header layout is as follows:
|
||||
*
|
||||
* v |
|
||||
* e | MAGIC_NUMBER + version of the file format, 2 bytes.
|
||||
* r |
|
||||
* sion
|
||||
*
|
||||
* o |
|
||||
* p | not used 4 bits
|
||||
* t | has bigrams ? 1 bit, 1 = yes, 0 = no : CONTAINS_BIGRAMS_FLAG
|
||||
* i | FRENCH_LIGATURE_PROCESSING_FLAG
|
||||
* o | supports dynamic updates ? 1 bit, 1 = yes, 0 = no : SUPPORTS_DYNAMIC_UPDATE
|
||||
* n | GERMAN_UMLAUT_PROCESSING_FLAG
|
||||
* f |
|
||||
* lags
|
||||
*
|
||||
* h |
|
||||
* e | size of the file header, 4bytes
|
||||
* a | including the size of the magic number, the option flags and the header size
|
||||
* d |
|
||||
* ersize
|
||||
*
|
||||
* | attributes list
|
||||
*
|
||||
* attributes list is:
|
||||
* <key> = | string of characters at the char format described below, with the terminator used
|
||||
* | to signal the end of the string.
|
||||
* <value> = | string of characters at the char format described below, with the terminator used
|
||||
* | to signal the end of the string.
|
||||
* if the size of already read < headersize, goto key.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Array of Node(FusionDictionary.Node) layout is as follows:
|
||||
*
|
||||
|
@ -151,12 +185,10 @@ public final class FormatSpec {
|
|||
* if (FLAG_ATTRIBUTE_HAS_NEXT goto flags
|
||||
*/
|
||||
|
||||
static final int VERSION_1_MAGIC_NUMBER = 0x78B1;
|
||||
public static final int VERSION_2_MAGIC_NUMBER = 0x9BC13AFE;
|
||||
static final int MINIMUM_SUPPORTED_VERSION = 1;
|
||||
public static final int MAGIC_NUMBER = 0x9BC13AFE;
|
||||
static final int MINIMUM_SUPPORTED_VERSION = 2;
|
||||
static final int MAXIMUM_SUPPORTED_VERSION = 3;
|
||||
static final int NOT_A_VERSION_NUMBER = -1;
|
||||
static final int FIRST_VERSION_WITH_HEADER_SIZE = 2;
|
||||
static final int FIRST_VERSION_WITH_DYNAMIC_UPDATE = 3;
|
||||
|
||||
// These options need to be the same numeric values as the one in the native reading code.
|
||||
|
|
Loading…
Reference in New Issue