Source:
public void storeFileToFileSystem(Long userEntityId, String fileId, byte[] content) throws IOException { if (userEntityId == null || fileId == null || content == null) { logger.severe(String.format("Invalid store parameters or no file content: file %s of user %d", fileId, userEntityId)); return; } SystemSetting fileFolderSetting = systemSettingDAO.findByKey(SETTING_FILEFOLDER); if (fileFolderSetting == null || StringUtils.isBlank(fileFolderSetting.getValue())) { throw new IOException("File answer storage folder not set"); } java.io.File fileFolder = Paths.get(fileFolderSetting.getValue()).toFile(); if (!fileFolder.exists() || !fileFolder.isDirectory()) { throw new IOException(String.format("File answer storage folder %s is not a directory", fileFolderSetting.getValue())); } java.io.File userFolder = Paths.get(fileFolder.getPath(), userEntityId.toString()).toFile(); if (!userFolder.exists()) { logger.info(String.format("Creating user file folder %s", userFolder.getPath())); if (!userFolder.mkdir()) { throw new IOException(String.format("Failed to create user file folder %s", userFolder.getPath())); } } java.io.File answerFile = Paths.get(userFolder.getPath(), fileId).toFile(); if (answerFile.exists()) { throw new IOException(String.format("User file %s already exists", answerFile.getPath())); } FileOutputStream fileOutputStream = null; try { fileOutputStream = new FileOutputStream(answerFile); IOUtils.write(content, fileOutputStream); fileOutputStream.flush(); fileOutputStream.close(); } catch (Exception e) { logger.log(Level.SEVERE, String.format("Failed to create user file %s", answerFile.getPath()), e); throw new IOException("Failed to store file data", e); } }

Target:
public void storeFileToFileSystem(Long userEntityId, String fileId, byte[] content) throws IOException { if (userEntityId == null || fileId == null || content == null) { logger.severe(String.format("Invalid store parameters or no file content: file %s of user %d", fileId, userEntityId)); throw new IllegalArgumentException("Invalid store parameters"); } SystemSetting fileFolderSetting = systemSettingDAO.findByKey(SETTING_FILEFOLDER); if (fileFolderSetting == null || StringUtils.isBlank(fileFolderSetting.getValue())) { throw new IOException("File answer storage folder not set"); } java.io.File fileFolder = Paths.get(fileFolderSetting.getValue()).toFile(); if (!fileFolder.exists() || !fileFolder.isDirectory()) { throw new IOException(String.format("File answer storage folder %s is not a directory", fileFolderSetting.getValue())); } java.io.File userFolder = Paths.get(fileFolder.getPath(), userEntityId.toString()).toFile(); if (!userFolder.exists()) { logger.info(String.format("Creating user file folder %s", userFolder.getPath())); if (!userFolder.mkdir()) { throw new IOException(String.format("Failed to create user file folder %s", userFolder.getPath())); } } java.io.File answerFile = Paths.get(userFolder.getPath(), fileId).toFile(); if (answerFile.exists()) { throw new IOException(String.format("User file %s already exists", answerFile.getPath())); } FileOutputStream fileOutputStream = null; try { fileOutputStream = new FileOutputStream(answerFile); IOUtils.write(content, fileOutputStream); fileOutputStream.flush(); fileOutputStream.close(); } catch (Exception e) { logger.log(Level.SEVERE, String.format("Failed to create user file %s", answerFile.getPath()), e); throw new IOException("Failed to store file data", e); } }