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/05/26 02:00:27 UTC

svn commit: r1127738 - 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: Thu May 26 00:00:27 2011
New Revision: 1127738

URL: http://svn.apache.org/viewvc?rev=1127738&view=rev
Log:
adding IOUtil.copy(String,OutputStream,int)

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=1127738&r1=1127737&r2=1127738&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 Thu May 26 00:00:27 2011
@@ -227,7 +227,10 @@ public final class IOUtil
     public static void copy( java.lang.String input, java.io.OutputStream output, int bufferSize )
         throws java.io.IOException
     {
-        throw new UnsupportedOperationException( "Not implemented yet" );
+        input.getClass();
+        output.getClass();
+        IOUtils.write( input, output );
+        fakeBufferSizeHandler( bufferSize );
     }
 
     public static void copy( java.lang.String 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=1127738&r1=1127737&r2=1127738&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 Thu May 26 00:00:27 2011
@@ -2164,7 +2164,7 @@ public class IOUtilTest
         IOUtil.copy( "", nullOutputStream() );
     }
 
-    @Test(expected = NullPointerException.class)
+    @Test( expected = NullPointerException.class )
     public void copyNullStringValidOutputStream()
         throws Exception
     {
@@ -2198,6 +2198,192 @@ public class IOUtilTest
         assertThat( OutputStream.toByteArray(), is( probe.getBytes() ) );
     }
 
+    @Test( expected = NullPointerException.class )
+    public void copyNullStringNullOutputStreamNegBufSz()
+        throws Exception
+    {
+        IOUtil.copy( nullString(), nullOutputStream(), -1 );
+    }
+
+    @Test( expected = NullPointerException.class )
+    public void copyEmptyStringNullOutputStreamNegBufSz()
+        throws Exception
+    {
+        IOUtil.copy( "", nullOutputStream(), -1 );
+    }
+
+    @Test( expected = NullPointerException.class )
+    public void copyNullStringValidOutputStreamNegBufSz()
+        throws Exception
+    {
+        IOUtil.copy( nullString(), new DontCloseByteArrayOutputStream(), -1 );
+    }
+
+    @Test(expected = NegativeArraySizeException.class)
+    public void copyEmptyStringValidOutputStreamNegBufSz()
+        throws Exception
+    {
+        ByteArrayOutputStream OutputStream = new DontCloseByteArrayOutputStream();
+        IOUtil.copy( "", OutputStream, -1 );
+        assertThat( OutputStream.toByteArray(), is( "".getBytes() ) );
+    }
+
+    @Test( expected = NullPointerException.class )
+    public void copyStringNullOutputStreamNegBufSz()
+        throws Exception
+    {
+        String probe = "A string \u2345\u00ef";
+        IOUtil.copy( probe, nullOutputStream(), -1 );
+    }
+
+    @Test(expected = NegativeArraySizeException.class)
+    public void copyStringValidOutputStreamNegBufSz()
+        throws Exception
+    {
+        String probe = "A string \u2345\u00ef";
+        ByteArrayOutputStream OutputStream = new DontCloseByteArrayOutputStream();
+        IOUtil.copy( probe, OutputStream, -1 );
+        assertThat( OutputStream.toByteArray(), is( probe.getBytes() ) );
+    }
+
+    @Test( expected = NullPointerException.class, timeout = 150 )
+    public void copyNullStringNullOutputStreamZeroBufSz()
+        throws Exception
+    {
+        IOUtil.copy( nullString(), nullOutputStream(), 0 );
+    }
+
+    @Test( expected = NullPointerException.class, timeout = 150 )
+    public void copyEmptyStringNullOutputStreamZeroBufSz()
+        throws Exception
+    {
+        IOUtil.copy( "", nullOutputStream(), 0 );
+    }
+
+    @Test( expected = NullPointerException.class, timeout = 150 )
+    public void copyNullStringValidOutputStreamZeroBufSz()
+        throws Exception
+    {
+        IOUtil.copy( nullString(), new DontCloseByteArrayOutputStream(), 0 );
+    }
+
+    @Test( timeout = 150 )
+    @ReproducesPlexusBug( "Should not infinite loop" )
+    public void copyEmptyStringValidOutputStreamZeroBufSz()
+        throws Exception
+    {
+        final AtomicBoolean finished = new AtomicBoolean( false );
+        Thread worker = new Thread()
+        {
+            @Override
+            public void run()
+            {
+                try
+                {
+                    ByteArrayOutputStream OutputStream = new DontCloseByteArrayOutputStream();
+                    IOUtil.copy( "", OutputStream, 0 );
+                    assertThat( OutputStream.toByteArray(), is( "".getBytes() ) );
+                }
+                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 copyStringNullOutputStreamZeroBufSz()
+        throws Exception
+    {
+        String probe = "A string \u2345\u00ef";
+        IOUtil.copy( probe, nullOutputStream(), 0 );
+    }
+
+    @Test( timeout = 150 )
+    @ReproducesPlexusBug( "Should not infinite loop" )
+    public void copyStringValidOutputStreamZeroBufSz()
+        throws Exception
+    {
+        final AtomicBoolean finished = new AtomicBoolean( false );
+        Thread worker = new Thread()
+        {
+            @Override
+            public void run()
+            {
+                try
+                {
+                    String probe = "A string \u2345\u00ef";
+                    ByteArrayOutputStream OutputStream = new DontCloseByteArrayOutputStream();
+                    IOUtil.copy( probe, OutputStream, 0 );
+                    assertThat( OutputStream.toByteArray(), is( probe.getBytes() ) );
+                }
+                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 copyNullStringNullOutputStreamPosBufSz()
+        throws Exception
+    {
+        IOUtil.copy( nullString(), nullOutputStream(), 1 );
+    }
+
+    @Test( expected = NullPointerException.class )
+    public void copyEmptyStringNullOutputStreamPosBufSz()
+        throws Exception
+    {
+        IOUtil.copy( "", nullOutputStream(), 1 );
+    }
+
+    @Test( expected = NullPointerException.class )
+    public void copyNullStringValidOutputStreamPosBufSz()
+        throws Exception
+    {
+        IOUtil.copy( nullString(), new DontCloseByteArrayOutputStream(), 1 );
+    }
+
+    @Test
+    public void copyEmptyStringValidOutputStreamPosBufSz()
+        throws Exception
+    {
+        ByteArrayOutputStream OutputStream = new DontCloseByteArrayOutputStream();
+        IOUtil.copy( "", OutputStream, 1 );
+        assertThat( OutputStream.toByteArray(), is( "".getBytes() ) );
+    }
+
+    @Test( expected = NullPointerException.class )
+    public void copyStringNullOutputStreamPosBufSz()
+        throws Exception
+    {
+        String probe = "A string \u2345\u00ef";
+        IOUtil.copy( probe, nullOutputStream(), 1 );
+    }
+
+    @Test
+    public void copyStringValidOutputStreamPosBufSz()
+        throws Exception
+    {
+        String probe = "A string \u2345\u00ef";
+        ByteArrayOutputStream OutputStream = new DontCloseByteArrayOutputStream();
+        IOUtil.copy( probe, OutputStream, 1 );
+        assertThat( OutputStream.toByteArray(), is( probe.getBytes() ) );
+    }
+
     private static byte[] nullByteArray()
     {
         return null;