Package com.luna.common.io
Class FastByteArrayOutputStream
java.lang.Object
java.io.OutputStream
com.luna.common.io.FastByteArrayOutputStream
- All Implemented Interfaces:
Closeable
,Flushable
,AutoCloseable
基于快速缓冲FastByteBuffer的OutputStream,随着数据的增长自动扩充缓冲区
可以通过toByteArray()
和 toString()
来获取数据
close()
方法无任何效果,当流被关闭后不会抛出IOException
这种设计避免重新分配内存块而是分配新增的缓冲区,缓冲区不会被GC,数据也不会被拷贝到其他缓冲区。
- Author:
- biezhi
-
Constructor Summary
-
Method Summary
Methods inherited from class java.io.OutputStream
flush, nullOutputStream, write
-
Constructor Details
-
FastByteArrayOutputStream
public FastByteArrayOutputStream() -
FastByteArrayOutputStream
public FastByteArrayOutputStream(int size) 构造- Parameters:
size
- 预估大小
-
-
Method Details
-
write
public void write(byte[] b, int off, int len) - Overrides:
write
in classOutputStream
-
write
public void write(int b) - Specified by:
write
in classOutputStream
-
size
public int size() -
close
public void close()此方法无任何效果,当流被关闭后不会抛出IOException- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classOutputStream
-
reset
public void reset() -
writeTo
写出- Parameters:
out
- 输出流- Throws:
IOException
- IO异常
-
toByteArray
public byte[] toByteArray()转为Byte数组- Returns:
- Byte数组
-
toString
-
toString
转为字符串- Parameters:
charsetName
- 编码- Returns:
- 字符串
-
toString
转为字符串- Parameters:
charset
- 编码,null表示默认编码- Returns:
- 字符串
-