public void writeFile(Exchange exchange, String fileName) throws GenericFileOperationFailedException { // build directory if auto create is enabled if (endpoint.isAutoCreate()) { // we must normalize it (to avoid having both \ and / in the name which confuses java.io.File) String name = FileUtil.normalizePath(fileName); // use java.io.File to compute the file path File file = new File(name); String directory = file.getParent(); boolean absolute = FileUtil.isAbsolute(file); if (directory != null) { if (!operations.buildDirectory(directory, absolute)) { log.debug( "Cannot build directory [{}] (could be because of denied permissions)", directory); } } } // upload if (log.isTraceEnabled()) { log.trace( "About to write [{}] to [{}] from exchange [{}]", new Object[] {fileName, getEndpoint(), exchange}); } boolean success = operations.storeFile(fileName, exchange); if (!success) { throw new GenericFileOperationFailedException("Error writing file [" + fileName + "]"); } log.debug("Wrote [{}] to [{}]", fileName, getEndpoint()); }
/** * Creates the associated name of the done file based on the given file name. * * <p>This method should only be invoked if a done filename property has been set on this * endpoint. * * @param fileName the file name * @return name of the associated done file name */ protected String createDoneFileName(String fileName) { String pattern = getDoneFileName(); ObjectHelper.notEmpty(pattern, "doneFileName", pattern); // we only support ${file:name} or ${file:name.noext} as dynamic placeholders for done files String path = FileUtil.onlyPath(fileName); String onlyName = FileUtil.stripPath(fileName); pattern = pattern.replaceFirst("\\$\\{file:name\\}", onlyName); pattern = pattern.replaceFirst("\\$simple\\{file:name\\}", onlyName); pattern = pattern.replaceFirst("\\$\\{file:name.noext\\}", FileUtil.stripExt(onlyName)); pattern = pattern.replaceFirst("\\$simple\\{file:name.noext\\}", FileUtil.stripExt(onlyName)); // must be able to resolve all placeholders supported if (SimpleLanguage.hasStartToken(pattern)) { throw new ExpressionIllegalSyntaxException( fileName + ". Cannot resolve reminder: " + pattern); } String answer = pattern; if (ObjectHelper.isNotEmpty(path) && ObjectHelper.isNotEmpty(pattern)) { // done file must always be in same directory as the real file name answer = path + File.separator + pattern; } if (getConfiguration().needToNormalize()) { // must normalize path to cater for Windows and other OS answer = FileUtil.normalizePath(answer); } return answer; }
public String normalizePath(String name) { return FileUtil.normalizePath(name); }