Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2220aeed authored by Ken Wakasa's avatar Ken Wakasa Committed by Android (Google) Code Review
Browse files

Merge "Put temporary files under a separate directory." into jb-mr1-dev

parents 9d423536 66c90cd2
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -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
+12 −0
Original line number Diff line number Diff line
@@ -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.
     */