Return-Path: X-Original-To: apmail-camel-issues-archive@minotaur.apache.org Delivered-To: apmail-camel-issues-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id B40C59108 for ; Wed, 11 Apr 2012 05:14:53 +0000 (UTC) Received: (qmail 97385 invoked by uid 500); 11 Apr 2012 05:14:53 -0000 Delivered-To: apmail-camel-issues-archive@camel.apache.org Received: (qmail 97324 invoked by uid 500); 11 Apr 2012 05:14:52 -0000 Mailing-List: contact issues-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list issues@camel.apache.org Received: (qmail 97315 invoked by uid 99); 11 Apr 2012 05:14:52 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 11 Apr 2012 05:14:52 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED,T_RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.116] (HELO hel.zones.apache.org) (140.211.11.116) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 11 Apr 2012 05:14:49 +0000 Received: from hel.zones.apache.org (hel.zones.apache.org [140.211.11.116]) by hel.zones.apache.org (Postfix) with ESMTP id 4FC023640D5 for ; Wed, 11 Apr 2012 05:14:28 +0000 (UTC) Date: Wed, 11 Apr 2012 05:14:28 +0000 (UTC) From: "Claus Ibsen (Commented) (JIRA)" To: issues@camel.apache.org Message-ID: <1418064774.11068.1334121268540.JavaMail.tomcat@hel.zones.apache.org> In-Reply-To: <1053178219.432.1333373244360.JavaMail.tomcat@hel.zones.apache.org> Subject: [jira] [Commented] (CAMEL-5136) File producer should support a flush attribute MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/CAMEL-5136?page=3Dcom.atlassian= .jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=3D1325= 1323#comment-13251323 ]=20 Claus Ibsen commented on CAMEL-5136: ------------------------------------ We should use force on the file channel to flush the updates http://docs.oracle.com/javase/6/docs/api/java/nio/channels/FileChannel.html= #force(boolean) =20 > 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=C3=A9 > Assignee: Claus Ibsen > Fix For: 2.8.5, 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 IOExcep= tion { > FileChannel in =3D new FileInputStream(source).getChannel(); > FileChannel out =3D null; > try { > out =3D prepareOutputFileChannel(target, out); > LOG.trace("Using FileChannel to transfer from: {} to: {}", in= , out); > long size =3D in.size(); > long position =3D 0; > while (position < size) { > position +=3D in.transferTo(position, endpoint.getBufferS= ize(), out); > } > } finally { > IOHelper.close(in, source.getName(), LOG); > IOHelper.close(out, target.getName(), LOG); > } > } > private void writeFileByStream(InputStream in, File target) throws IO= Exception { > FileChannel out =3D null; > try { > out =3D prepareOutputFileChannel(target, out); > LOG.trace("Using InputStream to transfer from: {} to: {}", in= , out); > int size =3D endpoint.getBufferSize(); > byte[] buffer =3D new byte[size]; > ByteBuffer byteBuffer =3D ByteBuffer.wrap(buffer); > int bytesRead; > while ((bytesRead =3D in.read(buffer)) !=3D -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 =3D ... > FileDescriptor fd =3D 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 administrato= rs: https://issues.apache.org/jira/secure/ContactAdministrators!default.jsp= a For more information on JIRA, see: http://www.atlassian.com/software/jira