List of usage examples for org.apache.cordova.file EncodingException EncodingException
public EncodingException(String message)
From source file:com.MustacheMonitor.MustacheMonitor.FileUtils.java
License:Apache License
/** * A setup method that handles the move/copy of files/directories * * @param fileName to be copied/moved// ww w . j a va 2 s. c om * @param newParent is the location where the file will be copied/moved to * @param newName for the file directory to be called, if null use existing file name * @param move if false do a copy, if true do a move * @return a Entry object * @throws NoModificationAllowedException * @throws IOException * @throws InvalidModificationException * @throws EncodingException * @throws JSONException */ private JSONObject transferTo(String fileName, String newParent, String newName, boolean move) throws JSONException, NoModificationAllowedException, IOException, InvalidModificationException, EncodingException { fileName = stripFileProtocol(fileName); newParent = stripFileProtocol(newParent); // Check for invalid file name if (newName != null && newName.contains(":")) { throw new EncodingException("Bad file name"); } File source = new File(fileName); if (!source.exists()) { // The file/directory we are copying doesn't exist so we should fail. throw new FileNotFoundException("The source does not exist"); } File destinationDir = new File(newParent); if (!destinationDir.exists()) { // The destination does not exist so we should fail. throw new FileNotFoundException("The source does not exist"); } // Figure out where we should be copying to File destination = createDestination(newName, source, destinationDir); //Log.d(LOG_TAG, "Source: " + source.getAbsolutePath()); //Log.d(LOG_TAG, "Destin: " + destination.getAbsolutePath()); // Check to see if source and destination are the same file if (source.getAbsolutePath().equals(destination.getAbsolutePath())) { throw new InvalidModificationException("Can't copy a file onto itself"); } if (source.isDirectory()) { if (move) { return moveDirectory(source, destination); } else { return copyDirectory(source, destination); } } else { if (move) { return moveFile(source, destination); } else { return copyFile(source, destination); } } }
From source file:com.MustacheMonitor.MustacheMonitor.FileUtils.java
License:Apache License
/** * Creates or looks up a file./*from w w w . jav a 2s . c o m*/ * * @param dirPath base directory * @param fileName file/directory to lookup or create * @param options specify whether to create or not * @param directory if true look up directory, if false look up file * @return a Entry object * @throws FileExistsException * @throws IOException * @throws TypeMismatchException * @throws EncodingException * @throws JSONException */ private JSONObject getFile(String dirPath, String fileName, JSONObject options, boolean directory) throws FileExistsException, IOException, TypeMismatchException, EncodingException, JSONException { boolean create = false; boolean exclusive = false; if (options != null) { create = options.optBoolean("create"); if (create) { exclusive = options.optBoolean("exclusive"); } } // Check for a ":" character in the file to line up with BB and iOS if (fileName.contains(":")) { throw new EncodingException("This file has a : in it's name"); } File fp = createFileObject(dirPath, fileName); if (create) { if (exclusive && fp.exists()) { throw new FileExistsException("create/exclusive fails"); } if (directory) { fp.mkdir(); } else { fp.createNewFile(); } if (!fp.exists()) { throw new FileExistsException("create fails"); } } else { if (!fp.exists()) { throw new FileNotFoundException("path does not exist"); } if (directory) { if (fp.isFile()) { throw new TypeMismatchException("path doesn't exist or is file"); } } else { if (fp.isDirectory()) { throw new TypeMismatchException("path doesn't exist or is directory"); } } } // Return the directory return getEntry(fp); }