camel-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Claus Ibsen (Resolved) (JIRA)" <j...@apache.org>
Subject [jira] [Resolved] (CAMEL-5136) File producer should support a flush attribute
Date Wed, 11 Apr 2012 05:50:52 GMT

     [ https://issues.apache.org/jira/browse/CAMEL-5136?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Claus Ibsen resolved CAMEL-5136.
--------------------------------

       Resolution: Fixed
    Fix Version/s:     (was: 2.8.5)
    
> File producer should support a flush attribute
> ----------------------------------------------
>
>                 Key: CAMEL-5136
>                 URL: https://issues.apache.org/jira/browse/CAMEL-5136
>             Project: Camel
>          Issue Type: Improvement
>          Components: camel-core
>    Affects Versions: 2.8.4, 2.9.1
>            Reporter: Jean-Baptiste Onofré
>            Assignee: Claus Ibsen
>             Fix For: 2.9.2, 2.10.0
>
>
> Currently, the file operation doesn't flush the file change while writing to the filesystem:
>     private void writeFileByFile(File source, File target) throws IOException {
>         FileChannel in = new FileInputStream(source).getChannel();
>         FileChannel out = null;
>         try {
>             out = prepareOutputFileChannel(target, out);
>             LOG.trace("Using FileChannel to transfer from: {} to: {}", in, out);
>             long size = in.size();
>             long position = 0;
>             while (position < size) {
>                 position += in.transferTo(position, endpoint.getBufferSize(), out);
>             }
>         } finally {
>             IOHelper.close(in, source.getName(), LOG);
>             IOHelper.close(out, target.getName(), LOG);
>         }
>     }
>     private void writeFileByStream(InputStream in, File target) throws IOException {
>         FileChannel out = null;
>         try {
>             out = prepareOutputFileChannel(target, out);
>             LOG.trace("Using InputStream to transfer from: {} to: {}", in, out);
>             int size = endpoint.getBufferSize();
>             byte[] buffer = new byte[size];
>             ByteBuffer byteBuffer = ByteBuffer.wrap(buffer);
>             int bytesRead;
>             while ((bytesRead = in.read(buffer)) != -1) {
>                 if (bytesRead < size) {
>                     byteBuffer.limit(bytesRead);
>                 }
>                 out.write(byteBuffer);
>                 byteBuffer.clear();
>             }
>         } finally {
>             IOHelper.close(in, target.getName(), LOG);
>             IOHelper.close(out, target.getName(), LOG);
>         }
>     }
> It means that the file can be visible on the filesystem quite a long time after starting
to send the exchanges to the file endpoint.
> It could be interesting to add a flush attribute doing:
>     FileOutputStream os = ...
>     FileDescriptor fd = os.getFD();
>     ...
>     os.write(data);
>     os.flush();
>     fd.sync();

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

Mime
View raw message