Class StringWriter
java.lang.Object
java.io.Writer
java.io.StringWriter
- All Implemented Interfaces:
Appendable, AutoCloseable
-
Field Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionappend(char c) Appends the specified character.append(CharSequence csq) Appends the character sequencecsq.append(CharSequence csq, int start, int end) Appends a subsequence ofcsq.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 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 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 interface:AppendableAppends the specified character.- Specified by:
appendin interfaceAppendable- Parameters:
c- the character to append.- Returns:
- this
Appendable.
-
append
Description copied from interface:AppendableAppends the character sequencecsq. Implementation classes may not append the whole sequence, for example if the target is a buffer with limited size.If
csqisnull, the characters "null" are appended.- Specified by:
appendin interfaceAppendable- Parameters:
csq- the character sequence to append.- Returns:
- this
Appendable.
-
append
Description copied from interface:AppendableAppends a subsequence ofcsq.If
csqis notnullthen calling this method is equivalent to callingappend(csq.subSequence(start, end)).If
csqisnull, the characters "null" are appended.- Specified by:
appendin interfaceAppendable- Parameters:
csq- the character sequence to append.start- the first index of the subsequence ofcsqthat is appended.end- the last index of the subsequence ofcsqthat is appended.- Returns:
- this
Appendable.
-