List of usage examples for org.apache.commons.io FileExistsException getLocalizedMessage
public String getLocalizedMessage()
From source file:net.osten.watermap.batch.FetchPCTWaypointsJob.java
private void unZipIt(File zipFile, File outputFolder) { byte[] buffer = new byte[1024]; try (ZipInputStream zis = new ZipInputStream(new FileInputStream(zipFile))) { // get the zipped file list entry ZipEntry ze = zis.getNextEntry(); while (ze != null) { String fileName = ze.getName(); File newFile = new File(outputFolder.getAbsolutePath() + File.separator + fileName); log.log(Level.FINER, "file unzip : {0}", new Object[] { newFile.getAbsoluteFile() }); // create all non existing folders else you will hit FileNotFoundException for compressed folder new File(newFile.getParent()).mkdirs(); try (FileOutputStream fos = new FileOutputStream(newFile)) { int len; while ((len = zis.read(buffer)) > 0) { fos.write(buffer, 0, len); }// ww w . j a va 2 s. c om } ze = zis.getNextEntry(); // move newFile to data directory try { // have to delete first since FileUtils does not overwrite File destinationFile = new File(outputFolder + File.separator + newFile.getName()); if (destinationFile.exists()) { destinationFile.delete(); } FileUtils.moveFileToDirectory(newFile, outputFolder, false); } catch (FileExistsException ioe) { log.warning(ioe.getLocalizedMessage()); } catch (IOException ioe) { log.warning(ioe.getLocalizedMessage()); } } // close the last entry zis.closeEntry(); } catch (IOException e) { log.warning(e.getLocalizedMessage()); } }
From source file:eu.chocolatejar.eclipse.plugin.cleaner.Cleaner.java
/** * Removes and back duplicates up./*from ww w .j a v a 2 s . c o m*/ * * @param duplicates * list of artifacts to remove * @param type * either {@link #PLUGINS} or {@link #FEATURES} */ private void removeAndBackupDuplicates(final Set<Artifact> duplicates, final String type) { File destinationTypeFolder = FileUtils.getFile(backupFolder, type); for (Artifact artifact : duplicates) { logger.info("Cleaning {}", artifact); try { FileUtils.moveToDirectory(artifact.getLocation(), destinationTypeFolder, true); logger.info(" OK"); } catch (FileExistsException e1) { // the bundle was already copied there from an other // location, so it means we have more duplicates in multiple // location(s) with the same version, simply just delete it! boolean wasDeleted = FileUtils.deleteQuietly(artifact.getLocation()); if (wasDeleted) { logger.warn( " --> The duplicate `{}` was deleted directly without creating a copy in the destination folder due to \n `{}`.", artifact, e1.getLocalizedMessage()); } else { logger.warn(" Unable to remove the duplicate '{}' from '{}'.", artifact, artifact.getLocation()); } } catch (Exception e) { logger.error("Unable to remove the duplicate '{}'.", artifact, e); } } }