Source:
protected Object handleRequestMessage(Message<?> requestMessage) { Assert.notNull(requestMessage, "message must not be null"); Object payload = requestMessage.getPayload(); Assert.notNull(payload, "message payload must not be null"); String generatedFileName = this.fileNameGenerator.generateFileName(requestMessage); File originalFileFromHeader = retrieveOriginalFileFromHeader(requestMessage); final File destinationDirectoryToUse = evaluateDestinationDirectoryExpression(requestMessage); File tempFile = new File(destinationDirectoryToUse, generatedFileName + this.temporaryFileSuffix); File resultFile = new File(destinationDirectoryToUse, generatedFileName); if (FileExistsMode.FAIL.equals(this.fileExistsMode) && resultFile.exists()) { throw new MessageHandlingException(requestMessage, "The destination file already exists at '" + resultFile.getAbsolutePath() + "'."); } final boolean ignore = FileExistsMode.IGNORE.equals(this.fileExistsMode) && (resultFile.exists() || (StringUtils.hasText(this.temporaryFileSuffix) && tempFile.exists())); if (!ignore) { try { if (!resultFile.exists()) { tempFile.getParentFile().mkdirs(); resultFile.getParentFile().mkdirs(); } if (payload instanceof File) { resultFile = handleFileMessage((File) payload, tempFile, resultFile); } else if (payload instanceof InputStream) { resultFile = handleInputStreamMessage((InputStream) payload, originalFileFromHeader, tempFile, resultFile); } else if (payload instanceof byte[]) { resultFile = this.handleByteArrayMessage( (byte[]) payload, originalFileFromHeader, tempFile, resultFile); } else if (payload instanceof String) { resultFile = this.handleStringMessage( (String) payload, originalFileFromHeader, tempFile, resultFile); } else { throw new IllegalArgumentException( "unsupported Message payload type [" + payload.getClass().getName() + "]"); } } catch (Exception e) { throw new MessageHandlingException(requestMessage, "failed to write Message payload to file", e); } } if (!this.expectReply) { return null; } if (resultFile != null) { if (originalFileFromHeader == null && payload instanceof File) { return this.getMessageBuilderFactory().withPayload(resultFile) .setHeader(FileHeaders.ORIGINAL_FILE, payload); } } return resultFile; }

Target:
protected Object handleRequestMessage(Message<?> requestMessage) { Assert.notNull(requestMessage, "message must not be null"); Object payload = requestMessage.getPayload(); Assert.notNull(payload, "message payload must not be null"); String generatedFileName = this.fileNameGenerator.generateFileName(requestMessage); File originalFileFromHeader = retrieveOriginalFileFromHeader(requestMessage); final File destinationDirectoryToUse = evaluateDestinationDirectoryExpression(requestMessage); File tempFile = new File(destinationDirectoryToUse, generatedFileName + this.temporaryFileSuffix); File resultFile = new File(destinationDirectoryToUse, generatedFileName); if (FileExistsMode.FAIL.equals(this.fileExistsMode) && resultFile.exists()) { throw new MessageHandlingException(requestMessage, "The destination file already exists at '" + resultFile.getAbsolutePath() + "'."); } final boolean ignore = FileExistsMode.IGNORE.equals(this.fileExistsMode) && (resultFile.exists() || (StringUtils.hasText(this.temporaryFileSuffix) && tempFile.exists())); if (!ignore) { try { if (!resultFile.exists() && generatedFileName.replaceAll("/", Matcher.quoteReplacement(File.separator)) .contains(File.separator)) { resultFile.getParentFile().mkdirs(); } if (payload instanceof File) { resultFile = handleFileMessage((File) payload, tempFile, resultFile); } else if (payload instanceof InputStream) { resultFile = handleInputStreamMessage((InputStream) payload, originalFileFromHeader, tempFile, resultFile); } else if (payload instanceof byte[]) { resultFile = this.handleByteArrayMessage( (byte[]) payload, originalFileFromHeader, tempFile, resultFile); } else if (payload instanceof String) { resultFile = this.handleStringMessage( (String) payload, originalFileFromHeader, tempFile, resultFile); } else { throw new IllegalArgumentException( "unsupported Message payload type [" + payload.getClass().getName() + "]"); } } catch (Exception e) { throw new MessageHandlingException(requestMessage, "failed to write Message payload to file", e); } } if (!this.expectReply) { return null; } if (resultFile != null) { if (originalFileFromHeader == null && payload instanceof File) { return this.getMessageBuilderFactory().withPayload(resultFile) .setHeader(FileHeaders.ORIGINAL_FILE, payload); } } return resultFile; }