You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by st...@apache.org on 2011/06/01 10:03:42 UTC

svn commit: r1130040 - in /maven/sandbox/trunk/plexus-utils-commons-bridge: plexus-utils-commons-bridge/src/main/java/org/codehaus/plexus/util/IOUtil.java plexus-utils-tck/src/test/java/org/codehaus/plexus/util/IOUtilTest.java

Author: stephenc
Date: Wed Jun  1 08:03:41 2011
New Revision: 1130040

URL: http://svn.apache.org/viewvc?rev=1130040&view=rev
Log:
IOUtil.copy(Reader,Writer,int) - done

Modified:
    maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-commons-bridge/src/main/java/org/codehaus/plexus/util/IOUtil.java
    maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-tck/src/test/java/org/codehaus/plexus/util/IOUtilTest.java

Modified: maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-commons-bridge/src/main/java/org/codehaus/plexus/util/IOUtil.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-commons-bridge/src/main/java/org/codehaus/plexus/util/IOUtil.java?rev=1130040&r1=1130039&r2=1130040&view=diff
==============================================================================
--- maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-commons-bridge/src/main/java/org/codehaus/plexus/util/IOUtil.java (original)
+++ maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-commons-bridge/src/main/java/org/codehaus/plexus/util/IOUtil.java Wed Jun  1 08:03:41 2011
@@ -68,7 +68,14 @@ public final class IOUtil
     public static void copy( java.io.Reader input, java.io.Writer output, int bufferSize )
         throws java.io.IOException
     {
-        throw new UnsupportedOperationException( "Not implemented yet" );
+        if ( bufferSize < 0 )
+        {
+            throw new NegativeArraySizeException();
+        }
+        input.getClass();
+        output.getClass();
+        fakeBufferSizeHandler( bufferSize );
+        IOUtils.copy( input, output );
     }
 
     public static void copy( java.io.InputStream input, java.io.Writer output )

Modified: maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-tck/src/test/java/org/codehaus/plexus/util/IOUtilTest.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-tck/src/test/java/org/codehaus/plexus/util/IOUtilTest.java?rev=1130040&r1=1130039&r2=1130040&view=diff
==============================================================================
--- maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-tck/src/test/java/org/codehaus/plexus/util/IOUtilTest.java (original)
+++ maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-tck/src/test/java/org/codehaus/plexus/util/IOUtilTest.java Wed Jun  1 08:03:41 2011
@@ -2432,6 +2432,196 @@ public class IOUtilTest
         assertThat( writer.toString(), is( probe ) );
     }
 
+    /*
+     * copy(Reader,Writer,int)
+     */
+
+    @Test( expected = NegativeArraySizeException.class )
+    public void copyNullReaderNullWriterNegBufSz()
+        throws Exception
+    {
+        IOUtil.copy( nullReader(), nullWriter(), -1 );
+    }
+
+    @Test( expected = NegativeArraySizeException.class )
+    public void copyEmptyReaderNullWriterNegBufSz()
+        throws Exception
+    {
+        IOUtil.copy( emptyReader(), nullWriter(), -1 );
+    }
+
+    @Test( expected = NegativeArraySizeException.class )
+    public void copyNullReaderValidWriterNegBufSz()
+        throws Exception
+    {
+        IOUtil.copy( nullReader(), new DontCloseStringWriter(), -1 );
+    }
+
+    @Test( expected = NegativeArraySizeException.class )
+    public void copyEmptyReaderValidWriterNegBufSz()
+        throws Exception
+    {
+        StringWriter writer = new DontCloseStringWriter();
+        IOUtil.copy( emptyReader(), writer, -1 );
+        assertThat( writer.toString(), is( emptyString() ) );
+    }
+
+    @Test( expected = NegativeArraySizeException.class )
+    public void copyReaderNullWriterNegBufSz()
+        throws Exception
+    {
+        String probe = "A string \u2345\u00ef";
+        IOUtil.copy( new StringReader( probe ), nullWriter(), -1 );
+    }
+
+    @Test(expected = NegativeArraySizeException.class )
+    public void copyReaderValidWriterNegBufSz()
+        throws Exception
+    {
+        String probe = "A string \u2345\u00ef";
+        StringWriter writer = new DontCloseStringWriter();
+        IOUtil.copy( new StringReader( probe ), writer, -1 );
+        assertThat( writer.toString(), is( probe ) );
+    }
+
+    @Test( expected = NullPointerException.class, timeout = 150)
+    public void copyNullReaderNullWriterZeroBufSz()
+        throws Exception
+    {
+        IOUtil.copy( nullReader(), nullWriter(), 0 );
+    }
+
+    @Test( expected = NullPointerException.class, timeout = 150 )
+    public void copyEmptyReaderNullWriterZeroBufSz()
+        throws Exception
+    {
+        IOUtil.copy( emptyReader(), nullWriter(), 0 );
+    }
+
+    @Test( expected = NullPointerException.class, timeout = 150 )
+    public void copyNullReaderValidWriterZeroBufSz()
+        throws Exception
+    {
+        IOUtil.copy( nullReader(), new DontCloseStringWriter(), 0 );
+    }
+
+    @Test(timeout = 150) // TODO
+    public void copyEmptyReaderValidWriterZeroBufSz()
+        throws Exception
+    {
+        final AtomicBoolean finished = new AtomicBoolean( false );
+        Thread worker = new Thread()
+        {
+            @Override
+            public void run()
+            {
+                try
+                {
+                    StringWriter writer = new DontCloseStringWriter();
+                    IOUtil.copy( emptyReader(), writer, 0 );
+                }
+                catch ( IOException e )
+                {
+                    // ignore
+                }
+                finished.set( true );
+            }
+        };
+        worker.start();
+        worker.join( 100 );
+        worker.interrupt();
+        assertThat( "We have an infinite loop", finished.get(), is( false ) );
+    }
+
+    @Test( expected = NullPointerException.class, timeout = 150 )
+    public void copyReaderNullWriterZeroBufSz()
+        throws Exception
+    {
+        String probe = "A string \u2345\u00ef";
+        IOUtil.copy( new StringReader( probe ), nullWriter(), 0 );
+    }
+
+    @Test(timeout = 150)  // TODO
+    public void copyReaderValidWriterZeroBufSz()
+        throws Exception
+    {
+        final AtomicBoolean finished = new AtomicBoolean( false );
+        Thread worker = new Thread()
+        {
+            @Override
+            public void run()
+            {
+                try
+                {
+                    String probe = "A string \u2345\u00ef";
+                    StringWriter writer = new DontCloseStringWriter();
+                    IOUtil.copy( new StringReader( probe ), writer, 0 );
+                }
+                catch ( IOException e )
+                {
+                    // ignore
+                }
+                finished.set( true );
+            }
+        };
+        worker.start();
+        worker.join( 100 );
+        worker.interrupt();
+        assertThat( "We have an infinite loop", finished.get(), is( false ) );
+    }
+
+    @Test( expected = NullPointerException.class )
+    public void copyNullReaderNullWriterPosBufSz()
+        throws Exception
+    {
+        IOUtil.copy( nullReader(), nullWriter(), 1 );
+    }
+
+    @Test( expected = NullPointerException.class )
+    public void copyEmptyReaderNullWriterPosBufSz()
+        throws Exception
+    {
+        IOUtil.copy( emptyReader(), nullWriter(), 1 );
+    }
+
+    @Test( expected = NullPointerException.class )
+    public void copyNullReaderValidWriterPosBufSz()
+        throws Exception
+    {
+        IOUtil.copy( nullReader(), new DontCloseStringWriter(), 1 );
+    }
+
+    @Test
+    public void copyEmptyReaderValidWriterPosBufSz()
+        throws Exception
+    {
+        StringWriter writer = new DontCloseStringWriter();
+        IOUtil.copy( emptyReader(), writer, 1 );
+        assertThat( writer.toString(), is( emptyString() ) );
+    }
+
+    @Test( expected = NullPointerException.class )
+    public void copyReaderNullWriterPosBufSz()
+        throws Exception
+    {
+        String probe = "A string \u2345\u00ef";
+        IOUtil.copy( new StringReader( probe ), nullWriter(), 1 );
+    }
+
+    @Test
+    public void copyReaderValidWriterPosBufSz()
+        throws Exception
+    {
+        String probe = "A string \u2345\u00ef";
+        StringWriter writer = new DontCloseStringWriter();
+        IOUtil.copy( new StringReader( probe ), writer, 1 );
+        assertThat( writer.toString(), is( probe ) );
+    }
+
+
+    /*
+     * Utility methods
+     */
     private static byte[] nullByteArray()
     {
         return null;