Page 3 of 3 FirstFirst 123
Results 21 to 26 of 26

Thread: file:outbound-channel-adapter : file extension ".writing" issue

  1. #21
    Join Date
    Aug 2009
    Location
    Paris, France
    Posts
    32

    Lightbulb

    Hi again,

    Sorry not coming with a full compiled test case, but i've looked at the source code in the spring-integration-file package, and i think the problem may come from that the rename function is not working, but its return value is not processed here :

    Code:
    private File handleFileMessage(File sourceFile, File tempFile, File resultFile) throws IOException {
    		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);
    		tempFile.renameTo(resultFile);
    		if (this.deleteSourceFiles) {
    			sourceFile.delete();
    		}
    		return resultFile;
    	}
    
    	private File handleByteArrayMessage(byte[] bytes, File originalFile, File tempFile, File resultFile) throws IOException {
    		FileCopyUtils.copy(bytes, tempFile);
    		tempFile.renameTo(resultFile);
    		if (this.deleteSourceFiles && originalFile != null) {
    			originalFile.delete();
    		}
    		return resultFile;
    	}
    
    	private File handleStringMessage(String content, File originalFile, File tempFile, File resultFile) throws IOException {
    		OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(tempFile), this.charset);
    		FileCopyUtils.copy(content, writer);
    		tempFile.renameTo(resultFile);
    		if (this.deleteSourceFiles && originalFile != null) {
    			originalFile.delete();
    		}
    		return resultFile;
    	}
    What about deleting src file first and then renaming the tempFile, if first rename failed (returned false) ?

    Thanks for your help

    Max

  2. #22
    Join Date
    Sep 2011
    Posts
    167

    Unhappy getting error in constructor attribute..!!

    have to see first ..!!

  3. #23
    Join Date
    Aug 2009
    Location
    Paris, France
    Posts
    32

    Default

    What do you wanna see ?

  4. #24
    Join Date
    Aug 2009
    Location
    Paris, France
    Posts
    32

    Default Solved like this

    Problem solved re-writing and subclassing FileWritingMessageHandler like follows :

    Code:
    @Override
    	protected File handleStringMessage(String content, File originalFile, File tempFile, File resultFile) throws IOException {
    		getLogger().debug("handling string message");
    		OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(tempFile), this.getCharset());
    		FileCopyUtils.copy(content, writer);
    		renameTo(tempFile, resultFile);
    		if (this.isDeleteSourceFiles() && originalFile != null) {
    			originalFile.delete();
    		}
    		return resultFile;
    	}
    
    
    
    	private void renameTo(File tempFile, File resultFile) {
    		if (resultFile != null && resultFile.exists())
    		{
    		resultFile.setWritable(true,false);
    		resultFile.delete();
    		if (!tempFile.renameTo(resultFile))
    			getLogger().debug("rename KO from " + tempFile.getAbsolutePath() + " to " + resultFile.getAbsolutePath());
    		}
    	else
    		{
    		if (!tempFile.renameTo(resultFile))
    			getLogger().debug("rename KO from " + tempFile.getAbsolutePath() + " to " + resultFile.getAbsolutePath());
    		
    		}
    	}
    Thanks for you help.

  5. #25
    Join Date
    Jan 2008
    Location
    Mohnton, PA USA (that's near Philadelphia)
    Posts
    2,148

    Default

    @munger

    Could you please rais a jIRA issue for that?

  6. #26
    Join Date
    Aug 2009
    Location
    Paris, France
    Posts
    32

    Default

    Done : INT-2278
    Thanks !

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •