List of usage examples for java.nio.file FileAlreadyExistsException FileAlreadyExistsException
public FileAlreadyExistsException(String file)
From source file:com.clothcat.rfcreader.network.RfcFetcher.java
private static void fetchIndexSafely(String url) throws FileAlreadyExistsException { // TODO handle exceptions better File f = new File(Constants.RFC_INDEX_LOCAL_NAME); if (f.exists()) { throw new FileAlreadyExistsException(f.getAbsolutePath()); } else {// ww w .j a v a 2s . c om try { URL u = new URL(url); FileUtils.copyURLToFile(u, f); } catch (MalformedURLException ex) { Logger.getLogger(RfcFetcher.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(RfcFetcher.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:org.moe.cli.utils.GrabUtils.java
/** * The method downloads file from given URI. * URI can be a path to local file/directory, remote archive or a file in remote .git repository. Output file should have same format to the input. * <br>Path to the file in remote .git repository should be in the format: <path to repo>.git#<tag/commit>:<path to file from repo's root> * <br>Example: https://github.com/NatJPods/Bindings.git#Example:Bindings/Google/1.3.2 * /*ww w. j a v a2s . c o m*/ * @param link file to download * @param dest destination * @throws FileAlreadyExistsException if file has already exists * @throws FileNotFoundException if source doesn't exist * @throws UnsupportedTypeException if URI links to file with unsupported type * @throws URISyntaxException if URI have unsupported or wrong format * @throws IOException if operation couldn't be successfully completed because of other reasons */ public static void download(@NonNull URI link, @NonNull File dest) throws FileAlreadyExistsException, FileNotFoundException, UnsupportedTypeException, URISyntaxException, IOException { if (dest.exists()) { throw new FileAlreadyExistsException(dest.toString() + " has already exists"); } String scheme = link.getScheme(); if (scheme == null) { //assume that FileUtils can handle it URL url = link.toURL(); FileUtils.copyURLToFile(url, dest); } else { String[] gitRepo = parseGitURI(link); if (gitRepo != null) { //try to parse it like a git repo URI git = new URI(gitRepo[0]); String tag = gitRepo[1]; Path file = Paths.get(gitRepo[2]); downloadFileFromGit(git, tag, file, dest); } else if (scheme.equals("file")) { File local = new File(link); if (local.exists()) { if (local.isDirectory()) { FileUtils.copyDirectory(local, dest); } else { FileUtils.copyFile(local, dest); } } else { throw new FileNotFoundException(local.toString() + " doesn't exists"); } } else {//this isn't a local or git repository downloadFileFromRemote(link, dest); } } }
From source file:com.bancvue.mongomigrate.CreateCommand.java
public int execute() { int exitCode = 0; Path file = null;/*from www . j a v a2s . co m*/ try { // Ensure migrations folder exists. Path folder = Paths.get(migrationsFolder); if (!Files.exists(folder)) { Files.createDirectories(folder); } // Generate filename and ensure it doesn't already exist. file = Paths.get(migrationsFolder, generateMigrationFileName(migrationName)); if (Files.exists(file)) throw new FileAlreadyExistsException(file.toAbsolutePath().toString()); // Write the file. BufferedWriter writer = Files.newBufferedWriter(file, Charset.forName("UTF-8")); writer.write("// Add migration javascript here.\n"); writer.write("db.<collection_name>.update(\n"); writer.write(" { <query> },\n"); writer.write(" { <update> },\n"); writer.write(" { multi: true }\n"); writer.write(");\n"); writer.flush(); writer.close(); System.out.println("Created migration file: " + file.toString()); } catch (FileAlreadyExistsException e) { System.err.println("The specified migration file " + file.toString() + " already exists."); exitCode = 1; } catch (IOException e) { e.printStackTrace(); exitCode = 1; } return exitCode; }
From source file:com.clothcat.rfcreader.network.RfcFetcher.java
/** * Fetch the RFC referred to by number./* w w w. j a va2 s .c o m*/ * * @param num The RFC to fetch * @param overwrite Whether to overwrite any existing file. * @throws java.nio.file.FileAlreadyExistsException */ public static void fetchRfc(int num, boolean overwrite) throws FileAlreadyExistsException { makeDirs(); String base_location = Constants.RFC_BASE_LOCATION; String s = "rfc" + num + ".txt"; File filename = new File(Constants.RFC_CACHE + s); if (filename.exists()) { if (!overwrite) { throw new FileAlreadyExistsException(filename.getAbsolutePath()); } else { filename.delete(); } } try { URL u = new URL(base_location + s); FileUtils.copyURLToFile(u, filename); } catch (MalformedURLException ex) { Logger.getLogger(RfcFetcher.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(RfcFetcher.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:org.apache.taverna.databundle.DataBundles.java
private static void checkExistingAnyExtension(Path path) throws IOException, FileAlreadyExistsException { Path existing = anyExtension(path); if (!path.equals(existing)) throw new FileAlreadyExistsException(existing.toString()); }
From source file:at.beris.virtualfile.client.ftp.FtpClient.java
@Override public void createDirectory(final String path) throws IOException { LOGGER.debug("createDirectory (path : {})", path); executionHandler(new Callable<Void>() { @Override// w w w.j a v a2s .c o m public Void call() throws Exception { int replyCode = ftpClient.mkd(path); String replyText = ftpClient.getReplyString(); if (!FTPReply.isPositiveCompletion(replyCode)) { // this replyText code is set when file already exists on the server if (FTPReply.FILE_UNAVAILABLE == replyCode) throw new FileAlreadyExistsException(path); else LOGGER.warn("Unexpected Reply (Code: {}, Text: '{}'", replyCode, replyText); } return null; } }); }
From source file:com.splicemachine.storage.HNIOFileSystem.java
@Override public void createDirectory(Path dir, FileAttribute<?>... attrs) throws IOException { org.apache.hadoop.fs.Path f = toHPath(dir); if (LOG.isTraceEnabled()) SpliceLogUtils.trace(LOG, "createDirectory(): path=%s", f); try {/* w ww. ja v a 2 s .c o m*/ FileStatus fileStatus = fs.getFileStatus(f); throw new FileAlreadyExistsException(dir.toString()); } catch (FileNotFoundException fnfe) { fs.mkdirs(f); } }
From source file:org.cryptomator.filesystem.crypto.CryptoFolder.java
@Override public void create() { parent.create();// w ww . j ava 2 s .com final boolean newDirIdGiven = directoryId.compareAndSet(null, UUID.randomUUID().toString()); final File dirFile = forceGetPhysicalFile(); final Folder dir = forceGetPhysicalFolder(); if (dirFile.exists() && dir.exists()) { return; } else if (!newDirIdGiven) { throw new IllegalStateException( "Newly created folder, that didn't exist before, already had an directoryId."); } if (parent.file(name).exists()) { throw new UncheckedIOException(new FileAlreadyExistsException(parent.file(name).toString())); } FileContents.UTF_8.writeContents(dirFile, directoryId.get()); dir.create(); }
From source file:org.wikidata.wdtk.testing.MockDirectoryManager.java
@Override public void createFile(String fileName, String fileContents) throws IOException { if (this.hasFile(fileName)) { throw new FileAlreadyExistsException("File exists"); }/*from w ww . j a va2 s. c o m*/ Path filePath = this.directory.resolve(fileName); files.put(filePath, fileContents.getBytes(StandardCharsets.UTF_8)); }
From source file:org.moe.cli.utils.GrabUtils.java
/** * Downloads file from remote .git repository with specified commit. * @param git repository address with .git ending * @param tag tag or commit to clone from; the latest commit will be downloaded if null * @param file relative to repository's root path to file; the whole repository will be downloaded if null * @param output symbolic link to the directory on the local file system where the downloaded file will be stored * @throws FileAlreadyExistsException if output file has already exists * @throws FileNotFoundException if repository doesn't exist * @throws URISyntaxException if URI has unsupported or wrong format * @throws IOException if operation couldn't be successfully completed because of other reasons *//*ww w . j av a2 s .c om*/ public static void downloadFileFromGit(@NonNull URI git, @Nullable String tag, @Nullable Path file, @NonNull File output) throws FileAlreadyExistsException, FileNotFoundException, URISyntaxException, IOException { if (output.exists()) { throw new FileAlreadyExistsException(output.toString() + " already exists!"); } if (!output.mkdir()) { throw new IOException("Couldn't create directory " + output); } String gitRepo = git.toString(); if (!gitRepo.endsWith(".git")) { throw new URISyntaxException(gitRepo, "doesn't match expected pattern"); } String svnCommandAddress = gitRepo.substring(0, gitRepo.length() - 4) + (tag == null ? "/trunk/" : "/tags/" + tag + "/") + (file == null ? "" : file.toString()); try { Svn.export(output, svnCommandAddress); } catch (SvnNotFoundException e) { throw new IOException(e.getMessage()); } catch (ConnectionException e) { throw new IOException(e.getMessage()); } catch (RepositoryNotFoundException e) { throw new FileNotFoundException(e.getMessage()); } catch (NotDirectoryException e) { // this is not realizable case e.printStackTrace(); } }