Return-Path: Delivered-To: apmail-incubator-harmony-dev-archive@www.apache.org Received: (qmail 48529 invoked from network); 18 Sep 2006 10:22:27 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 18 Sep 2006 10:22:27 -0000 Received: (qmail 97143 invoked by uid 500); 18 Sep 2006 10:22:23 -0000 Delivered-To: apmail-incubator-harmony-dev-archive@incubator.apache.org Received: (qmail 97101 invoked by uid 500); 18 Sep 2006 10:22:23 -0000 Mailing-List: contact harmony-dev-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: harmony-dev@incubator.apache.org Delivered-To: mailing list harmony-dev@incubator.apache.org Received: (qmail 97090 invoked by uid 99); 18 Sep 2006 10:22:23 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 18 Sep 2006 03:22:23 -0700 X-ASF-Spam-Status: No, hits=0.5 required=10.0 tests=DNS_FROM_RFC_ABUSE,HTML_MESSAGE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: domain of zhanghuangzhu@gmail.com designates 66.249.82.225 as permitted sender) Received: from [66.249.82.225] (HELO wx-out-0506.google.com) (66.249.82.225) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 18 Sep 2006 03:22:11 -0700 Received: by wx-out-0506.google.com with SMTP id s13so3893052wxc for ; Mon, 18 Sep 2006 03:21:25 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:references; b=RQrntqGwNjeBOwU3LG3Pf2n6V4xgORNQ8GSH2UJl2WA41118vXKtS5okEStAGiQKP03KdrSnMyBVpvuY+f11YGKaYUXfYCY8EILZleW7pw5DmZ5VSN2H7mam9MSGSDb/3miaVQRYFfm5FmuSJMuFWUdcGcH2iI65foDUYU7KuSI= Received: by 10.70.32.6 with SMTP id f6mr19893894wxf; Mon, 18 Sep 2006 03:21:23 -0700 (PDT) Received: by 10.70.123.4 with HTTP; Mon, 18 Sep 2006 03:21:23 -0700 (PDT) Message-ID: <4d0b24970609180321m28c15d83m3942242bf24d1328@mail.gmail.com> Date: Mon, 18 Sep 2006 18:21:23 +0800 From: "Andrew Zhang" To: harmony-dev@incubator.apache.org Subject: Re: [classlib][io][nio] Sync issue of java.io.FileOutputStream and java.nio.channels.FileChannel In-Reply-To: MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_35960_3493703.1158574883745" References: X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N ------=_Part_35960_3493703.1158574883745 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline On 9/18/06, Richard Liang wrote: > > Hello, > > One Apache Derby test[1] fails on Harmony. It seems that RI always > sync the FileOutputStream and FileChannel after each "write", which is > different from Harmony. But there is no explicit description in Java > Spec. Shall we follow RI? Thanks a lot. > > The following test cases could demonstrate this issue. > > public void testFile() { > File derbyLog = new File("d:\\", "derby1.log"); > > try { > FileOutputStream fos = new FileOutputStream(derbyLog); > fos.write(0x41); > assertEquals(1, derbyLog.length()); > } catch (Exception e) { > e.printStackTrace(); > } > } > > public void testFileChannel() { > File derbyLog = new File("d:\\", "derby2.log"); > > try { > FileOutputStream fos = new FileOutputStream(derbyLog); > FileChannel fc = fos.getChannel(); > fc.write(ByteBuffer.wrap(new byte[]{0x41, 0x42})); > assertEquals(2, derbyLog.length()); > } catch (Exception e) { > e.printStackTrace(); > } > } Interesting. I think we'd better follow RI although it's implementation dependent. Otherwise, it breaks existing application. To make test more interesting, I wrote a similar test: public void testFile() throws Exception { File derbyLog = File.createTempFile("test", "log"); derbyLog.deleteOnExit(); RandomAccessFile fos = new RandomAccessFile(derbyLog, "rws"); for (int i = 0; i < 1000; i++) { fos.write(0x41); assertEquals(1 + i, derbyLog.length()); } } Run it and you'll be surprised. :-) [1] > http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/logStream.java?view=co > -- > Richard Liang > China Development Lab, IBM > > --------------------------------------------------------------------- > Terms of use : http://incubator.apache.org/harmony/mailing.html > To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org > For additional commands, e-mail: harmony-dev-help@incubator.apache.org > > -- Andrew Zhang China Software Development Lab, IBM ------=_Part_35960_3493703.1158574883745--