You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by be...@apache.org on 2009/01/17 23:33:37 UTC
svn commit: r735346 - in /maven/release/trunk/maven-release-manager/src:
main/java/org/apache/maven/shared/release/exec/TeeOutputStream.java
test/java/org/apache/maven/shared/release/exec/TeeOutputStreamTest.java
Author: bentmann
Date: Sat Jan 17 14:33:36 2009
New Revision: 735346
URL: http://svn.apache.org/viewvc?rev=735346&view=rev
Log:
o Fixed output stream
Added:
maven/release/trunk/maven-release-manager/src/test/java/org/apache/maven/shared/release/exec/TeeOutputStreamTest.java (with props)
Modified:
maven/release/trunk/maven-release-manager/src/main/java/org/apache/maven/shared/release/exec/TeeOutputStream.java
Modified: maven/release/trunk/maven-release-manager/src/main/java/org/apache/maven/shared/release/exec/TeeOutputStream.java
URL: http://svn.apache.org/viewvc/maven/release/trunk/maven-release-manager/src/main/java/org/apache/maven/shared/release/exec/TeeOutputStream.java?rev=735346&r1=735345&r2=735346&view=diff
==============================================================================
--- maven/release/trunk/maven-release-manager/src/main/java/org/apache/maven/shared/release/exec/TeeOutputStream.java (original)
+++ maven/release/trunk/maven-release-manager/src/main/java/org/apache/maven/shared/release/exec/TeeOutputStream.java Sat Jan 17 14:33:36 2009
@@ -27,9 +27,10 @@
public class TeeOutputStream
extends FilterOutputStream
{
- ByteArrayOutputStream bout = new ByteArrayOutputStream( 1024 );
- byte indent[];
-
+ private ByteArrayOutputStream bout = new ByteArrayOutputStream( 1024 * 8 );
+ private byte indent[];
+ private int last = '\n';
+
public TeeOutputStream( OutputStream out )
{
this( out, " " );
@@ -40,45 +41,38 @@
super( out );
indent = i.getBytes();
}
-
- public void write( byte[] b, int off, int len )
+
+ public void write( byte[] b, int off, int len )
throws IOException
{
for ( int x = 0; x < len; x++ )
{
- if ( b[off + x] == '\r'
- && x < (len - 1)
- && b[off + x + 1] == '\n' )
+ int c = b[off + x];
+ if ( last == '\n' || ( last == '\r' && c != '\n' ) )
{
- x++;
- }
-
- if ( b[off + x] == '\n'
- || b[off + x] == '\r' )
- {
- super.write( b, off, x + 1);
- bout.write( b, off, x + 1);
- super.write( indent );
- bout.write( indent );
- off += ( x + 1 );
- len -= ( x + 1 );
+ out.write( b, off, x );
+ bout.write( b, off, x );
+ out.write( indent );
+ off += x;
+ len -= x;
x = 0;
}
+ last = c;
}
- super.write( b, off, len );
+ out.write( b, off, len );
bout.write( b, off, len );
}
public void write( int b )
throws IOException
{
- super.write( b );
- bout.write( b );
- if ( b == '\n' )
+ if ( last == '\n' || ( last == '\r' && b != '\n' ) )
{
- super.write( indent );
- bout.write( indent );
+ out.write( indent );
}
+ out.write( b );
+ bout.write( b );
+ last = b;
}
public String toString()
Added: maven/release/trunk/maven-release-manager/src/test/java/org/apache/maven/shared/release/exec/TeeOutputStreamTest.java
URL: http://svn.apache.org/viewvc/maven/release/trunk/maven-release-manager/src/test/java/org/apache/maven/shared/release/exec/TeeOutputStreamTest.java?rev=735346&view=auto
==============================================================================
--- maven/release/trunk/maven-release-manager/src/test/java/org/apache/maven/shared/release/exec/TeeOutputStreamTest.java (added)
+++ maven/release/trunk/maven-release-manager/src/test/java/org/apache/maven/shared/release/exec/TeeOutputStreamTest.java Sat Jan 17 14:33:36 2009
@@ -0,0 +1,62 @@
+package org.apache.maven.shared.release.exec;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import junit.framework.TestCase;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+
+/**
+ * Test the output stream that tees output both to a stream and into an internal buffer for later.
+ *
+ * @author Benjamin Bentmann
+ * @version $Id$
+ */
+public class TeeOutputStreamTest
+ extends TestCase
+{
+ private TeeOutputStream stream;
+
+ private ByteArrayOutputStream out;
+
+ private static final String LS = System.getProperty( "line.separator" );
+
+ protected void setUp()
+ throws Exception
+ {
+ super.setUp();
+
+ out = new ByteArrayOutputStream();
+ stream = new TeeOutputStream( new PrintStream( out ), "xxx " );
+ }
+
+ public void testConsumeLine()
+ throws Exception
+ {
+ stream.write( ( "the first line" + LS + "line2" + LS + "3" + LS ).getBytes() );
+
+ assertEquals( "Check output", "xxx the first line" + LS + "xxx line2" + LS + "xxx 3" + LS, out.toString() );
+
+ assertEquals( "Check content", "the first line" + LS + "line2" + LS + "3" + LS, stream.getContent() );
+
+ assertEquals( "Check toString", "the first line" + LS + "line2" + LS + "3" + LS, stream.toString() );
+ }
+}
Propchange: maven/release/trunk/maven-release-manager/src/test/java/org/apache/maven/shared/release/exec/TeeOutputStreamTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/release/trunk/maven-release-manager/src/test/java/org/apache/maven/shared/release/exec/TeeOutputStreamTest.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision