Java Code Examples for android.os.FileUtils#copyPermissions()

The following examples show how to use android.os.FileUtils#copyPermissions() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
/**
 * Try our best to migrate all files from source to target that match
 * requested prefix.
 *
 * @return the number of files moved, or -1 if there was trouble.
 */
private static int moveFiles(File sourceDir, File targetDir, final String prefix) {
    final File[] sourceFiles = FileUtils.listFilesOrEmpty(sourceDir, new FilenameFilter() {
        @Override
        public boolean accept(File dir, String name) {
            return name.startsWith(prefix);
        }
    });

    int res = 0;
    for (File sourceFile : sourceFiles) {
        final File targetFile = new File(targetDir, sourceFile.getName());
        Log.d(TAG, "Migrating " + sourceFile + " to " + targetFile);
        try {
            FileUtils.copyFileOrThrow(sourceFile, targetFile);
            FileUtils.copyPermissions(sourceFile, targetFile);
            if (!sourceFile.delete()) {
                throw new IOException("Failed to clean up " + sourceFile);
            }
            if (res != -1) {
                res++;
            }
        } catch (IOException e) {
            Log.w(TAG, "Failed to migrate " + sourceFile + ": " + e);
            res = -1;
        }
    }
    return res;
}
 
Example 2
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
/**
 * Try our best to migrate all files from source to target that match
 * requested prefix.
 *
 * @return the number of files moved, or -1 if there was trouble.
 */
private static int moveFiles(File sourceDir, File targetDir, final String prefix) {
    final File[] sourceFiles = FileUtils.listFilesOrEmpty(sourceDir, new FilenameFilter() {
        @Override
        public boolean accept(File dir, String name) {
            return name.startsWith(prefix);
        }
    });

    int res = 0;
    for (File sourceFile : sourceFiles) {
        final File targetFile = new File(targetDir, sourceFile.getName());
        Log.d(TAG, "Migrating " + sourceFile + " to " + targetFile);
        try {
            FileUtils.copyFileOrThrow(sourceFile, targetFile);
            FileUtils.copyPermissions(sourceFile, targetFile);
            if (!sourceFile.delete()) {
                throw new IOException("Failed to clean up " + sourceFile);
            }
            if (res != -1) {
                res++;
            }
        } catch (IOException e) {
            Log.w(TAG, "Failed to migrate " + sourceFile + ": " + e);
            res = -1;
        }
    }
    return res;
}
 
Example 3
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
/**
 * Try our best to migrate all files from source to target that match
 * requested prefix.
 *
 * @return the number of files moved, or -1 if there was trouble.
 */
private static int moveFiles(File sourceDir, File targetDir, final String prefix) {
    final File[] sourceFiles = FileUtils.listFilesOrEmpty(sourceDir, new FilenameFilter() {
        @Override
        public boolean accept(File dir, String name) {
            return name.startsWith(prefix);
        }
    });

    int res = 0;
    for (File sourceFile : sourceFiles) {
        final File targetFile = new File(targetDir, sourceFile.getName());
        Log.d(TAG, "Migrating " + sourceFile + " to " + targetFile);
        try {
            FileUtils.copyFileOrThrow(sourceFile, targetFile);
            FileUtils.copyPermissions(sourceFile, targetFile);
            if (!sourceFile.delete()) {
                throw new IOException("Failed to clean up " + sourceFile);
            }
            if (res != -1) {
                res++;
            }
        } catch (IOException e) {
            Log.w(TAG, "Failed to migrate " + sourceFile + ": " + e);
            res = -1;
        }
    }
    return res;
}
 
Example 4
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
/**
 * Try our best to migrate all files from source to target that match
 * requested prefix.
 *
 * @return the number of files moved, or -1 if there was trouble.
 */
private static int moveFiles(File sourceDir, File targetDir, final String prefix) {
    final File[] sourceFiles = FileUtils.listFilesOrEmpty(sourceDir, new FilenameFilter() {
        @Override
        public boolean accept(File dir, String name) {
            return name.startsWith(prefix);
        }
    });

    int res = 0;
    for (File sourceFile : sourceFiles) {
        final File targetFile = new File(targetDir, sourceFile.getName());
        Log.d(TAG, "Migrating " + sourceFile + " to " + targetFile);
        try {
            FileUtils.copyFileOrThrow(sourceFile, targetFile);
            FileUtils.copyPermissions(sourceFile, targetFile);
            if (!sourceFile.delete()) {
                throw new IOException("Failed to clean up " + sourceFile);
            }
            if (res != -1) {
                res++;
            }
        } catch (IOException e) {
            Log.w(TAG, "Failed to migrate " + sourceFile + ": " + e);
            res = -1;
        }
    }
    return res;
}
 
Example 5
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
/**
 * Try our best to migrate all files from source to target that match
 * requested prefix.
 *
 * @return the number of files moved, or -1 if there was trouble.
 */
private static int moveFiles(File sourceDir, File targetDir, final String prefix) {
    final File[] sourceFiles = FileUtils.listFilesOrEmpty(sourceDir, new FilenameFilter() {
        @Override
        public boolean accept(File dir, String name) {
            return name.startsWith(prefix);
        }
    });

    int res = 0;
    for (File sourceFile : sourceFiles) {
        final File targetFile = new File(targetDir, sourceFile.getName());
        Log.d(TAG, "Migrating " + sourceFile + " to " + targetFile);
        try {
            FileUtils.copyFileOrThrow(sourceFile, targetFile);
            FileUtils.copyPermissions(sourceFile, targetFile);
            if (!sourceFile.delete()) {
                throw new IOException("Failed to clean up " + sourceFile);
            }
            if (res != -1) {
                res++;
            }
        } catch (IOException e) {
            Log.w(TAG, "Failed to migrate " + sourceFile + ": " + e);
            res = -1;
        }
    }
    return res;
}
 
Example 6
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
/**
 * Try our best to migrate all files from source to target that match
 * requested prefix.
 *
 * @return the number of files moved, or -1 if there was trouble.
 */
private static int moveFiles(File sourceDir, File targetDir, final String prefix) {
    final File[] sourceFiles = FileUtils.listFilesOrEmpty(sourceDir, new FilenameFilter() {
        @Override
        public boolean accept(File dir, String name) {
            return name.startsWith(prefix);
        }
    });

    int res = 0;
    for (File sourceFile : sourceFiles) {
        final File targetFile = new File(targetDir, sourceFile.getName());
        Log.d(TAG, "Migrating " + sourceFile + " to " + targetFile);
        try {
            FileUtils.copyFileOrThrow(sourceFile, targetFile);
            FileUtils.copyPermissions(sourceFile, targetFile);
            if (!sourceFile.delete()) {
                throw new IOException("Failed to clean up " + sourceFile);
            }
            if (res != -1) {
                res++;
            }
        } catch (IOException e) {
            Log.w(TAG, "Failed to migrate " + sourceFile + ": " + e);
            res = -1;
        }
    }
    return res;
}
 
Example 7
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
/**
 * Try our best to migrate all files from source to target that match
 * requested prefix.
 *
 * @return the number of files moved, or -1 if there was trouble.
 */
private static int moveFiles(File sourceDir, File targetDir, final String prefix) {
    final File[] sourceFiles = FileUtils.listFilesOrEmpty(sourceDir, new FilenameFilter() {
        @Override
        public boolean accept(File dir, String name) {
            return name.startsWith(prefix);
        }
    });

    int res = 0;
    for (File sourceFile : sourceFiles) {
        final File targetFile = new File(targetDir, sourceFile.getName());
        Log.d(TAG, "Migrating " + sourceFile + " to " + targetFile);
        try {
            FileUtils.copyFileOrThrow(sourceFile, targetFile);
            FileUtils.copyPermissions(sourceFile, targetFile);
            if (!sourceFile.delete()) {
                throw new IOException("Failed to clean up " + sourceFile);
            }
            if (res != -1) {
                res++;
            }
        } catch (IOException e) {
            Log.w(TAG, "Failed to migrate " + sourceFile + ": " + e);
            res = -1;
        }
    }
    return res;
}
 
Example 8
Source File: ContextImpl.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Try our best to migrate all files from source to target that match
 * requested prefix.
 *
 * @return the number of files moved, or -1 if there was trouble.
 */
private static int moveFiles(File sourceDir, File targetDir, final String prefix) {
    final File[] sourceFiles = FileUtils.listFilesOrEmpty(sourceDir, new FilenameFilter() {
        @Override
        public boolean accept(File dir, String name) {
            return name.startsWith(prefix);
        }
    });

    int res = 0;
    for (File sourceFile : sourceFiles) {
        final File targetFile = new File(targetDir, sourceFile.getName());
        Log.d(TAG, "Migrating " + sourceFile + " to " + targetFile);
        try {
            FileUtils.copyFileOrThrow(sourceFile, targetFile);
            FileUtils.copyPermissions(sourceFile, targetFile);
            if (!sourceFile.delete()) {
                throw new IOException("Failed to clean up " + sourceFile);
            }
            if (res != -1) {
                res++;
            }
        } catch (IOException e) {
            Log.w(TAG, "Failed to migrate " + sourceFile + ": " + e);
            res = -1;
        }
    }
    return res;
}