Put temporary files under a separate directory.

Bug: 7328003
Change-Id: Ibe5278ea209d149f87fd08785c77b17e3859948e
main
Jean Chalard 2012-10-11 16:08:25 +09:00
parent 471252b9da
commit 66c90cd2ae
2 changed files with 15 additions and 2 deletions

View File

@ -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

View File

@ -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.
*/