//FTP连接省略.......
long secound[] = {4,3,2,1};
int i = 0;
//记录循环次数
while(null != ftpUtil && null != ftpUtil.getBsFtpPath()){
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHH24mmss");
String strDate = sdf.format(new Date());
int num = (int) (Math.random()*9000+1000);
InputStream iptStream = ftpUtil.readRemote("simple_"+strDate+num);
int len = 0;
int tmp = 0;
byte []b = new byte[1024];
while((tmp = iptStream.read()) != -1){
b[len] = (byte) tmp; len++;
}
String str = new String(b,0,len);
if(StringUtils.isNotBlank(str)){
JSONArray jsonArray = JSONArray.fromString(str);
if(jsonArray.length() > 0 && jsonArray != null){
JSONObject jsonObj = (JSONObject) jsonArray.get(0);
if(jsonObj.length() > 0 && jsonObj != null){
List list = new ArrayList();
for(int k=0;k<jsonObj.length();k++){
Map map = new HashMap();
map.put("xm", jsonObj.getString("XM"));
map.put("cert", jsonObj.getString("SFZH"));
list.add(map); return ; } } } }
Thread.sleep(secound[i] * 1000);
if(secound[i]==1){
//当i等于1循环结束,并且报错超时
Exception();//超时错误提示结束
return; } i++; } }
以json格式的解析FTP上的文件,10秒超时
最新推荐文章于 2021-08-05 08:14:34 发布