Make a better choice for the temporary file

Change-Id: I745bb285b6b52875c8d2b3a94deb962352f9754e
This commit is contained in:
Jean Chalard 2012-10-12 18:07:30 +09:00
parent 1e06a4d8e9
commit 01e0913ad2
2 changed files with 9 additions and 8 deletions

View file

@ -149,7 +149,13 @@ public final class BinaryDictionaryFileDumper {
final Uri.Builder wordListUriBuilder = getProviderUriBuilder(id);
final String finalFileName = BinaryDictionaryGetter.getCacheFileName(id, locale, context);
final String tempFileName = BinaryDictionaryGetter.getTempFileName(id, context);
String tempFileName;
try {
tempFileName = BinaryDictionaryGetter.getTempFileName(id, context);
} catch (IOException e) {
Log.e(TAG, "Can't open the temporary file", e);
return null;
}
for (int mode = MODE_MIN; mode <= MODE_MAX; ++mode) {
InputStream originalSourceStream = null;

View file

@ -165,14 +165,9 @@ final class BinaryDictionaryGetter {
/**
* 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();
public static String getTempFileName(String id, Context context) throws IOException {
return File.createTempFile(replaceFileNameDangerousCharacters(id), null).getAbsolutePath();
}
/**