前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >FTPClient中使用completePendingCommand方法注意事项

FTPClient中使用completePendingCommand方法注意事项

作者头像
庞小明
发布2019-05-25 17:59:08
2.1K0
发布2019-05-25 17:59:08
举报
文章被收录于专栏:pangguomingpangguoming

方法介绍:

代码语言:javascript
复制
    * There are a few FTPClient methods that do not complete the
    * entire sequence of FTP commands to complete a transaction.  These
    * commands require some action by the programmer after the reception
    * of a positive intermediate command.  After the programmer's code
    * completes its actions, it must call this method to receive
    * the completion reply from the server and verify the success of the
    * entire transaction.
   public boolean completePendingCommad() throws IOException;
   {
        return FTPReply.isPositiveCompletion(getReply());
   }

方法介绍中未说明,在何种情况下应该使用该方法。但是跟踪代码可以发现 这是一个同步阻塞方法,如果调用错误,会导致程序卡住假死在这里。

代码语言:javascript
复制
卡住代码
 String line = _controlInput_.readLine();

何时调用?

其实ftp功能,总结来说,只有上传和下载。只有在获取返回流时,才需要调用completePendingCommad方法,因为返回流不是立刻处理的。所以需用手动调用结束方法。

代码语言:javascript
复制
public boolean storeFile(String remote, InputStream local)
public OutputStream storeFileStream(String remote)

public boolean retrieveFile(String remote, OutputStream local)
public InputStream retrieveFileStream(String remote)

我们看到上面4个人方法,其中两个有流返回,另外两个无返回。当调用有返回流方法时,需要手动调用completePendingCommad方法,即第二个和第四个是需要调用completePendingCommad方法,其他两个方法如果调用了,则会产生卡死超时现象。

注意事项

不可多加或者漏加,否则会导致程序卡死

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019-05-23 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 方法介绍:
  • 何时调用?
  • 注意事项
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档