diff options
Diffstat (limited to 'tools')
3 files changed, 22 insertions, 7 deletions
diff --git a/tools/dicttool/src/com/android/inputmethod/latin/dicttool/BinaryDictOffdeviceUtils.java b/tools/dicttool/src/com/android/inputmethod/latin/dicttool/BinaryDictOffdeviceUtils.java index 3ec28f313..84c3956f7 100644 --- a/tools/dicttool/src/com/android/inputmethod/latin/dicttool/BinaryDictOffdeviceUtils.java +++ b/tools/dicttool/src/com/android/inputmethod/latin/dicttool/BinaryDictOffdeviceUtils.java @@ -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)) { diff --git a/tools/dicttool/src/com/android/inputmethod/latin/dicttool/Header.java b/tools/dicttool/src/com/android/inputmethod/latin/dicttool/Header.java index 51efdec33..ba96c0aeb 100644 --- a/tools/dicttool/src/com/android/inputmethod/latin/dicttool/Header.java +++ b/tools/dicttool/src/com/android/inputmethod/latin/dicttool/Header.java @@ -62,6 +62,7 @@ public class Header extends Dicttool.Command { System.out.println("Dictionary : " + dictFile.getAbsolutePath()); System.out.println("Size : " + dictFile.length() + " bytes"); System.out.println("Format : Binary dictionary format"); + System.out.println("Format version : " + header.mFormatOptions.mVersion); System.out.println("Packaging : " + spec.describeChain()); System.out.println("Header attributes :"); System.out.print(header.mDictionaryOptions.toString(2 /* indentCount */, plumbing)); diff --git a/tools/dicttool/src/com/android/inputmethod/latin/dicttool/Package.java b/tools/dicttool/src/com/android/inputmethod/latin/dicttool/Package.java index 4e5c0742e..3efa10a80 100644 --- a/tools/dicttool/src/com/android/inputmethod/latin/dicttool/Package.java +++ b/tools/dicttool/src/com/android/inputmethod/latin/dicttool/Package.java @@ -16,6 +16,8 @@ package com.android.inputmethod.latin.dicttool; +import com.android.inputmethod.latin.makedict.DictionaryHeader; + import java.io.BufferedOutputStream; import java.io.File; import java.io.FileNotFoundException; @@ -77,16 +79,16 @@ public class Package { if (mArgs.length != 2) { throw new RuntimeException("Too many/too few arguments for command " + COMMAND); } - final BinaryDictOffdeviceUtils.DecoderChainSpec<File> decodedSpec = - BinaryDictOffdeviceUtils.getRawDictionaryOrNull(new File(mArgs[0])); + final BinaryDictOffdeviceUtils.DecoderChainSpec<DictionaryHeader> decodedSpec = + BinaryDictOffdeviceUtils.decodeDictionaryForProcess(new File(mArgs[0]), + new BinaryDictOffdeviceUtils.HeaderReaderProcessor()); if (null == decodedSpec) { System.out.println(mArgs[0] + " does not seem to be a dictionary"); return; } System.out.println("Packaging : " + decodedSpec.describeChain()); - System.out.println("Uncompressed size : " + decodedSpec.mResult.length()); try ( - final InputStream input = getFileInputStream(decodedSpec.mResult); + final InputStream input = decodedSpec.getStream(new File(mArgs[0])); final OutputStream output = new BufferedOutputStream( getFileOutputStreamOrStdOut(mArgs[1])) ) { |