View Javadoc
1   package org.codehaus.plexus.util;
2   
3   /*
4    * Copyright The Codehaus Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  import java.io.IOException;
20  import java.io.OutputStream;
21  
22  /**
23   * Wraps a String as an OutputStream.
24   *
25   * @author <a href="mailto:evenisse@codehaus.org">Emmanuel Venisse</a>
26   * @version $Id$
27   * @deprecated As of version 1.5.2 this class should no longer be used because it does not properly handle character
28   *             encoding. Instead, use {@link java.io.ByteArrayOutputStream#toString(String)}.
29   */
30  public class StringOutputStream
31      extends OutputStream
32  {
33      private StringBuffer buf = new StringBuffer();
34  
35      public void write( byte[] b )
36          throws IOException
37      {
38          buf.append( new String( b ) );
39      }
40  
41      public void write( byte[] b, int off, int len )
42          throws IOException
43      {
44          buf.append( new String( b, off, len ) );
45      }
46  
47      public void write( int b )
48          throws IOException
49      {
50          byte[] bytes = new byte[1];
51          bytes[0] = (byte) b;
52          buf.append( new String( bytes ) );
53      }
54  
55      public String toString()
56      {
57          return buf.toString();
58      }
59  }