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 *
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 @Deprecated
31 public class StringOutputStream
32 extends OutputStream
33 {
34 private StringBuffer buf = new StringBuffer();
35
36 @Override
37 public void write( byte[] b )
38 throws IOException
39 {
40 buf.append( new String( b ) );
41 }
42
43 @Override
44 public void write( byte[] b, int off, int len )
45 throws IOException
46 {
47 buf.append( new String( b, off, len ) );
48 }
49
50 @Override
51 public void write( int b )
52 throws IOException
53 {
54 byte[] bytes = new byte[1];
55 bytes[0] = (byte) b;
56 buf.append( new String( bytes ) );
57 }
58
59 @Override
60 public String toString()
61 {
62 return buf.toString();
63 }
64 }