am 2220aeed: Merge "Put temporary files under a separate directory." into jb-mr1-dev
* commit '2220aeedfeeb796d627f2fd659c81256297f145e': Put temporary files under a separate directory.main
commit
c1a1937c0d
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue