org.apache.commons.io.FileExistsException Java Examples
The following examples show how to use
org.apache.commons.io.FileExistsException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SafeFileOutputCommitter.java From datawave with Apache License 2.0 | 6 votes |
/** * Cleanup the job. Note that this is deprecated in the super class but is still being used for this work. When the method has been removed from the super * class then this class will need to be reworked. */ @Override public void cleanupJob(JobContext context) throws IOException { if (checkForEmptyDir) { if (this.outputPath != null) { Path pendingJobAttemptsPath = getPendingJobAttemptsPath(); FileSystem fs = pendingJobAttemptsPath.getFileSystem(context.getConfiguration()); // now verify we do not have any files left in the temporary directory structure List<Path> fileList = new ArrayList<>(); if (containsFiles(fs, pendingJobAttemptsPath, fileList)) { throw new FileExistsException("Found files still left in the temporary job attempts path: " + fileList); } } } super.cleanupJob(context); }
Example #2
Source File: FileUtils.java From lucene-solr with Apache License 2.0 | 5 votes |
public static Path createDirectories(Path path) throws IOException { if (Files.exists(path) && Files.isSymbolicLink(path)) { Path real = path.toRealPath(); if (Files.isDirectory(real)) return real; throw new FileExistsException("Tried to create a directory at to an existing non-directory symlink: " + path.toString()); } return Files.createDirectories(path); }
Example #3
Source File: CoreUtils.java From TranskribusCore with GNU General Public License v3.0 | 5 votes |
public static File createDirectory(String path, boolean overwrite) throws FileExistsException, IOException { File dir = new File(path); if (dir.exists()) { if (overwrite) { FileUtils.forceDelete(dir); } else { throw new FileExistsException("Output path already exists: " + path); } } if (!dir.mkdirs()) throw new IOException("Could not create directory: " + path); return dir; }
Example #4
Source File: LayoutManagementService.java From abixen-platform with GNU Lesser General Public License v2.1 | 5 votes |
@PreAuthorize("hasPermission(#id, '" + AclClassName.Values.LAYOUT + "', '" + PermissionName.Values.LAYOUT_EDIT + "')") public LayoutDto changeLayoutIcon(final Long id, final MultipartFile iconFile) throws IOException { log.debug("changeLayoutIcon() - id: {}, iconFile: {}", id, iconFile); final Layout layout = layoutService.find(id); //FIXME - rename to thumbnail final File currentThumbnailFile = new File(platformResourceConfigurationProperties.getImageLibraryDirectory() + "/layout-miniature/" + layout.getIconFileName()); if (currentThumbnailFile.exists()) { if (!currentThumbnailFile.delete()) { throw new FileExistsException(); } } final PasswordEncoder encoder = new BCryptPasswordEncoder(); final String newIconFileName = encoder.encode(iconFile.getName() + new Date().getTime()).replaceAll("\"", "s").replaceAll("/", "a").replace(".", "sde"); final File newIconFile = new File(platformResourceConfigurationProperties.getImageLibraryDirectory() + "/layout-miniature/" + newIconFileName); final FileOutputStream out = new FileOutputStream(newIconFile); out.write(iconFile.getBytes()); out.close(); layout.changeIconFileName(newIconFileName); final Layout updatedLayout = layoutService.update(layout); return layoutToLayoutDtoConverter.convert(updatedLayout); }
Example #5
Source File: User.java From abixen-platform with GNU Lesser General Public License v2.1 | 5 votes |
public void changeAvatar(String imageLibraryDirectory, MultipartFile avatarFile) throws IOException { final File currentAvatarFile = new File(imageLibraryDirectory + "/user-avatar/" + getAvatarFileName()); if (currentAvatarFile.exists()) { if (!currentAvatarFile.delete()) { throw new FileExistsException(); } } final PasswordEncoder encoder = new BCryptPasswordEncoder(); final String newAvatarFileName = encoder.encode(avatarFile.getName() + new Date().getTime()).replaceAll("\"", "s").replaceAll("/", "a").replace(".", "sde"); final File newAvatarFile = new File(imageLibraryDirectory + "/user-avatar/" + newAvatarFileName); final FileOutputStream out = new FileOutputStream(newAvatarFile); out.write(avatarFile.getBytes()); out.close(); setAvatarFileName(newAvatarFileName); }
Example #6
Source File: MoveFileBatchlet.java From wow-auctions with GNU General Public License v3.0 | 5 votes |
@Override public String process() throws Exception { File file = getContext().getFileToProcess(FolderType.valueOf(from)); File destinationFolder = getContext().getFolder(FolderType.valueOf(to)); try { getLogger(this.getClass().getName()).log(Level.INFO, "Moving file " + file + " to " + destinationFolder); moveFileToDirectory(file, destinationFolder, false); } catch (FileExistsException e) { getLogger(this.getClass().getName()).log(Level.WARNING, "File " + file + " already exists at " + destinationFolder); } return "COMPLETED"; }
Example #7
Source File: ProcessingManager.java From DataHubSystem with GNU Affero General Public License v3.0 | 4 votes |
private void moveFile (File src_file, File dest_file) throws IOException, NoSuchAlgorithmException { if (src_file == null) { throw new NullPointerException ("Source must not be null"); } 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 + "'"); } } }
Example #8
Source File: BlobStoreUtils.java From jstorm with Apache License 2.0 | 4 votes |
public static void downloadLocalStormCode(Map conf, String topologyId, String masterCodeDir) throws IOException, TException { // STORM_LOCAL_DIR/supervisor/tmp/(UUID) String tmpRoot = StormConfig.supervisorTmpDir(conf) + File.separator + UUID.randomUUID().toString(); // STORM-LOCAL-DIR/supervisor/stormdist/storm-id String stormRoot = StormConfig.supervisor_stormdist_root(conf, topologyId); BlobStore blobStore = null; try { blobStore = BlobStoreUtils.getNimbusBlobStore(conf, masterCodeDir, null); FileUtils.forceMkdir(new File(tmpRoot)); blobStore.readBlobTo(StormConfig.master_stormcode_key(topologyId), new FileOutputStream(StormConfig.stormcode_path(tmpRoot))); blobStore.readBlobTo(StormConfig.master_stormconf_key(topologyId), new FileOutputStream(StormConfig.stormconf_path(tmpRoot))); } finally { if (blobStore != null) blobStore.shutdown(); } File srcDir = new File(tmpRoot); File destDir = new File(stormRoot); try { FileUtils.moveDirectory(srcDir, destDir); } catch (FileExistsException e) { FileUtils.copyDirectory(srcDir, destDir); FileUtils.deleteQuietly(srcDir); } ClassLoader classloader = Thread.currentThread().getContextClassLoader(); String resourcesJar = resourcesJar(); URL url = classloader.getResource(StormConfig.RESOURCES_SUBDIR); String targetDir = stormRoot + '/' + StormConfig.RESOURCES_SUBDIR; if (resourcesJar != null) { LOG.info("Extracting resources from jar at " + resourcesJar + " to " + targetDir); JStormUtils.extractDirFromJar(resourcesJar, StormConfig.RESOURCES_SUBDIR, stormRoot); } else if (url != null) { LOG.info("Copying resources at " + url.toString() + " to " + targetDir); FileUtils.copyDirectory(new File(url.getFile()), (new File(targetDir))); } }