List of usage examples for org.springframework.integration.util WhileLockedProcessor doWhileLocked
public final void doWhileLocked() throws IOException
From source file:org.springframework.integration.file.FileWritingMessageHandler.java
private File handleFileMessage(final File sourceFile, File tempFile, final File resultFile) throws IOException { if (FileExistsMode.APPEND.equals(this.fileExistsMode)) { File fileToWriteTo = this.determineFileToWrite(resultFile, tempFile); final FileOutputStream fos = new FileOutputStream(fileToWriteTo, true); final FileInputStream fis = new FileInputStream(sourceFile); WhileLockedProcessor whileLockedProcessor = new WhileLockedProcessor(this.lockRegistry, fileToWriteTo.getAbsolutePath()) { @Override//from w ww .ja v a2 s.co m protected void whileLocked() throws IOException { FileCopyUtils.copy(fis, fos); } }; whileLockedProcessor.doWhileLocked(); this.cleanUpAfterCopy(fileToWriteTo, resultFile, sourceFile); return resultFile; } else { if (this.deleteSourceFiles) { if (sourceFile.renameTo(resultFile)) { return resultFile; } if (logger.isInfoEnabled()) { logger.info(String.format("Failed to move file '%s'. Using copy and delete fallback.", sourceFile.getAbsolutePath())); } } FileCopyUtils.copy(sourceFile, tempFile); this.cleanUpAfterCopy(tempFile, resultFile, sourceFile); return resultFile; } }
From source file:org.springframework.integration.file.FileWritingMessageHandler.java
private File handleByteArrayMessage(final byte[] bytes, File originalFile, File tempFile, final File resultFile) throws IOException { File fileToWriteTo = this.determineFileToWrite(resultFile, tempFile); final boolean append = FileExistsMode.APPEND.equals(this.fileExistsMode); final FileOutputStream fos = new FileOutputStream(fileToWriteTo, append); WhileLockedProcessor whileLockedProcessor = new WhileLockedProcessor(this.lockRegistry, fileToWriteTo.getAbsolutePath()) { @Override/* w w w. j a v a 2 s. co m*/ protected void whileLocked() throws IOException { FileCopyUtils.copy(bytes, fos); } }; whileLockedProcessor.doWhileLocked(); this.cleanUpAfterCopy(fileToWriteTo, resultFile, originalFile); return resultFile; }
From source file:org.springframework.integration.file.FileWritingMessageHandler.java
private File handleStringMessage(final String content, File originalFile, File tempFile, final File resultFile) throws IOException { File fileToWriteTo = this.determineFileToWrite(resultFile, tempFile); final boolean append = FileExistsMode.APPEND.equals(this.fileExistsMode); final OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(fileToWriteTo, append), this.charset); WhileLockedProcessor whileLockedProcessor = new WhileLockedProcessor(this.lockRegistry, fileToWriteTo.getAbsolutePath()) { @Override/* w w w . j a v a 2 s . c o m*/ protected void whileLocked() throws IOException { FileCopyUtils.copy(content, writer); } }; whileLockedProcessor.doWhileLocked(); this.cleanUpAfterCopy(fileToWriteTo, resultFile, originalFile); return resultFile; }