List of usage examples for org.apache.cordova.file TypeMismatchException TypeMismatchException
public TypeMismatchException(String message)
From source file:com.MustacheMonitor.MustacheMonitor.FileUtils.java
License:Apache License
/** * Creates or looks up a file.//from w w w . ja va 2 s . 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); }