java开源网络包org.apache.commons.net研究(二)

本文探讨了org.apache.commons.net.io.Util.copyStream方法,该方法用于从InputStream复制内容到OutputStream,并利用CopyStreamListener监听拷贝进度。文章详细分析了方法内部实现,包括缓冲区、监听器机制,以及如何处理IOException。最后提到了接下来将研究TelnetClient的connect方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

       通过顺藤摸瓜的研究,现在代码的焦点集中在写线程中的下面这个方法:
               org.apache.commons.net.io.Util.copyStream(remoteInput, localOutput);
       再往里面跟踪,发现Util里面有几个copyStream的重载方法,归根结底,最终调用的是这个方法:
      
/***************************************************************************
     * Copies the contents of an InputStream to an OutputStream using a copy
     * buffer of a given size and notifies the provided CopyStreamListener of
     * the progress of the copy operation by calling its bytesTransferred(long,
     * int) method after each write to the destination. If you wish to notify
     * more than one listener you should use a CopyStreamAdapter as the listener
     * and register the additional listeners with the CopyStreamAdapter.
     * <p>
     * The contents of the InputStream are read until the end of the stream is
     * reached, but neither the source nor the destination are closed. You must
     * do this yourself outside of the method call. The number of bytes
     * read/written is returned.
     * <p>
     * 
     * 
@param source
     *            The source InputStream.
     * 
@param dest
     *            The destination OutputStream.
     * 
@param bufferSize
     *            The number of bytes to buffer during the copy.
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值