public class FastByteArrayOutputStream extends OutputStream
可以通过toByteArray()
和 toString()
来获取数据
close()
方法无任何效果,当流被关闭后不会抛出IOException
这种设计避免重新分配内存块而是分配新增的缓冲区,缓冲区不会被GC,数据也不会被拷贝到其他缓冲区。
Constructor and Description |
---|
FastByteArrayOutputStream()
构造
|
FastByteArrayOutputStream(int size)
构造
|
Modifier and Type | Method and Description |
---|---|
void |
close()
此方法无任何效果,当流被关闭后不会抛出IOException
|
void |
reset() |
int |
size() |
byte[] |
toByteArray()
转为Byte数组
|
String |
toString() |
String |
toString(Charset charset)
转为字符串
|
String |
toString(String charsetName)
转为字符串
|
void |
write(byte[] b,
int off,
int len) |
void |
write(int b) |
void |
writeTo(OutputStream out)
写出
|
flush, write
public FastByteArrayOutputStream()
public FastByteArrayOutputStream(int size)
size
- 预估大小public void write(byte[] b, int off, int len)
write
in class OutputStream
public void write(int b)
write
in class OutputStream
public int size()
public void close()
close
in interface Closeable
close
in interface AutoCloseable
close
in class OutputStream
public void reset()
public void writeTo(OutputStream out) throws IORuntimeException
out
- 输出流IORuntimeException
- IO异常public byte[] toByteArray()
Copyright © 2024. All rights reserved.