List of usage examples for org.apache.commons.io FileExistsException FileExistsException
public FileExistsException(File file)
From source file:es.uvigo.ei.sing.adops.operations.CopyExperiment.java
@Port(order = 3, direction = Direction.OUTPUT) public Experiment copyExperiment() throws IOException, IllegalArgumentException { final File newFolder = new File(this.experiment.getFolder().getParentFile(), this.name); if (newFolder.exists()) throw new FileExistsException("New experiment folder already exists (" + newFolder + ")"); if (!(new File(newFolder, this.experiment.getFilesFolder().getName()).mkdirs())) throw new IOException("Error writing in new folder (" + newFolder + ")"); FileUtils.copyFile(this.experiment.getPropertiesFile(), new File(newFolder, this.experiment.getPropertiesFile().getName())); FileUtils.copyFile(this.experiment.getNotesFile(), new File(newFolder, this.experiment.getNotesFile().getName())); return new ProjectExperiment(this.experiment.getProject(), newFolder); }
From source file:de.lazyzero.kkMulticopterFlashTool.utils.Zip.java
public static void unzip2folder(File zipFile, File toFolder) throws FileExistsException { if (!toFolder.exists()) { toFolder.mkdirs();/*from www . j av a2 s . co m*/ } else if (toFolder.isFile()) { throw new FileExistsException(toFolder.getName()); } try { ZipEntry entry; @SuppressWarnings("resource") ZipFile zipfile = new ZipFile(zipFile); Enumeration<? extends ZipEntry> e = zipfile.entries(); while (e.hasMoreElements()) { entry = e.nextElement(); // String newDir; // if (entry.getName().indexOf("/") == -1) { // newDir = zipFile.getName().substring(0, zipFile.getName().indexOf(".")); // } else { // newDir = entry.getName().substring(0, entry.getName().indexOf("/")); // } // String folder = toFolder + (File.separatorChar+"") + newDir; // System.out.println(folder); // if ((new File(folder).mkdir())) { // System.out.println("Done."); // } System.out.println("Extracting: " + entry); if (entry.isDirectory()) { new File(toFolder + (File.separatorChar + "") + entry.getName()).mkdir(); } else { BufferedInputStream is = new BufferedInputStream(zipfile.getInputStream(entry)); int count; byte data[] = new byte[2048]; String fileName = toFolder + (File.separatorChar + "") + entry.getName(); FileOutputStream fos = new FileOutputStream(fileName); BufferedOutputStream dest = new BufferedOutputStream(fos, 2048); while ((count = is.read(data, 0, 2048)) != -1) { dest.write(data, 0, count); } dest.flush(); dest.close(); is.close(); System.out.println("extracted to: " + fileName); } } } catch (ZipException e1) { zipFile.delete(); e1.printStackTrace(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } finally { } }
From source file:com.docd.purefm.utils.PFMFileUtils.java
public static void moveFile(@NonNull final GenericFile source, @NonNull final GenericFile target, final boolean useCommandLine) throws IOException { if (useCommandLine) { if (target.exists()) { throw new FileExistsException("Target exists"); }/* w ww. java2 s. c o m*/ final boolean result = CommandLine.execute(new CommandMove(source, target)); if (!result) { throw new IOException("Move failed"); } } else { FileUtils.moveFile(source.toFile(), target.toFile()); } }
From source file:edu.monash.merc.util.file.DMFileUtils.java
public static void moveFile(File srcFile, File destFile, boolean override) { try {// www. j a v a2 s. c om if (srcFile == null) { throw new NullPointerException("Source file must not be null"); } if (destFile == null) { throw new NullPointerException("Destination file must not be null"); } if (!srcFile.exists()) { throw new FileNotFoundException("Source '" + srcFile + "' does not exist"); } if (srcFile.isDirectory()) { throw new IOException("Source '" + srcFile + "' is a directory"); } if (destFile.exists() && !override) { throw new FileExistsException("Destination '" + destFile + "' already exists"); } if (destFile.isDirectory()) { throw new IOException("Destination '" + destFile + "' is a directory"); } boolean rename = srcFile.renameTo(destFile); if (!rename) { copyFile(srcFile, destFile, true); if (!srcFile.delete()) { FileUtils.deleteQuietly(destFile); throw new IOException( "Failed to delete original file '" + srcFile + "' after copy to '" + destFile + "'"); } } } catch (Exception e) { throw new DMFileException(e); } }
From source file:com.docd.purefm.utils.PFMFileUtils.java
public static void moveDirectory(@NonNull final GenericFile source, @NonNull final GenericFile target, final boolean useCommandLine) throws IOException { if (useCommandLine) { if (target.exists()) { throw new FileExistsException("Target exists"); }//from w w w. j a va2s . c o m final boolean result = CommandLine.execute(new CommandMove(source, target)); if (!result) { throw new IOException("Move failed"); } } else { FileUtils.moveDirectory(source.toFile(), target.toFile()); } }
From source file:fr.gael.dhus.datastore.processing.impl.ProcessProductTransfer.java
public void moveFile(File srcFile, File destFile, boolean compute_checksum) throws IOException, NoSuchAlgorithmException { if (srcFile == null) { throw new NullPointerException("Source must not be null"); }//from w w w .jav a2 s.com if (destFile == null) { throw new NullPointerException("Destination must not be null"); } if (!srcFile.exists()) { throw new FileNotFoundException("Source '" + srcFile + "' does not exist"); } if (srcFile.isDirectory()) { throw new IOException("Source '" + srcFile + "' is a directory"); } if (destFile.exists()) { throw new FileExistsException("Destination '" + destFile + "' already exists"); } if (destFile.isDirectory()) { throw new IOException("Destination '" + destFile + "' is a directory"); } boolean rename = srcFile.renameTo(destFile); if (!rename) { copyFile(srcFile, destFile, compute_checksum); if (!srcFile.delete()) { FileUtils.deleteQuietly(destFile); throw new IOException( "Failed to delete original file '" + srcFile + "' after copy to '" + destFile + "'"); } } }
From source file:fr.gael.dhus.datastore.processing.ProcessingManager.java
private void moveFile(File src_file, File dest_file) throws IOException, NoSuchAlgorithmException { if (src_file == null) { throw new NullPointerException("Source must not be null"); }/*from ww w . j a va 2 s .co m*/ if (dest_file == null) { throw new NullPointerException("Destination must not be null"); } if (!src_file.exists()) { throw new FileNotFoundException("Source '" + src_file + "' does not exist"); } if (src_file.isDirectory()) { throw new IOException("Source '" + src_file + "' is a directory"); } if (dest_file.exists()) { throw new FileExistsException("Destination '" + dest_file + "' already exists"); } if (dest_file.isDirectory()) { throw new IOException("Destination '" + dest_file + "' is a directory"); } boolean rename = src_file.renameTo(dest_file); if (!rename) { copyFile(src_file, dest_file); if (!src_file.delete()) { FileUtils.deleteQuietly(dest_file); throw new IOException( "Failed to delete original file '" + src_file + "' after copy to '" + dest_file + "'"); } } }
From source file:com.example.util.FileUtils.java
/** * Moves a directory.// w w w . j a v a 2s . co m * <p> * When the destination directory is on another file system, do a "copy and delete". * * @param srcDir the directory to be moved * @param destDir the destination directory * @throws NullPointerException if source or destination is {@code null} * @throws FileExistsException if the destination directory exists * @throws IOException if source or destination is invalid * @throws IOException if an IO error occurs moving the file * @since 1.4 */ public static void moveDirectory(File srcDir, File destDir) throws IOException { if (srcDir == null) { throw new NullPointerException("Source must not be null"); } if (destDir == null) { throw new NullPointerException("Destination must not be null"); } if (!srcDir.exists()) { throw new FileNotFoundException("Source '" + srcDir + "' does not exist"); } if (!srcDir.isDirectory()) { throw new IOException("Source '" + srcDir + "' is not a directory"); } if (destDir.exists()) { throw new FileExistsException("Destination '" + destDir + "' already exists"); } boolean rename = srcDir.renameTo(destDir); if (!rename) { if (destDir.getCanonicalPath().startsWith(srcDir.getCanonicalPath())) { throw new IOException( "Cannot move directory: " + srcDir + " to a subdirectory of itself: " + destDir); } copyDirectory(srcDir, destDir); deleteDirectory(srcDir); if (srcDir.exists()) { throw new IOException( "Failed to delete original directory '" + srcDir + "' after copy to '" + destDir + "'"); } } }
From source file:com.example.util.FileUtils.java
/** * Moves a file./*from w w w. j av a 2 s . c om*/ * <p> * When the destination file is on another file system, do a "copy and delete". * * @param srcFile the file to be moved * @param destFile the destination file * @throws NullPointerException if source or destination is {@code null} * @throws FileExistsException if the destination file exists * @throws IOException if source or destination is invalid * @throws IOException if an IO error occurs moving the file * @since 1.4 */ public static void moveFile(File srcFile, File destFile) throws IOException { if (srcFile == null) { throw new NullPointerException("Source must not be null"); } if (destFile == null) { throw new NullPointerException("Destination must not be null"); } if (!srcFile.exists()) { throw new FileNotFoundException("Source '" + srcFile + "' does not exist"); } if (srcFile.isDirectory()) { throw new IOException("Source '" + srcFile + "' is a directory"); } if (destFile.exists()) { throw new FileExistsException("Destination '" + destFile + "' already exists"); } if (destFile.isDirectory()) { throw new IOException("Destination '" + destFile + "' is a directory"); } boolean rename = srcFile.renameTo(destFile); if (!rename) { copyFile(srcFile, destFile); if (!srcFile.delete()) { FileUtils.deleteQuietly(destFile); throw new IOException( "Failed to delete original file '" + srcFile + "' after copy to '" + destFile + "'"); } } }
From source file:org.apache.accumulo.test.util.CertUtils.java
public void createSelfSignedCert(File targetKeystoreFile, String keyName, String keystorePassword) throws KeyStoreException, CertificateException, NoSuchAlgorithmException, IOException, OperatorCreationException, AccumuloSecurityException, NoSuchProviderException { if (targetKeystoreFile.exists()) { throw new FileExistsException(targetKeystoreFile); }/*from w ww .jav a2 s .c o m*/ KeyPair kp = generateKeyPair(); X509CertificateObject cert = generateCert(keyName, kp, true, kp.getPublic(), kp.getPrivate()); char[] password = keystorePassword.toCharArray(); KeyStore keystore = KeyStore.getInstance(keystoreType); keystore.load(null, null); keystore.setCertificateEntry(keyName + "Cert", cert); keystore.setKeyEntry(keyName + "Key", kp.getPrivate(), password, new Certificate[] { cert }); try (FileOutputStream fos = new FileOutputStream(targetKeystoreFile)) { keystore.store(fos, password); } }