Skip to content
Snippets Groups Projects
Commit 66c90cd2 authored by Jean Chalard's avatar Jean Chalard
Browse files

Put temporary files under a separate directory.

Bug: 7328003
Change-Id: Ibe5278ea209d149f87fd08785c77b17e3859948e
parent 471252b9
No related branches found
No related tags found
No related merge requests found
......@@ -46,7 +46,7 @@ public final class BinaryDictionaryFileDumper {
/**
* The size of the temporary buffer to copy files.
*/
private static final int FILE_READ_BUFFER_SIZE = 1024;
private static final int FILE_READ_BUFFER_SIZE = 8192;
// TODO: make the following data common with the native code
private static final byte[] MAGIC_NUMBER_VERSION_1 =
new byte[] { (byte)0x78, (byte)0xB1, (byte)0x00, (byte)0x00 };
......@@ -149,7 +149,7 @@ public final class BinaryDictionaryFileDumper {
final Uri.Builder wordListUriBuilder = getProviderUriBuilder(id);
final String finalFileName = BinaryDictionaryGetter.getCacheFileName(id, locale, context);
final String tempFileName = finalFileName + ".tmp";
final String tempFileName = BinaryDictionaryGetter.getTempFileName(id, context);
for (int mode = MODE_MIN; mode <= MODE_MAX; ++mode) {
InputStream originalSourceStream = null;
......@@ -287,6 +287,7 @@ public final class BinaryDictionaryFileDumper {
* @param input the stream to be copied.
* @param output an output stream to copy the data to.
*/
// TODO: make output a BufferedOutputStream
private static void checkMagicAndCopyFileTo(final BufferedInputStream input,
final FileOutputStream output) throws FileNotFoundException, IOException {
// Check the magic number
......
......@@ -163,6 +163,18 @@ final class BinaryDictionaryGetter {
return getCacheDirectoryForLocale(locale, context) + File.separator + fileName;
}
/**
* Generates a unique temporary file name in the app cache directory.
*
* This is unique as long as it doesn't get called twice in the same millisecond by the same
* thread, which should be more than enough for our purposes.
*/
public static String getTempFileName(String id, Context context) {
final String fileName = replaceFileNameDangerousCharacters(id);
return context.getCacheDir() + File.separator + fileName + "."
+ Thread.currentThread().getId() + "." + System.currentTimeMillis();
}
/**
* Returns a file address from a resource, or null if it cannot be opened.
*/
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment