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