home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Programming Languages Suite
/
ProgLangD.iso
/
VCAFE.3.0A
/
Main.bin
/
StringWriter.java
< prev
next >
Wrap
Text File
|
1998-09-22
|
3KB
|
113 lines
/*
* @(#)StringWriter.java 1.6 98/07/01
*
* Copyright 1995-1998 by Sun Microsystems, Inc.,
* 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
* All rights reserved.
*
* This software is the confidential and proprietary information
* of Sun Microsystems, Inc. ("Confidential Information"). You
* shall not disclose such Confidential Information and shall use
* it only in accordance with the terms of the license agreement
* you entered into with Sun.
*/
package java.io;
/**
* A character stream that collects its output in a string buffer, which can
* then be used to construct a string.
*
* @version 1.6, 98/07/01
* @author Mark Reinhold
* @since JDK1.1
*/
public class StringWriter extends Writer {
private StringBuffer buf;
/**
* Create a new string writer, using the default initial string-buffer
* size.
*/
public StringWriter() {
buf = new StringBuffer();
lock = buf;
}
/**
* Create a new string writer, using the specified initial string-buffer
* size.
*/
protected StringWriter(int initialSize) {
buf = new StringBuffer(initialSize);
lock = buf;
}
/**
* Write a single character.
*/
public void write(int c) {
buf.append((char) c);
}
/**
* Write a portion of an array of characters.
*
* @param cbuf Array of characters
* @param off Offset from which to start writing characters
* @param len Number of characters to write
*/
public void write(char cbuf[], int off, int len) {
buf.append(cbuf, off, len);
}
/**
* Write a string.
*/
public void write(String str) {
buf.append(str);
}
/**
* Write a portion of a string.
*
* @param str String to be written
* @param off Offset from which to start writing characters
* @param len Number of characters to write
*/
public void write(String str, int off, int len) {
char cbuf[] = new char[len];
str.getChars(off, len, cbuf, 0);
buf.append(cbuf);
}
/**
* Return the buffer's current value as a string.
*/
public String toString() {
return buf.toString();
}
/**
* Return the string buffer itself.
*/
public StringBuffer getBuffer() {
return buf;
}
/**
* Flush the stream.
*/
public void flush() { }
/**
* Close the stream. This method does not release the buffer, since its
* contents might still be required.
*/
public void close() { }
}