private JSONObject getFile(String paramString1, String paramString2, JSONObject paramJSONObject, boolean paramBoolean) throws FileExistsException, IOException, TypeMismatchException, EncodingException, JSONException { boolean bool1 = false; boolean bool2 = false; if (paramJSONObject != null) { bool1 = paramJSONObject.optBoolean("create"); bool2 = false; if (bool1) bool2 = paramJSONObject.optBoolean("exclusive"); } if (paramString2.contains(":")) throw new EncodingException("This file has a : in it's name"); File localFile = createFileObject(paramString1, paramString2); if (bool1) { if ((bool2) && (localFile.exists())) throw new FileExistsException("create/exclusive fails"); if (paramBoolean) localFile.mkdir(); while (!localFile.exists()) { throw new FileExistsException("create fails"); localFile.createNewFile(); } } if (!localFile.exists()) throw new FileNotFoundException("path does not exist"); if (paramBoolean) { if (localFile.isFile()) throw new TypeMismatchException("path doesn't exist or is file"); } else if (localFile.isDirectory()) throw new TypeMismatchException("path doesn't exist or is directory"); return getEntry(localFile); }
/** * Creates or looks up a file. * * @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); }