Merge "Make a better choice for the temporary file"

main
Jean Chalard 2012-10-12 03:59:09 -07:00 committed by Android (Google) Code Review
commit b5f1916c74
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();
}
/**