Loading tools/dicttool/src/com/android/inputmethod/latin/dicttool/BinaryDictOffdeviceUtils.java +15 −3 Original line number Diff line number Diff line Loading @@ -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), Loading @@ -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)) { Loading Loading
tools/dicttool/src/com/android/inputmethod/latin/dicttool/BinaryDictOffdeviceUtils.java +15 −3 Original line number Diff line number Diff line Loading @@ -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), Loading @@ -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)) { Loading