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
9f468348
Commit
9f468348
authored
10 years ago
by
Adrian Velicu
Browse files
Options
Downloads
Patches
Plain Diff
dicttool header to read stream exhaustively
Change-Id: I50a286c115f5bd6e93763bd2f79031676d6fffd8
parent
1e72f9da
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
tools/dicttool/src/com/android/inputmethod/latin/dicttool/BinaryDictOffdeviceUtils.java
+15
-3
15 additions, 3 deletions
.../inputmethod/latin/dicttool/BinaryDictOffdeviceUtils.java
with
15 additions
and
3 deletions
tools/dicttool/src/com/android/inputmethod/latin/dicttool/BinaryDictOffdeviceUtils.java
+
15
−
3
View file @
9f468348
...
...
@@ -186,9 +186,7 @@ public final class BinaryDictOffdeviceUtils {
throw
new
UnsupportedFormatException
(
"Header too large"
);
}
final
byte
[]
headerBuffer
=
new
byte
[
totalHeaderSize
-
tmpBuffer
.
length
];
if
(
headerBuffer
.
length
!=
input
.
read
(
headerBuffer
))
{
throw
new
UnsupportedFormatException
(
"File shorter than specified in the header"
);
}
readStreamExhaustively
(
input
,
headerBuffer
);
final
HashMap
<
String
,
String
>
attributes
=
BinaryDictDecoderUtils
.
decodeHeaderAttributes
(
headerBuffer
);
return
new
DictionaryHeader
(
totalHeaderSize
,
new
DictionaryOptions
(
attributes
),
...
...
@@ -196,6 +194,20 @@ public final class BinaryDictOffdeviceUtils {
}
}
private
static
void
readStreamExhaustively
(
final
InputStream
inputStream
,
final
byte
[]
outBuffer
)
throws
IOException
,
UnsupportedFormatException
{
int
readBytes
=
0
;
int
readBytesLastCycle
=
-
1
;
while
(
readBytes
!=
outBuffer
.
length
)
{
readBytesLastCycle
=
inputStream
.
read
(
outBuffer
,
readBytes
,
outBuffer
.
length
-
readBytes
);
if
(
readBytesLastCycle
==
-
1
)
throw
new
UnsupportedFormatException
(
"File shorter than specified in the header"
+
" (expected "
+
outBuffer
.
length
+
", read "
+
readBytes
+
")"
);
readBytes
+=
readBytesLastCycle
;
}
}
public
static
void
copy
(
final
InputStream
input
,
final
OutputStream
output
)
throws
IOException
{
final
byte
[]
buffer
=
new
byte
[
COPY_BUFFER_SIZE
];
for
(
int
readBytes
=
input
.
read
(
buffer
);
readBytes
>=
0
;
readBytes
=
input
.
read
(
buffer
))
{
...
...
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