am 726e98b7: am c1a1937c: am 2220aeed: Merge "Put temporary files under a separate directory." into jb-mr1-dev

* commit '726e98b7378987b2cfe46ea5395692640b108e83':
  Put temporary files under a separate directory.
main
Ken Wakasa 2012-10-11 08:41:42 -07:00 committed by Android Git Automerger
commit b0aa9606ae
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.
*/