public class FastByteArrayOutputStream extends OutputStream
可以通过toByteArray()和 toString()来获取数据
close()方法无任何效果,当流被关闭后不会抛出IOException
这种设计避免重新分配内存块而是分配新增的缓冲区,缓冲区不会被GC,数据也不会被拷贝到其他缓冲区。
| 构造器和说明 |
|---|
FastByteArrayOutputStream()
构造
|
FastByteArrayOutputStream(int size)
构造
|
| 限定符和类型 | 方法和说明 |
|---|---|
void |
close()
此方法无任何效果,当流被关闭后不会抛出IOException
|
void |
reset()
复位
|
int |
size()
长度
|
byte[] |
toByteArray()
转为Byte数组
|
byte[] |
toByteArrayZeroCopyIfPossible()
转为Byte数组,如果缓冲区中的数据长度固定,则直接返回原始数组
注意此方法共享数组,不能修改数组内容! |
String |
toString() |
String |
toString(Charset charset)
转为字符串
|
void |
write(byte[] b,
int off,
int len) |
void |
write(int b) |
void |
writeTo(OutputStream out)
写出
|
flush, writepublic FastByteArrayOutputStream()
public FastByteArrayOutputStream(int size)
size - 预估大小public void write(byte[] b,
int off,
int len)
write 在类中 OutputStreampublic void write(int b)
write 在类中 OutputStreampublic int size()
public void close()
close 在接口中 Closeableclose 在接口中 AutoCloseableclose 在类中 OutputStreampublic void reset()
public void writeTo(OutputStream out) throws IORuntimeException
out - 输出流IORuntimeException - IO异常public byte[] toByteArray()
public byte[] toByteArrayZeroCopyIfPossible()
Copyright © 2023. All rights reserved.