List of usage examples for org.apache.cordova.file File getName
public String getName()
From source file:com.MustacheMonitor.MustacheMonitor.FileUtils.java
License:Apache License
/** * Creates the destination File object based on name passed in * * @param newName for the file directory to be called, if null use existing file name * @param fp represents the source file//from ww w . jav a 2 s . c o m * @param destination represents the destination file * @return a File object that represents the destination */ private File createDestination(String newName, File fp, File destination) { File destFile = null; // I know this looks weird but it is to work around a JSON bug. if ("null".equals(newName) || "".equals(newName)) { newName = null; } if (newName != null) { destFile = new File(destination.getAbsolutePath() + File.separator + newName); } else { destFile = new File(destination.getAbsolutePath() + File.separator + fp.getName()); } return destFile; }
From source file:com.MustacheMonitor.MustacheMonitor.FileUtils.java
License:Apache License
/** * Copy a directory/*from w w w . j a v a 2 s . c o m*/ * * @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
/** * Loops through a directory deleting all the files. * * @param directory to be removed/* ww w .ja v a 2 s .c o m*/ * @return a boolean representing success of failure * @throws FileExistsException */ private boolean removeDirRecursively(File directory) throws FileExistsException { if (directory.isDirectory()) { for (File file : directory.listFiles()) { removeDirRecursively(file); } } if (!directory.delete()) { throw new FileExistsException("could not delete: " + directory.getName()); } else { return true; } }
From source file:com.MustacheMonitor.MustacheMonitor.FileUtils.java
License:Apache License
/** * Returns a File that represents the current state of the file that this FileEntry represents. * * @param filePath to entry//from w w w . j av a 2 s. c o m * @return returns a JSONObject represent a W3C File object * @throws FileNotFoundException * @throws JSONException */ private JSONObject getFileMetadata(String filePath) throws FileNotFoundException, JSONException { File file = createFileObject(filePath); if (!file.exists()) { throw new FileNotFoundException("File: " + filePath + " does not exist."); } JSONObject metadata = new JSONObject(); metadata.put("size", file.length()); metadata.put("type", getMimeType(filePath)); metadata.put("name", file.getName()); metadata.put("fullPath", file.getAbsolutePath()); metadata.put("lastModifiedDate", file.lastModified()); return metadata; }
From source file:com.MustacheMonitor.MustacheMonitor.FileUtils.java
License:Apache License
/** * Returns a JSON Object representing a directory on the device's file system * * @param path to the directory// w w w .j a v a2s . c om * @return * @throws JSONException */ public JSONObject getEntry(File file) throws JSONException { JSONObject entry = new JSONObject(); entry.put("isFile", file.isFile()); entry.put("isDirectory", file.isDirectory()); entry.put("name", file.getName()); entry.put("fullPath", "file://" + file.getAbsolutePath()); // I can't add the next thing it as it would be an infinite loop //entry.put("filesystem", null); return entry; }