harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hinde...@apache.org
Subject svn commit: r979963 - in /harmony/enhanced/java/branches/java6: ./ classlib/ classlib/depends/libs/ classlib/modules/luni/src/main/java/java/io/ classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/ classlib/modules/nio_char/...
Date Wed, 28 Jul 2010 06:59:41 GMT
Author: hindessm
Date: Wed Jul 28 06:59:41 2010
New Revision: 979963

URL: http://svn.apache.org/viewvc?rev=979963&view=rev
Log:
Merge change from /harmony/enhanced/java/trunk@979647:

  r979647 | tellison | 2010-07-27 12:31:30 +0100 (Tue, 27 Jul 2010) | 4 lines
  
  Apply modified patches for 
  HARMONY-6590 ([classlib][luni]A issue about CharsetEncoder.flush() in the OutputStreamWriter.close())
  HARMONY-6594 ([classlib][nio_char] CharsetEncoder.flush(Bytebuffer) doesn't follow the spec
and RI's behavior)
  


Modified:
    harmony/enhanced/java/branches/java6/   (props changed)
    harmony/enhanced/java/branches/java6/classlib/   (props changed)
    harmony/enhanced/java/branches/java6/classlib/depends/libs/   (props changed)
    harmony/enhanced/java/branches/java6/classlib/modules/luni/src/main/java/java/io/OutputStreamWriter.java
    harmony/enhanced/java/branches/java6/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/BufferedWriterTest.java
    harmony/enhanced/java/branches/java6/classlib/modules/nio_char/src/main/java/java/nio/charset/CharsetEncoder.java
    harmony/enhanced/java/branches/java6/classlib/modules/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/ASCIICharsetEncoderTest.java
    harmony/enhanced/java/branches/java6/classlib/modules/nio_char/src/test/java/tests/api/java/nio/charset/CharsetEncoderTest.java
    harmony/enhanced/java/branches/java6/drlvm/   (props changed)
    harmony/enhanced/java/branches/java6/jdktools/   (props changed)

Propchange: harmony/enhanced/java/branches/java6/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Jul 28 06:59:41 2010
@@ -1,4 +1,4 @@
 /harmony/enhanced/java/branches/mrh:935751-941490
-/harmony/enhanced/java/trunk:929253-979569,979593,979613,979615,979659
+/harmony/enhanced/java/trunk:929253-979569,979593,979613,979615,979647,979659
 /harmony/enhanced/trunk:476395-929252
 /incubator/harmony/enhanced/trunk:292550-476394

Propchange: harmony/enhanced/java/branches/java6/classlib/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Jul 28 06:59:41 2010
@@ -1,7 +1,7 @@
 /harmony/enhanced/classlib/trunk:713674-735919,765923-926091,926318-926838
 /harmony/enhanced/classlib/trunk/working_classlib:884014-884286
 /harmony/enhanced/java/branches/mrh/classlib:935751-941490
-/harmony/enhanced/java/trunk/classlib:929253-979569,979593,979613,979615,979659
+/harmony/enhanced/java/trunk/classlib:929253-979569,979593,979613,979615,979647,979659
 /harmony/enhanced/trunk/classlib:476395-929252
 /harmony/enhanced/trunk/working_classlib:476396-920147
 /incubator/harmony/enhanced/trunk/classlib:292550-476394

Propchange: harmony/enhanced/java/branches/java6/classlib/depends/libs/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Jul 28 06:59:41 2010
@@ -1,4 +1,4 @@
 /harmony/enhanced/classlib/trunk/depends/libs:544451-926091
-/harmony/enhanced/java/trunk/classlib/depends/libs:929253-979569,979593,979613,979615,979659
+/harmony/enhanced/java/trunk/classlib/depends/libs:929253-979569,979593,979613,979615,979647,979659
 /harmony/enhanced/trunk/classlib/depends/libs:476395-929252
 /incubator/harmony/enhanced/trunk/classlib/depends/libs:292550-476394

Modified: harmony/enhanced/java/branches/java6/classlib/modules/luni/src/main/java/java/io/OutputStreamWriter.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/java6/classlib/modules/luni/src/main/java/java/io/OutputStreamWriter.java?rev=979963&r1=979962&r2=979963&view=diff
==============================================================================
--- harmony/enhanced/java/branches/java6/classlib/modules/luni/src/main/java/java/io/OutputStreamWriter.java
(original)
+++ harmony/enhanced/java/branches/java6/classlib/modules/luni/src/main/java/java/io/OutputStreamWriter.java
Wed Jul 28 06:59:41 2010
@@ -47,6 +47,8 @@ public class OutputStreamWriter extends 
 
     private ByteBuffer bytes = ByteBuffer.allocate(8192);
 
+    private boolean encoderFlush = false;
+
     /**
      * Constructs a new OutputStreamWriter using {@code out} as the target
      * stream to write converted characters to. The default character encoding
@@ -147,7 +149,18 @@ public class OutputStreamWriter extends 
     public void close() throws IOException {
         synchronized (lock) {
             if (encoder != null) {
-                encoder.flush(bytes);
+                if (encoderFlush) {
+                    CoderResult result = encoder.flush(bytes);
+                    while (!result.isUnderflow()) {
+                        if (result.isOverflow()) {
+                            flush();
+                            result = encoder.flush(bytes);
+                        } else {
+                            result.throwException();
+                        }
+                    }
+                }
+
                 flush();
                 out.flush();
                 out.close();
@@ -234,6 +247,7 @@ public class OutputStreamWriter extends 
 
     private void convert(CharBuffer chars) throws IOException {
         CoderResult result = encoder.encode(chars, bytes, true);
+        encoderFlush = true;
         while (true) {
             if (result.isError()) {
                 throw new IOException(result.toString());

Modified: harmony/enhanced/java/branches/java6/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/BufferedWriterTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/java6/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/BufferedWriterTest.java?rev=979963&r1=979962&r2=979963&view=diff
==============================================================================
--- harmony/enhanced/java/branches/java6/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/BufferedWriterTest.java
(original)
+++ harmony/enhanced/java/branches/java6/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/BufferedWriterTest.java
Wed Jul 28 06:59:41 2010
@@ -18,7 +18,9 @@
 package org.apache.harmony.luni.tests.java.io;
 
 import java.io.BufferedWriter;
+import java.io.ByteArrayOutputStream;
 import java.io.IOException;
+import java.io.OutputStreamWriter;
 import java.io.Writer;
 
 import tests.support.Support_StringWriter;
@@ -103,6 +105,16 @@ public class BufferedWriterTest extends 
         assertEquals("BufferdWriter do not flush itself before close", "a", mw
                 .getWritten());
     }
+    
+    /**
+     * @throws IOException 
+     * @tests java.io.BufferedWriter#close()
+     *
+     */
+    public void test_close2() throws IOException {
+        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new ByteArrayOutputStream()));
+            bw.close();
+    }
 
     /**
      * @tests java.io.BufferedWriter#flush()

Modified: harmony/enhanced/java/branches/java6/classlib/modules/nio_char/src/main/java/java/nio/charset/CharsetEncoder.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/java6/classlib/modules/nio_char/src/main/java/java/nio/charset/CharsetEncoder.java?rev=979963&r1=979962&r2=979963&view=diff
==============================================================================
--- harmony/enhanced/java/branches/java6/classlib/modules/nio_char/src/main/java/java/nio/charset/CharsetEncoder.java
(original)
+++ harmony/enhanced/java/branches/java6/classlib/modules/nio_char/src/main/java/java/nio/charset/CharsetEncoder.java
Wed Jul 28 06:59:41 2010
@@ -88,7 +88,7 @@ public abstract class CharsetEncoder {
     /*
      * internal status consts
      */
-    private static final int INIT = 0;
+    private static final int READY = 0;
 
     private static final int ONGOING = 1;
 
@@ -96,6 +96,8 @@ public abstract class CharsetEncoder {
 
     private static final int FLUSH = 3;
 
+    private static final int INIT = 4;
+
     // the Charset which creates this encoder
     private Charset cs;
 
@@ -111,6 +113,9 @@ public abstract class CharsetEncoder {
     // internal status
     private int status;
 
+    // internal status indicates encode(CharBuffer) operation is finished
+    private boolean finished;
+
     // action for malformed input
     private CodingErrorAction malformAction;
 
@@ -217,10 +222,10 @@ public abstract class CharsetEncoder {
 
     // implementation of canEncode
     private boolean implCanEncode(CharBuffer cb) {
-        if (status == FLUSH) {
-            status = INIT;
+        if (status == FLUSH || status == INIT) {
+            status = READY;
         }
-        if (status != INIT) {
+        if (status != READY) {
             // niochar.0B=Another encoding process is ongoing\!
             throw new IllegalStateException(Messages.getString("niochar.0B")); //$NON-NLS-1$
         }
@@ -347,7 +352,8 @@ public abstract class CharsetEncoder {
             }
             break;
         }
-        status = FLUSH;
+        status = READY;
+        finished = true;
         return output;
     }
 
@@ -438,6 +444,12 @@ public abstract class CharsetEncoder {
      */
     public final CoderResult encode(CharBuffer in, ByteBuffer out,
             boolean endOfInput) {
+        //If the previous step is encode(CharBuffer), then no more input is needed
+        // thus endOfInput should not be false
+        if (status == READY && finished && !endOfInput) {
+            throw new IllegalStateException();
+        }
+
         if ((status == FLUSH) || (!endOfInput && status == END)) {
             throw new IllegalStateException();
         }
@@ -553,7 +565,7 @@ public abstract class CharsetEncoder {
      *             for the last boolean parameter.
      */
     public final CoderResult flush(ByteBuffer out) {
-        if (status != END && status != INIT) {
+        if (status != END && status != READY) {
             throw new IllegalStateException();
         }
         CoderResult result = implFlush(out);

Modified: harmony/enhanced/java/branches/java6/classlib/modules/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/ASCIICharsetEncoderTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/java6/classlib/modules/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/ASCIICharsetEncoderTest.java?rev=979963&r1=979962&r2=979963&view=diff
==============================================================================
--- harmony/enhanced/java/branches/java6/classlib/modules/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/ASCIICharsetEncoderTest.java
(original)
+++ harmony/enhanced/java/branches/java6/classlib/modules/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/ASCIICharsetEncoderTest.java
Wed Jul 28 06:59:41 2010
@@ -290,20 +290,31 @@ public class ASCIICharsetEncoderTest ext
     public void testInternalState_Flushed() {
         CharsetEncoder newEncoder = cs.newEncoder();
         
-        //init -> flushed
-        {
-            ByteBuffer out = ByteBuffer.allocate(0x10);
-            newEncoder.flush(out);
-        }
-        
-        //reset - > flushed
+        // init -> flushed
+		{
+			ByteBuffer out = ByteBuffer.allocate(0x10);
+			try {
+				newEncoder.flush(out);
+				fail("Should throw IllegalStateException");
+			} catch (IllegalStateException e) {
+				//expected
+			}
+
+		}
+
+        // reset - > flushed
         {
             newEncoder.reset();
             CharBuffer in = CharBuffer.wrap("A");
             ByteBuffer out = ByteBuffer.allocate(0x10);
             newEncoder.encode(in, out, true);
             newEncoder.reset();
-            newEncoder.flush(out);
+            try {
+                newEncoder.flush(out);
+				fail("Should throw IllegalStateException");
+            } catch (IllegalStateException e) {
+                //expected
+            }
         }
         
         //encoding - > flushed
@@ -421,23 +432,14 @@ public class ASCIICharsetEncoderTest ext
             CharBuffer in = CharBuffer.wrap("A");
             newEncoder.encode(in);
             ByteBuffer out = ByteBuffer.allocate(0x10);
-            try {
-                newEncoder.encode(in, out, true);
-                fail("Should throw IllegalStateException");
-            } catch (IllegalStateException e) {
-                // expected
-            }
+            newEncoder.encode(in, out, true);
         }
+
         //Encode -> Flushed
         {
             CharBuffer in = CharBuffer.wrap("A");
             ByteBuffer out = newEncoder.encode(in);
-            try {
-                newEncoder.flush(out);
-                fail("Should throw IllegalStateException");
-            } catch (IllegalStateException e) {
-                // expected
-            }
+            newEncoder.flush(out);
         }
         
         //Encode - > encode

Modified: harmony/enhanced/java/branches/java6/classlib/modules/nio_char/src/test/java/tests/api/java/nio/charset/CharsetEncoderTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/java6/classlib/modules/nio_char/src/test/java/tests/api/java/nio/charset/CharsetEncoderTest.java?rev=979963&r1=979962&r2=979963&view=diff
==============================================================================
--- harmony/enhanced/java/branches/java6/classlib/modules/nio_char/src/test/java/tests/api/java/nio/charset/CharsetEncoderTest.java
(original)
+++ harmony/enhanced/java/branches/java6/classlib/modules/nio_char/src/test/java/tests/api/java/nio/charset/CharsetEncoderTest.java
Wed Jul 28 06:59:41 2010
@@ -296,6 +296,7 @@ public class CharsetEncoderTest extends 
 			encoder.flush(out);
 			fail("should throw IllegalStateException");
 		} catch (IllegalStateException e) {
+		    // Expected
 		}
 
 		// Illegal state: flush after encode with endOfInput is false
@@ -305,8 +306,22 @@ public class CharsetEncoderTest extends 
 			encoder.flush(out);
 			fail("should throw IllegalStateException");
 		} catch (IllegalStateException e) {
+		    // Expected
 		}
 	}
+	
+	public void testFlushAfterConstructing() {
+		ByteBuffer out = ByteBuffer.allocate(5);
+		
+		//Illegal state: flush after instance created
+		try {
+			encoder.flush(out);			
+			fail("should throw IllegalStateException");
+		} catch (IllegalStateException e) {
+			// Expected
+		}
+
+	}
 
 	// test illegal states for encode facade
 	public void testEncodeFacadeIllegalState() throws CharacterCodingException {

Propchange: harmony/enhanced/java/branches/java6/drlvm/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Jul 28 06:59:41 2010
@@ -1,5 +1,5 @@
 /harmony/enhanced/java/branches/mrh/drlvm:935751-941490
-/harmony/enhanced/java/trunk/drlvm:929253-979569,979593,979613,979615,979659
+/harmony/enhanced/java/trunk/drlvm:929253-979569,979593,979613,979615,979647,979659
 /harmony/enhanced/trunk/drlvm:476395-929252
 /harmony/enhanced/trunk/working_vm:476396-920147
 /incubator/harmony/enhanced/trunk/drlvm:292550-476394

Propchange: harmony/enhanced/java/branches/java6/jdktools/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Jul 28 06:59:41 2010
@@ -1,4 +1,4 @@
-/harmony/enhanced/java/trunk/jdktools:929253-979569,979593,979613,979615,979659
+/harmony/enhanced/java/trunk/jdktools:929253-979569,979593,979613,979615,979647,979659
 /harmony/enhanced/jdktools/trunk:630107-925933
 /harmony/enhanced/trunk/jdktools:476395-929252
 /harmony/enhanced/trunk/working_jdktools:476396-920147



Mime
View raw message