Return-Path: Delivered-To: apmail-harmony-commits-archive@www.apache.org Received: (qmail 44773 invoked from network); 13 Sep 2009 20:23:19 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 13 Sep 2009 20:23:19 -0000 Received: (qmail 51532 invoked by uid 500); 13 Sep 2009 20:23:19 -0000 Delivered-To: apmail-harmony-commits-archive@harmony.apache.org Received: (qmail 51452 invoked by uid 500); 13 Sep 2009 20:23:18 -0000 Mailing-List: contact commits-help@harmony.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@harmony.apache.org Delivered-To: mailing list commits@harmony.apache.org Received: (qmail 51443 invoked by uid 99); 13 Sep 2009 20:23:18 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 13 Sep 2009 20:23:18 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 13 Sep 2009 20:23:08 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 33B4E23888FD; Sun, 13 Sep 2009 20:22:48 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r814380 - in /harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io: DataOutputStream.java ObjectOutputStream.java Date: Sun, 13 Sep 2009 20:22:48 -0000 To: commits@harmony.apache.org From: hindessm@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090913202248.33B4E23888FD@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: hindessm Date: Sun Sep 13 20:22:47 2009 New Revision: 814380 URL: http://svn.apache.org/viewvc?rev=814380&view=rev Log: Match behaviour of RI (and fix instability in java6 jdwp tests) by combining write operations. See http://markmail.org/thread/d5t2p24imcqw62xz Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/DataOutputStream.java harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectOutputStream.java Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/DataOutputStream.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/DataOutputStream.java?rev=814380&r1=814379&r2=814380&view=diff ============================================================================== --- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/DataOutputStream.java (original) +++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/DataOutputStream.java Sun Sep 13 20:22:47 2009 @@ -277,6 +277,19 @@ written += 8; } + int writeLongToBuffer(long val, + byte[] buffer, int offset) throws IOException { + buff[offset++] = (byte) (val >> 56); + buff[offset++] = (byte) (val >> 48); + buff[offset++] = (byte) (val >> 40); + buff[offset++] = (byte) (val >> 32); + buff[offset++] = (byte) (val >> 24); + buff[offset++] = (byte) (val >> 16); + buff[offset++] = (byte) (val >> 8); + buff[offset++] = (byte) val; + return offset; + } + /** * Writes the specified 16-bit short to the target stream. Only the lower * two bytes of the integer {@code val} are written, with the higher one @@ -296,6 +309,13 @@ written += 2; } + int writeShortToBuffer(int val, + byte[] buffer, int offset) throws IOException { + buffer[offset++] = (byte) (val >> 8); + buffer[offset++] = (byte) val; + return offset; + } + /** * Writes the specified encoded in {@link DataInput modified UTF-8} to this * stream. @@ -314,8 +334,11 @@ if (utfCount > 65535) { throw new UTFDataFormatException(Msg.getString("K0068")); //$NON-NLS-1$ } - writeShort((int) utfCount); - writeUTFBytes(str, utfCount); + byte[] buffer = new byte[(int)utfCount + 2]; + int offset = 0; + offset = writeShortToBuffer((int) utfCount, buffer, offset); + offset = writeUTFBytesToBuffer(str, (int) utfCount, buffer, offset); + write(buffer, 0, offset); } long countUTFBytes(String str) { @@ -333,24 +356,22 @@ return utfCount; } - void writeUTFBytes(String str, long count) throws IOException { - int size = (int) count; + int writeUTFBytesToBuffer(String str, long count, + byte[] buffer, int offset) throws IOException { int length = str.length(); - byte[] utfBytes = new byte[size]; - int utfIndex = 0; for (int i = 0; i < length; i++) { int charValue = str.charAt(i); if (charValue > 0 && charValue <= 127) { - utfBytes[utfIndex++] = (byte) charValue; + buffer[offset++] = (byte) charValue; } else if (charValue <= 2047) { - utfBytes[utfIndex++] = (byte) (0xc0 | (0x1f & (charValue >> 6))); - utfBytes[utfIndex++] = (byte) (0x80 | (0x3f & charValue)); + buffer[offset++] = (byte) (0xc0 | (0x1f & (charValue >> 6))); + buffer[offset++] = (byte) (0x80 | (0x3f & charValue)); } else { - utfBytes[utfIndex++] = (byte) (0xe0 | (0x0f & (charValue >> 12))); - utfBytes[utfIndex++] = (byte) (0x80 | (0x3f & (charValue >> 6))); - utfBytes[utfIndex++] = (byte) (0x80 | (0x3f & charValue)); + buffer[offset++] = (byte) (0xe0 | (0x0f & (charValue >> 12))); + buffer[offset++] = (byte) (0x80 | (0x3f & (charValue >> 6))); + buffer[offset++] = (byte) (0x80 | (0x3f & charValue)); } } - write(utfBytes, 0, utfIndex); + return offset; } } Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectOutputStream.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectOutputStream.java?rev=814380&r1=814379&r2=814380&view=diff ============================================================================== --- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectOutputStream.java (original) +++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectOutputStream.java Sun Sep 13 20:22:47 2009 @@ -1555,15 +1555,20 @@ private Integer writeNewString(String object, boolean unshared) throws IOException { long count = output.countUTFBytes(object); + byte[] buffer; + int offset = 0; if (count <= 0xffff) { - output.writeByte(TC_STRING); - output.writeShort((short) count); + buffer = new byte[(int)count+3]; + buffer[offset++] = TC_STRING; + offset = output.writeShortToBuffer((short) count, buffer, offset); } else { - output.writeByte(TC_LONGSTRING); - output.writeLong(count); + buffer = new byte[(int)count+9]; + buffer[offset++] = TC_LONGSTRING; + offset = output.writeLongToBuffer(count, buffer, offset); } - output.writeUTFBytes(object, count); - + offset = output.writeUTFBytesToBuffer(object, count, buffer, offset); + output.write(buffer, 0, offset); + Integer handle = nextHandle(); if (!unshared) {