Class StringWriter
java.lang.Object
java.io.Writer
java.io.StringWriter
- All Implemented Interfaces:
Closeable, Flushable, Appendable, AutoCloseable
-
Field Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionappend(char c) Writesc.append(CharSequence csq) Writescsq, or "null" when it is null.append(CharSequence csq, int start, int end) Writes the characters ofcsqfromstartup toend.voidclose()Close the stream, flushing it first.voidflush()Flush the stream.toString()Returns a string representation of the object.voidwrite(char[] cbuf) Write an array of characters.voidwrite(char[] cbuf, int off, int len) Write a portion of an array of characters.voidwrite(int c) Write a single character.voidWrite a string.voidWrite a portion of a string.
-
Constructor Details
-
StringWriter
public StringWriter() -
StringWriter
public StringWriter(int initialSize)
-
-
Method Details
-
close
Description copied from class:WriterClose the stream, flushing it first. Once a stream has been closed, further write() or flush() invocations will cause an IOException to be thrown. Closing a previously-closed stream, however, has no effect.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein classWriter- Throws:
IOException
-
flush
Description copied from class:WriterFlush the stream. If the stream has saved any characters from the various write() methods in a buffer, write them immediately to their intended destination. Then, if that destination is another character or byte stream, flush it. Thus one flush() invocation will flush all the buffers in a chain of Writers and OutputStreams.- Specified by:
flushin interfaceFlushable- Specified by:
flushin classWriter- Throws:
IOException
-
write
Description copied from class:WriterWrite a portion of an array of characters.- Specified by:
writein classWriter- Throws:
IOException
-
write
Description copied from class:WriterWrite a portion of a string.- Overrides:
writein classWriter- Throws:
IOException
-
write
Description copied from class:WriterWrite a single character. The character to be written is contained in the 16 low-order bits of the given integer value; the 16 high-order bits are ignored. Subclasses that intend to support efficient single-character output should override this method.- Overrides:
writein classWriter- Throws:
IOException
-
write
Description copied from class:WriterWrite a string.- Overrides:
writein classWriter- Throws:
IOException
-
write
Description copied from class:WriterWrite an array of characters.- Overrides:
writein classWriter- Throws:
IOException
-
toString
Description copied from class:ObjectReturns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method. The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of: getClass().getName() + '@' + Integer.toHexString(hashCode()) -
getBuffer
-
append
Description copied from class:WriterWritesc.- Specified by:
appendin interfaceAppendable- Overrides:
appendin classWriter
-
append
Description copied from class:WriterWritescsq, or "null" when it is null.- Specified by:
appendin interfaceAppendable- Overrides:
appendin classWriter
-
append
Description copied from class:WriterWrites the characters ofcsqfromstartup toend.- Specified by:
appendin interfaceAppendable- Overrides:
appendin classWriter
-