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
62ed9011
Commit
62ed9011
authored
12 years ago
by
Yuichiro Hanada
Browse files
Options
Downloads
Patches
Plain Diff
add readHeader.
Change-Id: I5be5d62a63ca897e36fe93200ffdca6befb363aa
parent
d2a81ab9
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java
+45
-20
45 additions, 20 deletions
...oid/inputmethod/latin/makedict/BinaryDictInputOutput.java
with
45 additions
and
20 deletions
java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java
+
45
−
20
View file @
62ed9011
...
...
@@ -1380,6 +1380,48 @@ public class BinaryDictInputOutput {
return
NOT_A_VERSION_NUMBER
;
}
/**
* Helper function to get and validate the binary format version.
* @throws UnsupportedFormatException
* @throws IOException
*/
private
static
int
checkFormatVersion
(
final
FusionDictionaryBufferInterface
buffer
)
throws
IOException
,
UnsupportedFormatException
{
final
int
version
=
getFormatVersion
(
buffer
);
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
);
}
return
version
;
}
/**
* Reads a header from a buffer.
* @throws IOException
* @throws UnsupportedFormatException
*/
private
static
int
readHeader
(
final
FusionDictionaryBufferInterface
buffer
,
final
HashMap
<
String
,
String
>
options
,
final
int
version
)
throws
IOException
,
UnsupportedFormatException
{
final
int
headerSize
;
if
(
version
<
FIRST_VERSION_WITH_HEADER_SIZE
)
{
headerSize
=
buffer
.
position
();
}
else
{
headerSize
=
buffer
.
readInt
();
populateOptions
(
buffer
,
headerSize
,
options
);
buffer
.
position
(
headerSize
);
}
if
(
headerSize
<
0
)
{
throw
new
UnsupportedFormatException
(
"header size can't be negative."
);
}
return
headerSize
;
}
/**
* Reads options from a buffer and populate a map with their contents.
*
...
...
@@ -1414,33 +1456,16 @@ public class BinaryDictInputOutput {
public
static
FusionDictionary
readDictionaryBinary
(
final
FusionDictionaryBufferInterface
buffer
,
final
FusionDictionary
dict
)
throws
IOException
,
UnsupportedFormatException
{
// Check file version
final
int
version
=
getFormatVersion
(
buffer
);
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
);
}
// clear cache
wordCache
.
clear
();
// Read options
// Read header
final
int
version
=
checkFormatVersion
(
buffer
);
final
int
optionsFlags
=
buffer
.
readUnsignedShort
();
final
int
headerSize
;
final
HashMap
<
String
,
String
>
options
=
new
HashMap
<
String
,
String
>();
if
(
version
<
FIRST_VERSION_WITH_HEADER_SIZE
)
{
headerSize
=
buffer
.
position
();
}
else
{
headerSize
=
buffer
.
readInt
();
populateOptions
(
buffer
,
headerSize
,
options
);
buffer
.
position
(
headerSize
);
}
if
(
headerSize
<
0
)
{
throw
new
UnsupportedFormatException
(
"header size can't be negative."
);
}
final
int
headerSize
=
readHeader
(
buffer
,
options
,
version
);
Map
<
Integer
,
Node
>
reverseNodeMapping
=
new
TreeMap
<
Integer
,
Node
>();
Map
<
Integer
,
CharGroup
>
reverseGroupMapping
=
new
TreeMap
<
Integer
,
CharGroup
>();
...
...
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