Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
LatinIME
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
keyboard
LatinIME
Commits
49aa5856
Commit
49aa5856
authored
13 years ago
by
Jean Chalard
Committed by
Android (Google) Code Review
13 years ago
Browse files
Options
Downloads
Plain Diff
Merge "Touch up the header format"
parents
46a1eec4
a9a5dd07
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tools/makedict/src/com/android/inputmethod/latin/BinaryDictInputOutput.java
+22
-22
22 additions, 22 deletions
.../com/android/inputmethod/latin/BinaryDictInputOutput.java
with
22 additions
and
22 deletions
tools/makedict/src/com/android/inputmethod/latin/BinaryDictInputOutput.java
+
22
−
22
View file @
49aa5856
...
...
@@ -115,6 +115,7 @@ public class BinaryDictInputOutput {
private
static
final
int
VERSION_2_MAGIC_NUMBER
=
0x9BC13AFE
;
private
static
final
int
MINIMUM_SUPPORTED_VERSION
=
1
;
private
static
final
int
MAXIMUM_SUPPORTED_VERSION
=
2
;
private
static
final
int
NOT_A_VERSION_NUMBER
=
-
1
;
private
static
final
int
FIRST_VERSION_WITH_HEADER_SIZE
=
2
;
// No options yet, reserved for future use.
...
...
@@ -829,24 +830,28 @@ public class BinaryDictInputOutput {
buffer
[
index
++]
=
(
byte
)
(
0xFF
&
(
VERSION_2_MAGIC_NUMBER
>>
16
));
buffer
[
index
++]
=
(
byte
)
(
0xFF
&
(
VERSION_2_MAGIC_NUMBER
>>
8
));
buffer
[
index
++]
=
(
byte
)
(
0xFF
&
VERSION_2_MAGIC_NUMBER
);
// Dictionary version.
buffer
[
index
++]
=
(
byte
)
(
0xFF
&
(
version
>>
8
));
buffer
[
index
++]
=
(
byte
)
(
0xFF
&
version
);
}
else
{
// Magic number for version 1.
buffer
[
index
++]
=
(
byte
)
(
0xFF
&
(
VERSION_1_MAGIC_NUMBER
>>
8
));
buffer
[
index
++]
=
(
byte
)
(
0xFF
&
VERSION_1_MAGIC_NUMBER
);
// Dictionary version.
buffer
[
index
++]
=
(
byte
)
(
0xFF
&
version
);
}
// Dictionary version.
buffer
[
index
++]
=
(
byte
)
(
0xFF
&
version
);
// Options flags
buffer
[
index
++]
=
(
byte
)
(
0xFF
&
(
OPTIONS
>>
8
));
buffer
[
index
++]
=
(
byte
)
(
0xFF
&
OPTIONS
);
if
(
version
>=
FIRST_VERSION_WITH_HEADER_SIZE
)
{
final
int
headerSizeOffset
=
index
;
index
+=
3
;
// Size of the header size
index
+=
4
;
// Size of the header size
// TODO: Write out the header contents here.
// Write out the header size.
buffer
[
headerSizeOffset
]
=
(
byte
)
(
0xFF
&
(
index
>>
16
));
buffer
[
headerSizeOffset
+
1
]
=
(
byte
)
(
0xFF
&
(
index
>>
8
));
buffer
[
headerSizeOffset
+
2
]
=
(
byte
)
(
0xFF
&
(
index
>>
0
));
buffer
[
headerSizeOffset
]
=
(
byte
)
(
0xFF
&
(
index
>>
24
));
buffer
[
headerSizeOffset
+
1
]
=
(
byte
)
(
0xFF
&
(
index
>>
16
));
buffer
[
headerSizeOffset
+
2
]
=
(
byte
)
(
0xFF
&
(
index
>>
8
));
buffer
[
headerSizeOffset
+
3
]
=
(
byte
)
(
0xFF
&
(
index
>>
0
));
}
destination
.
write
(
buffer
,
0
,
index
);
...
...
@@ -1122,14 +1127,14 @@ public class BinaryDictInputOutput {
}
/**
* Helper function to
tes
t the
magic number of the file
.
* Helper function to
ge
t the
binary format version from the header
.
*/
private
static
boolean
isExpectedMagicNumber
(
final
RandomAccessFile
source
)
throws
IOException
{
private
static
int
getFormatVersion
(
final
RandomAccessFile
source
)
throws
IOException
{
final
int
magic_v1
=
source
.
readUnsignedShort
();
if
(
VERSION_1_MAGIC_NUMBER
==
magic_v1
)
return
true
;
if
(
VERSION_1_MAGIC_NUMBER
==
magic_v1
)
return
source
.
readUnsignedByte
()
;
final
int
magic_v2
=
(
magic_v1
<<
16
)
+
source
.
readUnsignedShort
();
if
(
VERSION_2_MAGIC_NUMBER
==
magic_v2
)
return
true
;
return
false
;
if
(
VERSION_2_MAGIC_NUMBER
==
magic_v2
)
return
source
.
readUnsignedShort
()
;
return
NOT_A_VERSION_NUMBER
;
}
/**
...
...
@@ -1145,15 +1150,9 @@ public class BinaryDictInputOutput {
*/
public
static
FusionDictionary
readDictionaryBinary
(
final
RandomAccessFile
source
,
final
FusionDictionary
dict
)
throws
IOException
,
UnsupportedFormatException
{
// Check magic number
if
(!
isExpectedMagicNumber
(
source
))
{
throw
new
UnsupportedFormatException
(
"The magic number in this file does not match "
+
"the expected value"
);
}
// Check file version
final
int
version
=
source
.
readUnsignedByte
(
);
if
(
version
>
MAXIMUM_SUPPORTED_VERSION
)
{
final
int
version
=
getFormatVersion
(
source
);
if
(
version
<
MINIMUM_SUPPORTED_VERSION
||
version
>
MAXIMUM_SUPPORTED_VERSION
)
{
throw
new
UnsupportedFormatException
(
"This file has version "
+
version
+
", but this implementation does not support versions above "
+
MAXIMUM_SUPPORTED_VERSION
);
...
...
@@ -1166,8 +1165,8 @@ public class BinaryDictInputOutput {
if
(
version
<
FIRST_VERSION_WITH_HEADER_SIZE
)
{
headerSize
=
source
.
getFilePointer
();
}
else
{
headerSize
=
(
source
.
readUnsignedByte
()
<<
16
)
+
(
source
.
readUnsignedByte
()
<<
8
)
+
source
.
readUnsignedByte
();
headerSize
=
(
source
.
readUnsignedByte
()
<<
24
)
+
(
source
.
readUnsignedByte
()
<<
16
)
+
(
source
.
readUnsignedByte
()
<<
8
)
+
source
.
readUnsignedByte
();
// read the header body
source
.
seek
(
headerSize
);
}
...
...
@@ -1198,7 +1197,8 @@ public class BinaryDictInputOutput {
public
static
boolean
isBinaryDictionary
(
final
String
filename
)
{
try
{
RandomAccessFile
f
=
new
RandomAccessFile
(
filename
,
"r"
);
return
isExpectedMagicNumber
(
f
);
final
int
version
=
getFormatVersion
(
f
);
return
(
version
>=
MINIMUM_SUPPORTED_VERSION
&&
version
<=
MAXIMUM_SUPPORTED_VERSION
);
}
catch
(
FileNotFoundException
e
)
{
return
false
;
}
catch
(
IOException
e
)
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment