mirror of
https://gitlab.futo.org/keyboard/latinime.git
synced 2024-09-28 14:54:30 +01:00
[AD2] Add a helper method to read an arbitrary dict header
Bug: 7702011 Change-Id: Ib88f6dc222892831ae6932635b65fd2595b16b43
This commit is contained in:
parent
babc71ee30
commit
1d15fe7e51
@ -25,8 +25,12 @@ import com.android.inputmethod.latin.makedict.FormatSpec.FormatOptions;
|
||||
import com.android.inputmethod.latin.makedict.FusionDictionary.CharGroup;
|
||||
import com.android.inputmethod.latin.makedict.FusionDictionary.WeightedString;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
@ -977,4 +981,27 @@ public final class BinaryDictIOUtils {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method to read the header of a binary file.
|
||||
*
|
||||
* This is quite resource intensive - don't call when performance is critical.
|
||||
*
|
||||
* @param file The file to read.
|
||||
*/
|
||||
private static final int HEADER_READING_BUFFER_SIZE = 16384;
|
||||
public static FileHeader getDictionaryFileHeader(final File file)
|
||||
throws FileNotFoundException, IOException, UnsupportedFormatException {
|
||||
final byte[] buffer = new byte[HEADER_READING_BUFFER_SIZE];
|
||||
final FileInputStream inStream = new FileInputStream(file);
|
||||
try {
|
||||
inStream.read(buffer);
|
||||
final BinaryDictInputOutput.ByteBufferWrapper wrapper =
|
||||
new BinaryDictInputOutput.ByteBufferWrapper(inStream.getChannel().map(
|
||||
FileChannel.MapMode.READ_ONLY, 0, file.length()));
|
||||
return BinaryDictInputOutput.readHeader(wrapper);
|
||||
} finally {
|
||||
inStream.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user