List of usage examples for org.apache.cordova.file NoModificationAllowedException NoModificationAllowedException
public NoModificationAllowedException(String message)
From source file:com.MustacheMonitor.MustacheMonitor.FileUtils.java
License:Apache License
/** * Copy a directory/*from w w w . j ava2 s. com*/ * * @param srcDir directory to be copied * @param destinationDir destination to be copied to * @return a DirectoryEntry object * @throws JSONException * @throws IOException * @throws NoModificationAllowedException * @throws InvalidModificationException */ private JSONObject copyDirectory(File srcDir, File destinationDir) throws JSONException, IOException, NoModificationAllowedException, InvalidModificationException { // Renaming a file to an existing directory should fail if (destinationDir.exists() && destinationDir.isFile()) { throw new InvalidModificationException("Can't rename a file to a directory"); } // Check to make sure we are not copying the directory into itself if (isCopyOnItself(srcDir.getAbsolutePath(), destinationDir.getAbsolutePath())) { throw new InvalidModificationException("Can't copy itself into itself"); } // See if the destination directory exists. If not create it. if (!destinationDir.exists()) { if (!destinationDir.mkdir()) { // If we can't create the directory then fail throw new NoModificationAllowedException("Couldn't create the destination direcotry"); } } for (File file : srcDir.listFiles()) { if (file.isDirectory()) { copyDirectory(file, destinationDir); } else { File destination = new File(destinationDir.getAbsoluteFile() + File.separator + file.getName()); copyFile(file, destination); } } return getEntry(destinationDir); }
From source file:com.MustacheMonitor.MustacheMonitor.FileUtils.java
License:Apache License
/** * Deletes a file or directory. It is an error to attempt to delete a directory that is not empty. * It is an error to attempt to delete the root directory of a filesystem. * * @param filePath file or directory to be removed * @return a boolean representing success of failure * @throws NoModificationAllowedException * @throws InvalidModificationException/*from ww w . ja v a 2 s.c o m*/ */ private boolean remove(String filePath) throws NoModificationAllowedException, InvalidModificationException { File fp = createFileObject(filePath); // You can't delete the root directory. if (atRootDirectory(filePath)) { throw new NoModificationAllowedException("You can't delete the root directory"); } // You can't delete a directory that is not empty if (fp.isDirectory() && fp.list().length > 0) { throw new InvalidModificationException("You can't delete a directory that is not empty."); } return fp.delete(); }