Unknown parser type: System V900R012

问题概要:你懂得 ...

原因: common-net 缺少对 V900R012 类型系统的支持

方案:

1)  FTPClientConfig.java

增加字段  

public static final String SYST_V900R012 = "V900R012";

2)  DefaultFTPFileEntryParserFactory

修改方法 private FTPFileEntryParser createFileEntryParser(String key, FTPClientConfig config) , 增加

else if (ukey.indexOf("V900R012") >= 0)
      {
        parser = new V900R012FTPEntryParser();
      }

3) 新建 V900R012FTPEntryParser.java

package org.apache.commons.net.ftp.parser;

import java.text.ParseException;
import org.apache.commons.net.ftp.FTPClientConfig;
import org.apache.commons.net.ftp.FTPFile;

public class V900R012FTPEntryParser extends ConfigurableFTPFileEntryParserImpl
{
  private static final String DEFAULT_DATE_FORMAT = "MM-dd-yy HH:mm";
  private static final String REGEX = "(\\S+)\\s+(\\S+)\\s+(\\S+)\\s+(\\S+/?)\\s*";

  public V900R012FTPEntryParser()
  {
    this(null);
  }

  public V900R012FTPEntryParser(FTPClientConfig config) {
    super("(\\S+)\\s+(\\S+)\\s+(\\S+)\\s+(\\S+/?)\\s*");
    configure(config);
  }

  public FTPFile parseFTPEntry(String entry) {
    FTPFile file = new FTPFile();
    file.setRawListing(entry);

    if (matches(entry)) {
      String datestr = group(1) + " " + group(2);
      String dirFlag = group(3);
      String filesize = "";
      int type;
      if (dirFlag.contains("<DIR>")) {
        type = 1;
        filesize = "0";
      } else {
        type = 0;
        filesize = group(3);
      }

      String name = group(4);
      try {
        file.setTimestamp(super.parseTimestamp(datestr));
      } catch (ParseException e) {
        return null;
      }

      file.setType(type);
      try {
        file.setSize(Long.parseLong(filesize));
      }
      catch (NumberFormatException e) {
      }
      if (name.endsWith("/")) {
        name = name.substring(0, name.length() - 1);
      }

      int pos = name.lastIndexOf('/');
      if (pos > -1) {
        name = name.substring(pos + 1);
      }

      file.setName(name);

      return file;
    }
    return null;
  }

  protected FTPClientConfig getDefaultConfiguration() {
    return new FTPClientConfig("OS/400", "MM-dd-yy HH:mm", null, null, null, null);
  }
}

 

转载于:https://my.oschina.net/caiyuan/blog/33112

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值