Make a better choice for the temporary file
Change-Id: I745bb285b6b52875c8d2b3a94deb962352f9754emain
parent
1e06a4d8e9
commit
01e0913ad2
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue