mirror of
https://gitlab.futo.org/keyboard/latinime.git
synced 2024-09-28 14:54:30 +01:00
Merge "Add FusionDictionaryBufferFromWritableByteBufferFactory."
This commit is contained in:
commit
f795f2b789
@ -24,6 +24,7 @@ import java.io.File;
|
|||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.RandomAccessFile;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.channels.FileChannel;
|
import java.nio.channels.FileChannel;
|
||||||
|
|
||||||
@ -82,6 +83,32 @@ public class BinaryDictReader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates FusionDictionaryBuffer from a RandomAccessFile.
|
||||||
|
*/
|
||||||
|
@UsedForTesting
|
||||||
|
public static final class FusionDictionaryBufferFromWritableByteBufferFactory
|
||||||
|
implements FusionDictionaryBufferFactory {
|
||||||
|
@Override
|
||||||
|
public FusionDictionaryBufferInterface getFusionDictionaryBuffer(final File file)
|
||||||
|
throws FileNotFoundException, IOException {
|
||||||
|
RandomAccessFile raFile = null;
|
||||||
|
ByteBuffer buffer = null;
|
||||||
|
try {
|
||||||
|
raFile = new RandomAccessFile(file, "rw");
|
||||||
|
buffer = raFile.getChannel().map(FileChannel.MapMode.READ_WRITE, 0, file.length());
|
||||||
|
} finally {
|
||||||
|
if (raFile != null) {
|
||||||
|
raFile.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (buffer != null) {
|
||||||
|
return new BinaryDictInputOutput.ByteBufferWrapper(buffer);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private final File mDictionaryBinaryFile;
|
private final File mDictionaryBinaryFile;
|
||||||
private FusionDictionaryBufferInterface mFusionDictionaryBuffer;
|
private FusionDictionaryBufferInterface mFusionDictionaryBuffer;
|
||||||
|
|
||||||
|
@ -18,8 +18,12 @@ package com.android.inputmethod.latin.makedict;
|
|||||||
|
|
||||||
import com.android.inputmethod.latin.makedict.BinaryDictInputOutput.FusionDictionaryBufferInterface;
|
import com.android.inputmethod.latin.makedict.BinaryDictInputOutput.FusionDictionaryBufferInterface;
|
||||||
import com.android.inputmethod.latin.makedict.BinaryDictReader.FusionDictionaryBufferFactory;
|
import com.android.inputmethod.latin.makedict.BinaryDictReader.FusionDictionaryBufferFactory;
|
||||||
import com.android.inputmethod.latin.makedict.BinaryDictReader.FusionDictionaryBufferFromByteArrayFactory;
|
import com.android.inputmethod.latin.makedict.BinaryDictReader.
|
||||||
import com.android.inputmethod.latin.makedict.BinaryDictReader.FusionDictionaryBufferFromByteBufferFactory;
|
FusionDictionaryBufferFromByteArrayFactory;
|
||||||
|
import com.android.inputmethod.latin.makedict.BinaryDictReader.
|
||||||
|
FusionDictionaryBufferFromByteBufferFactory;
|
||||||
|
import com.android.inputmethod.latin.makedict.BinaryDictReader.
|
||||||
|
FusionDictionaryBufferFromWritableByteBufferFactory;
|
||||||
|
|
||||||
import android.test.AndroidTestCase;
|
import android.test.AndroidTestCase;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
@ -94,6 +98,11 @@ public class BinaryDictReaderTests extends AndroidTestCase {
|
|||||||
new FusionDictionaryBufferFromByteArrayFactory());
|
new FusionDictionaryBufferFromByteArrayFactory());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testOpenBufferWithWritableByteBuffer() {
|
||||||
|
runTestOpenBuffer("testOpenBufferWithWritableByteBuffer",
|
||||||
|
new FusionDictionaryBufferFromWritableByteBufferFactory());
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("null")
|
@SuppressWarnings("null")
|
||||||
public void runTestGetBuffer(final String testName,
|
public void runTestGetBuffer(final String testName,
|
||||||
final FusionDictionaryBufferFactory factory) {
|
final FusionDictionaryBufferFactory factory) {
|
||||||
@ -135,4 +144,9 @@ public class BinaryDictReaderTests extends AndroidTestCase {
|
|||||||
runTestGetBuffer("testGetBufferWithByteArray",
|
runTestGetBuffer("testGetBufferWithByteArray",
|
||||||
new FusionDictionaryBufferFromByteArrayFactory());
|
new FusionDictionaryBufferFromByteArrayFactory());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testGetBufferWithWritableByteBuffer() {
|
||||||
|
runTestGetBuffer("testGetBufferWithWritableByteBuffer",
|
||||||
|
new FusionDictionaryBufferFromWritableByteBufferFactory());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user