public class ByteArrayOutputStream extends OutputStream
toByteArray()
和
toString()
检索。
关闭ByteArrayOutputStream没有影响。这个类中的方法可以在流一直没有产生一个IOException闭叫。
Modifier and Type | Field and Description |
---|---|
protected byte[] |
buf
存储数据的缓冲区。
|
protected int |
count
缓冲区中有效字节数。
|
Constructor and Description |
---|
ByteArrayOutputStream()
创建一个新的字节数组输出流。
|
ByteArrayOutputStream(int size)
创建一个新的字节数组输出流,具有指定大小的缓冲容量,以字节为单位的。
|
Modifier and Type | Method and Description |
---|---|
void |
close()
关闭
ByteArrayOutputStream没有影响。
|
void |
reset()
将这个字节数组输出流的
count 场为零,因此,目前累计输出输出流被丢弃。
|
int |
size()
返回缓冲区的当前大小。
|
byte[] |
toByteArray()
创建一个新分配的字节数组。
|
String |
toString()
使用该平台的默认字符集将缓冲区的内容转换为字符串解码字节。
|
String |
toString(int hibyte)
过时的。
这种方法不正确地将字节转换为字符。作为 JDK 1.1,这样的首选方式是通过
toString(String enc) 方法,它以一个编码名称的争论,或toString() 方法,使用平台的默认字符编码。
|
String |
toString(String charsetName)
将缓冲区的内容到一个字符串使用命名
charset 解码字节。
|
void |
write(byte[] b, int off, int len)
写
len 字节指定字节数组中的起始偏移
off 这个字节数组输出流。
|
void |
write(int b)
将指定的字节写入该字节数组输出流中。
|
void |
writeTo(OutputStream out)
写这个字节数组输出流的完整内容到指定的输出流的说法,如果通过调用输出流的写法
out.write(buf, 0, count) 。
|
flush, write
public ByteArrayOutputStream()
public ByteArrayOutputStream(int size)
size
-初始大小。
IllegalArgumentException
如果尺寸是负的。
public void write(int b)
write
方法重写,继承类
OutputStream
b
的字节被写入。
public void write(byte[] b, int off, int len)
len
字节指定字节数组中的起始偏移
off
这个字节数组输出流。
write
方法重写,继承类
OutputStream
b
-数据。
off
的起始偏移量的数据。
len
-字节数写。
public void writeTo(OutputStream out) throws IOException
out.write(buf, 0, count)
。
out
-输出流中写入数据。
IOException
如果I/O错误发生。
public void reset()
count
场为零,因此,目前累计输出输出流被丢弃。输出流可以再次使用,再利用已分配的缓冲区空间。
public byte[] toByteArray()
size()
public int size()
count
字段的值,这是在输出流的有效字节数。
count
public String toString()
这种方法总是会替换格式不正确的输入,无法映射的字符序列与默认的字符串替换为平台的默认字符集。的CharsetDecoder班时应使用在解码过程中需要更多的控制。
public String toString(String charsetName) throws UnsupportedEncodingException
charset
解码字节。新的
String长度是一个字符集的功能,因此可能不相等的字节数组的长度。
这种方法总是会替换格式不正确的输入,无法映射的字符序列,该字符集的默认字符串替换。的CharsetDecoder
班时应使用在解码过程中需要更多的控制。
charsetName
-支持的
charset
名称
UnsupportedEncodingException
-如果指定的字符集不支持
@Deprecated public String toString(int hibyte)
toString(String enc)
方法,它以一个编码名称的争论,或toString()
方法,使用平台的默认字符编码。
这样:c == (char)(((hibyte & 0xff) << 8) | (b & 0xff))
hibyte
-每个Unicode字符的高字节。
size()
,
toString(String)
,
toString()
public void close() throws IOException
close
接口
Closeable
close
接口
AutoCloseable
close
方法重写,继承类
OutputStream
IOException
如果I/O错误发生。
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.