List of usage examples for org.apache.commons.io FileExistsException FileExistsException
public FileExistsException()
From source file:com.abixen.platform.core.service.impl.LayoutServiceImpl.java
@Override public Layout changeIcon(Long id, MultipartFile iconFile) throws IOException { Layout layout = findLayout(id);/* w w w . j a va2 s. c om*/ File currentAvatarFile = new File(platformResourceConfigurationProperties.getImageLibraryDirectory() + "/layout-miniature/" + layout.getIconFileName()); if (currentAvatarFile.exists()) { if (!currentAvatarFile.delete()) { throw new FileExistsException(); } } PasswordEncoder encoder = new BCryptPasswordEncoder(); String newIconFileName = encoder.encode(iconFile.getName() + new Date().getTime()).replaceAll("\"", "s") .replaceAll("/", "a").replace(".", "sde"); File newIconFile = new File(platformResourceConfigurationProperties.getImageLibraryDirectory() + "/layout-miniature/" + newIconFileName); FileOutputStream out = new FileOutputStream(newIconFile); out.write(iconFile.getBytes()); out.close(); layout.setIconFileName(newIconFileName); updateLayout(layout); return findLayout(id); }
From source file:com.splunk.shuttl.testutil.TUtilsFile.java
/** * Creates a temp directory with a name of the parameter. <br/> * Wraps the FileExistException in a {@link RuntimeException} to avoid the * try/catch./*from w w w . j a v a 2 s. com*/ * * @param string * name of the temp directory * @return temporary directory that's deleted when the VM terminates. */ public static File createPrefixedDirectory(String string) { File dir = getUniquelyNamedFileWithPrefix(string); if (dir.exists()) throw new RuntimeException(new FileExistsException()); createDirectory(dir); return dir; }
From source file:com.abixen.platform.core.application.service.LayoutManagementService.java
@PreAuthorize("hasPermission(#id, '" + AclClassName.Values.LAYOUT + "', '" + PermissionName.Values.LAYOUT_EDIT + "')")/* w w w . j a va 2 s. com*/ 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); }
From source file:com.abixen.platform.core.service.impl.UserServiceImpl.java
@Override public User changeUserAvatar(Long userId, MultipartFile avatarFile) throws IOException { User user = findUser(userId);/* w ww. jav a 2 s . co m*/ File currentAvatarFile = new File(platformResourceConfigurationProperties.getImageLibraryDirectory() + "/user-avatar/" + user.getAvatarFileName()); if (currentAvatarFile.exists()) { if (!currentAvatarFile.delete()) { throw new FileExistsException(); } } PasswordEncoder encoder = new BCryptPasswordEncoder(); String newAvatarFileName = encoder.encode(avatarFile.getName() + new Date().getTime()).replaceAll("\"", "s") .replaceAll("/", "a").replace(".", "sde"); File newAvatarFile = new File(platformResourceConfigurationProperties.getImageLibraryDirectory() + "/user-avatar/" + newAvatarFileName); FileOutputStream out = new FileOutputStream(newAvatarFile); out.write(avatarFile.getBytes()); out.close(); user.setAvatarFileName(newAvatarFileName); updateUser(user); return findUser(userId); }
From source file:com.abixen.platform.core.domain.model.User.java
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(); }/*from www . j a va 2 s . c o m*/ } 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); }
From source file:com.cisco.ca.cstg.pdi.services.ConfigurationServiceImpl.java
@Override public void validateAndCopyFile(MultipartFile file, Integer projectId) throws IOException { String copyFolderPath = null; String projectPath = null;/*from ww w . j av a 2 s . c o m*/ boolean status = false; File tempFile = null; if (file.getOriginalFilename().toLowerCase().matches(".*\\.zip$|.*\\.xml$")) { copyFolderPath = Util.getPdiConfFolderPath(projectDetailsService.fetchProjectDetails(projectId)); projectPath = Util.getPdiConfDataFolderPath(projectDetailsService.fetchProjectDetails(projectId)); // if exists delete previously created folder deletePreviousUcsData(projectId); // create project folder Util.createFolder(projectPath); tempFile = new File(copyFolderPath + File.separator + file.getOriginalFilename()); file.transferTo(tempFile); if (tempFile.getName().toLowerCase().matches(".*\\.zip$") && validateZipFile(tempFile)) { copyZipFile(tempFile, projectPath); status = true; } else { copyXmlFile(tempFile, projectPath); status = true; } if (!status) { throw new FileExistsException(); } } }