title: Spring integration File - reading the file by inbound channel adapter before it gets written
body: <p>I am testing the <a href="https://github.com/SpringSource/spring-integration-samples/tree/master/basic/file" rel="nofollow">SI sample</a> and I am encountering the following issue.</p>
  
  <p>My SI ver-1.0.4</p>
  
  <p>For easier understanding I am pasting the contents below:</p>
  
  <p><strong>fileCopyDemo-text.xml</strong>
          </p>
  
  <pre><code>    &lt;file:inbound-channel-adapter id="filesIn"
                                    directory="file:${java.io.tmpdir}/spring-integration-samples/input" filename-pattern=".*\.xml"&gt;
          &lt;integration:poller id="poller" &gt;
              &lt;integration:interval-trigger initial-delay="1000" interval="2000" fixed-rate="true"/&gt;
          &lt;/integration:poller&gt;
      &lt;/file:inbound-channel-adapter&gt;
  
      &lt;integration:service-activator input-channel="filesIn"
                                     output-channel="filesOut"
                                     ref="handler"/&gt;
  
      &lt;file:outbound-channel-adapter id="filesOut"
                                     directory="file:${java.io.tmpdir}/spring-integration-samples/output"
                                     delete-source-files="true"/&gt;
  
      &lt;bean id="handler" class="org.springframework.integration.samples.filecopy.Handler"/&gt;
  </code></pre>
  
  <p><strong>FileBasedCopyTest.java</strong></p>
  
  <pre><code>public class FileBasedFileCopyTest {
  
      public static void main(String[] args)
      {
          ApplicationContext ac = new ClassPathXmlApplicationContext("/META-INF/spring/integration/fileCopyDemo-file.xml");
      }
  }
  </code></pre>
  
  <p><strong>Handler.java</strong></p>
  
  <pre><code>public class Handler {
  
      public File handleFile(File input) {
          System.out.println("Copying file: " + input.getAbsolutePath());
          return input;
      }
  }
  </code></pre>
  
  <p>I have another java class which is creating a file into the input folder.</p>
  
  <p><strong>Sample.java</strong></p>
  
  <pre><code>public static void main(String[] args) {
  
      try {
          String str = "SomeMoreTextIsHere";
          File newTextFile = new File("C:/Windows/Temp/spring-integration-samples/input/thetextfile.xml");
  
          FileWriter fw = new FileWriter(newTextFile);
          fw.write(str);
          fw.close();
  
      } catch (IOException iox) {
          iox.printStackTrace();
      }
  }
  </code></pre>
  
  <p>I have run the FileBasedCopyTest and it is now listening to input folder.</p>
  
  <p><strong>Question</strong>
  I am running the Sample.java file in debug mode and the momemt </p>
  
  <blockquote>
    <p>FileWriter fw = new FileWriter(newTextFile);</p>
  </blockquote>
  
  <p>is executed I am receiving the control in Handler.java, ideally I wanted to receive the control once the file is closed. How to handle this scenario?</p>
  
  <p>PS : I have also read <a href="http://static.springsource.org/spring-integration/docs/1.0.x/spring-integration-reference/htmlsingle/spring-integration-reference.html#files" rel="nofollow">this</a> but not sure in this case how to handle here.</p>