public class FastStringWriter extends Writer
由 JDK 中 StringWriter 改造而来,在其基础之上做了如下改变: 1:StringBuffer 属性改为 StringBuilder,避免了前者的 synchronized 操作 2:添加了 MAX_SIZE 属性 3:去掉了 close() 方法声明中的 throws IOException,并添加了代码,原先该方法中无任何代码
Constructor and Description |
---|
FastStringWriter() |
FastStringWriter(int initialSize) |
Modifier and Type | Method and Description |
---|---|
FastStringWriter |
append(char c) |
FastStringWriter |
append(CharSequence csq) |
FastStringWriter |
append(CharSequence csq,
int start,
int end) |
void |
close()
由 StringWriter.close() 改造而来,原先该方法中无任何代码 ,改造如下:
1:去掉 throws IOException
2:添加 buf 空间释放处理逻辑
3:添加 buf.setLength(0),以便于配合 ThreadLocal 回收利用
|
void |
flush() |
StringBuilder |
getBuffer() |
String |
toString() |
void |
write(char[] cbuf,
int off,
int len) |
void |
write(int c) |
void |
write(String str) |
void |
write(String str,
int off,
int len) |
public FastStringWriter()
public FastStringWriter(int initialSize)
public FastStringWriter append(CharSequence csq)
append
in interface Appendable
append
in class Writer
public FastStringWriter append(CharSequence csq, int start, int end)
append
in interface Appendable
append
in class Writer
public FastStringWriter append(char c)
append
in interface Appendable
append
in class Writer
public StringBuilder getBuffer()
public void flush()
Copyright © 2018. All rights reserved.