Android API讲解之:ByteArrayOutputStream

ByteArrayOutputStream继承自OutputStream,它的变量及方法包括:

ByteArrayOutputStream() 长度为32个字节
public ByteArrayOutputStream(int size)可自定义长度size,用于字节超过32个字节时。
public void close() throws IOException关闭输出流,可释放系统资源
public synchronized void reset() 重置输出流,使内部字节为0
public int size() 该输出流中的字节数
public synchronized byte[] toByteArray() 将该输出流中内容转换为字节数组
public String toString()转换为字符串
public String toString(String charsetName) throws UnsupportedEncodingException转换为编码格式为charsetName的字符串
public synchronized void write(byte[] buffer, int offset, int len)将buffer写入该输出流
public synchronized void write(int oneByte)写入1个字节的数据
public synchronized void writeTo(OutputStream out) throws IOException将该输出流写入out中
上面所有的方法都很清晰明了,这里就仅说明下:public synchronized void write(byte[] buffer, int offset, int len),其详细代码为:

    @Override
    public synchronized void write(byte[] buffer, int offset, int len) {
        Arrays.checkOffsetAndCount(buffer.length, offset, len);
        if (len == 0) {
            return;
        }
        expand(len);
        System.arraycopy(buffer, offset, buf, this.count, len);
        this.count += len;
    }
其中buffer为写入该OutputStream流的数据源;offset为buffer中数据拷贝的索引值,即从第几个数据开始复制;this.count为该OutputStream的长度,即数据添加的起始编号,len为写入数据的长度。




  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值