ftp工具类

文章目录

            • 1.依赖
            • 2. 工具类
            • 2. 业务处理类

1.依赖
 <dependency><groupId>com.alibaba</groupId><artifactId>fastjson</artifactId><version>1.2.56</version></dependency><dependency><groupId>commons-net</groupId><artifactId>commons-net</artifactId><version>3.3</version></dependency>
2. 工具类
package com.example.demo.util;import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPFile;
import org.springframework.stereotype.Component;import java.io.*;
import java.nio.charset.Charset;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;/*** ftp文件上传工具类*/
@Component
public class FTPFileProUtils {/*** 远程ftp服务器的ip、端口号、用户名、口令*/private static String hostname = "192.168.xxx.131";private static int port = 21;private static String username = "myftp";private static String password = "myftp";private static String mInRConnFilePath = "/app/data/20181126/";private static String mOutRConnFilePath = "/app/data/xml/LP00000001/20181126/";/*** */private FTPClient client;/*** 创建Ftp客户端对象,开启ftp链接请求对象* * @return FTPClient对象* @throws Exception*/public void initFtpClient() throws Exception {// 2.1 创建Ftp客户端, 相当于开启ftp客户端软件.client = new FTPClient();// 设置字符集, 设置上传文件体的字符集.client.setCharset(Charset.forName("UTF-8"));// 设置为被动连接迷失client.enterLocalPassiveMode();// 2.2 连接服务器, 抛出异常. 服务器找不到.client.connect(hostname, port);// 2.3 登录client.login(username, password);// 2.5 设置要上传的文件类型, 设置二进制文件类型client.setFileType(FTP.BINARY_FILE_TYPE);// return client;}// Switching pathpublic void changeWorkingDirectory(String pathname) {try {client.changeWorkingDirectory(pathname);} catch (IOException e) {e.printStackTrace();}}/*** 创建Ftp客户端对象,开启ftp链接请求对象* * @return FTPClient对象* @throws Exception*/public void initFtpClientPara(String hostname, int port, String username, String password) throws Exception {// 2.1 创建Ftp客户端, 相当于开启ftp客户端软件.client = new FTPClient();// 设置字符集, 设置上传文件体的字符集.client.setCharset(Charset.forName("UTF-8"));// 设置为被动连接迷失client.enterLocalPassiveMode();// 2.2 连接服务器, 抛出异常. 服务器找不到.client.connect(hostname, port);// 2.3 登录client.login(username, password);// 2.5 设置要上传的文件类型, 设置二进制文件类型client.setFileType(FTP.BINARY_FILE_TYPE);// return client;}/*** 将用户上传的文件或图片,保存到ftp服务器上* * @param uploadFile    : 上传的文件(二进制流)* @param makeDirectory : 保存到的文件夹路径(基于ftp根路径)* @return ResponseResult.code == '0' : 上传失败;<br/>*         ResponseResult.code == '1' : 上传成功,其中:ResponseResult.data为保存的文件新名称*/public void fileUpload(InputStream in, String makeDirectory, String newFileName) {try {boolean isChanged = client.changeWorkingDirectory(makeDirectory);String s = client.printWorkingDirectory();System.out.println(s);if (!isChanged) {// 切换失败. 可能目录不存在, 返回创建是否成功.if (client.makeDirectory(new String(makeDirectory.getBytes("UTF-8"), "UTF-8"))) {// 如果创建成功. 切换目录client.changeWorkingDirectory(makeDirectory);} else {}}// storeFile(String 远程文件名称, InputStream 上传的文件输入流);client.enterLocalPassiveMode();boolean isSuccess = client.storeFile(new String(newFileName.getBytes("UTF-8"), "iso-8859-1"), in);System.out.println(isSuccess);} catch (Exception e) {// 异常问题System.out.println("异常问题 : " + e.getMessage());System.out.println("-------------文件上传方法结束-------------");}}/*** 从ftp服务器上,读取文件,并将文件的输入流返回* * @param makeDirectory : 要读取文件的文件路径(父目录)* @param fileName      : 要读取文件的名称* @return ResponseResult.code == '0' : 读取失败;<br/>*         ResponseResult.code == '1' : 读取成功,其中:ResponseResult.data为文件的输入流对象*/public ByteArrayInputStream getByteArrayInputStream(String makeDirectory, String fileName) {// 设置方法返回值ByteArrayInputStream inStream = null;// 1. 确定文件上传为有效文件.if (fileName == null || "".equals(fileName)) {System.out.println("文件名称不能为空");return null;}try {// 创建Ftp客户端对象,开启ftp链接请求对象System.out.println("Ftp客户端对象:client = " + client);// 切换工作目录, 参数为相对于当前工作目录的相对路径.登录的时候,当前目录为登录用户的主目录.boolean isChangedFlag = true;if (isChangedFlag) { // 如果文件目录更换成功// 将ftp设置为被动连接迷失client.enterLocalPassiveMode();// 通过ftp读取目标文件,并将目标文件写入到输出流ByteArrayOutputStrem对象outStream中ByteArrayOutputStream outStream = new ByteArrayOutputStream();// System.out.println("创建输出流对象:outStream = "+outStream);client.retrieveFile(fileName, outStream);// System.out.println("从ftp上写入输出流:outStream = "+outStream);inStream = new ByteArrayInputStream(outStream.toByteArray());System.out.println("输入流:ByteArrayInputStream:inStream = " + inStream);}// 关闭ftp客户端// client.logout();} catch (Exception e) {// 异常问题e.printStackTrace();System.out.println("操作异常:获取文件输入流失败");}return inStream;}/*** 切换工作目录* * @param directory*/public void changeDir(String path) {if (path != null && !"".equals(path)) {try {client.changeWorkingDirectory(new String(path.getBytes("UTF-8"), "UTF-8"));} catch (UnsupportedEncodingException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();}}}/*** 创建一个文件夹* * @param makeDirectory*/public void makeDir(String makeDirectory) {try {boolean isChanged = client.changeWorkingDirectory(makeDirectory);// String s = client.printWorkingDirectory();// System.out.println(s);if (!isChanged) {// 切换失败. 可能目录不存在, 返回创建是否成功.if (client.makeDirectory(new String(makeDirectory.getBytes("UTF-8"), "UTF-8"))) {// 如果创建成功. 切换目录client.changeWorkingDirectory(makeDirectory);} else {}}} catch (IOException e) {e.printStackTrace();}}/*** 打印出当前工作目录*/public void printWorkDir() {try {System.out.println(client.printWorkingDirectory());} catch (IOException e) {e.printStackTrace();}}/*** @param path* @return function:读取指定目录下的文件名* @throws IOException*//*** 获取FTP目录下面指定的文件* * @param path* @return* @throws ParseException*/public List<String> getFTPDirSpecifiedFile(String path, String fileName) throws ParseException {List<String> fileLists = new ArrayList<String>();// 获得指定目录下所有文件名FTPFile[] ftpFileList = null;try {ftpFileList = client.listFiles(path);} catch (IOException e) {e.printStackTrace();}if (ftpFileList != null && ftpFileList.length > 0) {for (int i = 2; i < ftpFileList.length; i++) {FTPFile file = ftpFileList[i];if (file.isFile()) {if (file.getName().equals(fileName)) {System.out.println("文件夹下面的文件=====:" + file.getName());fileLists.add(file.getName());}}}}return fileLists;}/*** 获取FTP目录下面指定的文件* * @param path* @return* @throws ParseException*/public List<String> getFTPCurrentDateDirSpecifiedFile(String path, String fileName) throws ParseException {List<String> fileLists = new ArrayList<String>();// 获得指定目录下所有文件名FTPFile[] ftpFileList = null;try {ftpFileList = client.listFiles(path);} catch (IOException e) {e.printStackTrace();}if (ftpFileList != null && ftpFileList.length > 0) {System.out.println("ftpFileList.length:" + ftpFileList.length);for (int i = 0; i < ftpFileList.length; i++) {FTPFile file = ftpFileList[i];if (file.isFile()) {if (file.getName().equals(fileName)) {System.out.println("文件夹下面的文件=====:" + file.getName());fileLists.add(file.getName());}}}}return fileLists;}/*** 获取FTP目录下面所有文件* * @param path* @return* @throws ParseException*/public List<String> getFTPDirAllFileList(String path) throws ParseException {List<String> fileLists = new ArrayList<String>();// 获得指定目录下所有文件名FTPFile[] ftpFileList = null;try {ftpFileList = client.listFiles(path);} catch (IOException e) {e.printStackTrace();}if (ftpFileList != null && ftpFileList.length > 0) {for (int i = 2; i < ftpFileList.length; i++) {FTPFile file = ftpFileList[i];if (file.isFile()) {System.out.println("文件夹下面的文件=====:" + file.getName());fileLists.add(file.getName());}}}return fileLists;}/*** 获取FTP目录当前日期下面所有文件* * @param remotePath* @return* @throws ParseException*/public List<String> getFTPCurrentDateDirAllFileList(String remotePath) throws ParseException {List<String> fileLists = new ArrayList<String>();// 获得指定目录下所有文件名FTPFile[] ftpFileList = null;try {ftpFileList = client.listFiles(remotePath);} catch (IOException e) {e.printStackTrace();}if (ftpFileList != null && ftpFileList.length > 0) {for (int i = 0; i < ftpFileList.length; i++) {FTPFile file = ftpFileList[i];if (file.isFile()) {System.out.println("文件夹下面的文件=====:" + file.getName());fileLists.add(file.getName());}}}return fileLists;}/*** 获取目录下面的某个类型的文件* * @param path* @return* @throws ParseException*/public List<String> getFTPDirTypeFileList(String path, String fileType) throws ParseException {List<String> fileLists = new ArrayList<String>();// 获得指定目录下所有文件名FTPFile[] ftpFileList = null;try {ftpFileList = client.listFiles(path);} catch (IOException e) {e.printStackTrace();}if (ftpFileList != null && ftpFileList.length > 0) {for (int i = 2; i < ftpFileList.length; i++) {FTPFile file = ftpFileList[i];if (file.isFile()) {System.out.println("文件夹下面的文件=====:" + file.getName());// "suffix后缀在类中定全局变量,从数据库中取值"if (file.getName().endsWith(fileType)) {fileLists.add(file.getName());}}}}return fileLists;}/*** 获取目录下面的某个类型的文件* * @param path* @return* @throws ParseException*/public List<String> getFTPCurrentDateDirTypeFile(String path, String fileType) throws ParseException {List<String> fileLists = new ArrayList<String>();// 获得指定目录下所有文件名FTPFile[] ftpFileList = null;try {ftpFileList = client.listFiles(path);} catch (IOException e) {e.printStackTrace();}if (ftpFileList != null && ftpFileList.length > 0) {for (int i = 2; i < ftpFileList.length; i++) {FTPFile file = ftpFileList[i];if (file.isFile()) {System.out.println("文件夹下面的文件=====:" + file.getName());// "suffix后缀在类中定全局变量,从数据库中取值"if (file.getName().endsWith(fileType)) {fileLists.add(file.getName());}}}}return fileLists;}/*** 原版支持文件和目录 传输目录下面的文件 大小为0kb 编码文件 需要解决这2个问题* * @param path* @return* @throws ParseException*/public List<String> getFileList2(String path) throws ParseException {List<String> fileLists = new ArrayList<String>();// 获得指定目录下所有文件名FTPFile[] ftpFileList = null;try {ftpFileList = client.listFiles(path);} catch (IOException e) {e.printStackTrace();}if (ftpFileList != null && ftpFileList.length > 0) {for (int i = 2; i < ftpFileList.length; i++) {FTPFile file = ftpFileList[i];if (file.isFile()) {System.out.println("文件夹下面的文件=====:" + file.getName());fileLists.add(file.getName());}}}return fileLists;}/*** 关闭ftp连接*/public void closeClient() {try {// 2.7 退出登录, 相当于回收了资源client.logout();// 2.8 回收资源, 回收资源方法和退出登录方法.可以选择其一执行.
//			client.quit();} catch (IOException e) {e.printStackTrace();}}/*** 删除目录下的所有文件* * @param pathname*/public void delDirAllFile(String pathname) {try {client.deleteFile(pathname);} catch (IOException e) {e.printStackTrace();}}public FTPClient getClient() {return client;}public void setClient(FTPClient client) {this.client = client;}public static String getmInRConnFilePath() {return mInRConnFilePath;}public static void setmInRConnFilePath(String mInRConnFilePath) {FTPFileProUtils.mInRConnFilePath = mInRConnFilePath;}public static String getmOutRConnFilePath() {return mOutRConnFilePath;}public static void setmOutRConnFilePath(String mOutRConnFilePath) {FTPFileProUtils.mOutRConnFilePath = mOutRConnFilePath;}public static String getHostname() {return hostname;}public static void setHostname(String hostname) {FTPFileProUtils.hostname = hostname;}public static int getPort() {return port;}public static void setPort(int port) {FTPFileProUtils.port = port;}public static String getUsername() {return username;}public static void setUsername(String username) {FTPFileProUtils.username = username;}public static String getPassword() {return password;}public static void setPassword(String password) {FTPFileProUtils.password = password;}
}
2. 业务处理类
package com.example.demo.util;import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.InputStream;
import java.text.ParseException;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;/*** Http File Transfer Service Class** @author guobin* @date 2018.11.26*/
@Service // 注册bean
@Transactional // 开启事务
public class HttpFTPServiceImpl implements HttpFTPService {private static Logger log = Logger.getLogger(HttpFTPServiceImpl.class);private String mUUID;private String mTransCode = "";private String mTransType = "";private String mFileName = "";private String mSouFilePath = "";private String mDesFilePath = "";private String jsonString = "";private JSONObject jsonObject = null;// 初始化轨迹表参数private int mUploadallnum = 0;// 文件总数private int mFilesuccnum = 0;// 上传成功文件数private int mFilefailnum = 0;// 上传失败文件数private Date tStartDate = null;private Date tEndDate = null;private String mINRConnIP = "192.168.xxx.145";private int mInRConnPort=21;private String mInRConnUser = "username";private String mInRConnPWD = "passwd";private String mOutRConnIP = "";private int mOutRConnPort;private String mOutRConnUser = "";private String mOutRConnPWD = "";// FTP Connection Entry Tool Class IntroductionFTPFileProUtils ftpOut = new FTPFileProUtils();FTPFileProUtils ftpIn = new FTPFileProUtils();Map<String, Object> map = new HashMap<String, Object>();@AutowiredHttpServletRequest httpRequest;@Autowiredprivate FisftpinoutparainfoMapper fisftpinoutparainfoMapper;Fisftpcallingtrace mFisftpcallingtrace = new Fisftpcallingtrace();// 请求轨迹实体类@Overridepublic String commonRequests(HttpServletRequest paramRequest, HttpServletResponse paramResponse,String paramRequestBody) throws Exception {log.info("Receive HttpRequest:!!!");try {jsonObject = JSONObject.parseObject(paramRequestBody);} catch (Exception e) {log.info("Request parameter format error, parse exception");// 请求错误处理jsonString = requestErrorDeal();return jsonString;}mTransCode = jsonObject.getString("TransCode");// 业务类型mTransType = jsonObject.getString("TransType");// 交易方式 0-单笔 1-批量mSouFilePath = jsonObject.getString("SouFilePath");// 源路径mDesFilePath = jsonObject.getString("DesFilePath");// 目标路径mFileName = jsonObject.getString("FileName");// 文件名log.info("业务类型mTransCode:" + mTransCode);log.info("交易方式mTransType:" + mTransType);log.info("源路径mSouFilePath:" + mSouFilePath);log.info("目标路径mDesFilePath:" + mDesFilePath);log.info("文件名mFileName:" + mFileName);if (mTransType.equals("1") && mTransType != null) {// Get FTP parameter informationgetFTPInOutPara(mTransCode);// Remote Read Write Current Date Dir All FileremoteReadWriteCurrentDateDirAllFile();// Set file mTransTypemFisftpcallingtrace.setTranstype("1");} else if (mTransType.equals("0") && mTransType != null) {// Get FTP parameter informationgetFTPInOutPara(mTransCode);// Remote Read Write Current Dir Specified FileremoteReadWriteCurrentDateDirAppointFile();// Set file flagmFisftpcallingtrace.setTranstype("0");} else {log.info("This business type is not supported!!!:");}log.info("fis执行处理完毕!!!:");return jsonString;}/*** Remote Read Write Current Date Dir All File*/private String remoteReadWriteCurrentDateDirAllFile() {try {// Connecting Common MethodsconnectingCommon();// Get all files in directoryList<String> fileNames = ftpOut.getFTPCurrentDateDirAllFileList(mSouFilePath);if (fileNames.size() == 0) {// 原路径无符合条件的文件处理jsonString = mSouFilePathErrorDeal();return jsonString;}// Number of printed fileslog.info("fileNames.length : " + fileNames.size());// Total number of documentsmUploadallnum = fileNames.size();mFisftpcallingtrace.setUploadallnum(String.valueOf(mUploadallnum));if (fileNames != null) {for (String fileName : fileNames) {log.info("File name under directory : " + fileName);InputStream in = ftpOut.getByteArrayInputStream(mSouFilePath, fileName);tStartDate = new Date();ftpIn.fileUpload(in, mDesFilePath, fileName);tEndDate = new Date();}}// Successful number of documents// Common Variables In TrajectorycommonVariablesInTrajectory(mDesFilePath);ResponseSuccRecordTrajectory(tStartDate, tEndDate);
//			int i =1/0;} catch (Exception e) {log.info("文件批量传输异常!!!");// 文件批量传输异常处理jsonString = FileTransferExceptionDeal(mUploadallnum, mFilesuccnum, mFilefailnum);return jsonString;} finally {// Quit logon and recycle resourcesftpIn.closeClient();ftpOut.closeClient();}return jsonString;}/*** Remote Read Write Current Date Dir Appoint File*/private String remoteReadWriteCurrentDateDirAppointFile() {try {// Connecting Common MethodsconnectingCommon();// Get all files in directoryList<String> fileNames = ftpOut.getFTPCurrentDateDirSpecifiedFile(mSouFilePath, mFileName);if (fileNames.size() == 0) {// 原路径无符合条件的文件处理jsonString = mSouFilePathErrorDeal();return jsonString;}// Number of printed fileslog.info("fileNames.length : " + fileNames.size());// Total number of documentsmUploadallnum = fileNames.size();mFisftpcallingtrace.setUploadallnum(String.valueOf(mUploadallnum));if (fileNames != null) {for (String fileName : fileNames) {log.info("File name under directory : " + fileName);InputStream in = ftpOut.getByteArrayInputStream(mSouFilePath, fileName);tStartDate = new Date();ftpIn.fileUpload(in, mDesFilePath, fileName);tEndDate = new Date();}}// Successful number of documents// Common Variables In TrajectorycommonVariablesInTrajectory(mDesFilePath);ResponseSuccRecordTrajectory(tStartDate, tEndDate);
//			int i =1/0;} catch (Exception e) {log.info("文件单笔读写出现异常");// 文件单笔读写出现异常处理jsonString = FileTransferExceptionDeal(mUploadallnum, mFilesuccnum, mFilefailnum);return jsonString;} finally {// Quit logon and recycle resourcesftpIn.closeClient();ftpOut.closeClient();}return jsonString;}/****************** Successful Part Encapsulation Start **********************//*** 1.Track success record 2.Return successful response** @param tStartDate* @param tEndDate* @return*/private String ResponseSuccRecordTrajectory(Date tStartDate, Date tEndDate) {// Success Trajectory Common VariableSuccessTrajectoryCommonVariable(tStartDate, tEndDate);map.put("ResultCode", "0");map.put("ResultMsg", "处理成功");jsonObject = JSONObject.parseObject(JSON.toJSONString(map));jsonString = JSON.toJSONString(jsonObject);return jsonString;}/*** Trajectory common variable** @param tStartDate* @param tEndDate*/private void SuccessTrajectoryCommonVariable(Date tStartDate, Date tEndDate) {mUUID = (String) httpRequest.getAttribute(TraceEntity.Trace_UUID);mFisftpcallingtrace.setTraceid(mUUID);mFisftpcallingtrace.setServicename("File transfer platform");mFisftpcallingtrace.setTranscode(mTransCode);mFisftpcallingtrace.setServicetype(TraceEntity.Trace_HttpType);mFisftpcallingtrace.setTranstype(mTransType);mFisftpcallingtrace.setReqip(httpRequest.getLocalAddr());mFilefailnum = mUploadallnum - mFilesuccnum;mFisftpcallingtrace.setFilefailnum(String.valueOf(mFilefailnum));mFisftpcallingtrace.setReqstatus("1");mFisftpcallingtrace.setReqdate(DateUtil.getyyyyMMddDate(tStartDate));mFisftpcallingtrace.setReqtime(DateUtil.getTimeFormat(tStartDate));mFisftpcallingtrace.setHandledate(DateUtil.getyyyyMMddDate(tEndDate));mFisftpcallingtrace.setHandletime(DateUtil.getTimeFormat(tEndDate));httpRequest.setAttribute("FTPTrace", mFisftpcallingtrace);}/****************** Successful partial encapsulation End **********************//****************** Public Part Encapsulation Start **********************//*** External And Intranet Network FTP Parameters** @param mTransCode*/private void getFTPInOutPara(String mTransCode) {Fisftpinoutparainfo ftpInOutParaInfo = fisftpinoutparainfoMapper.selectByPrimaryKey(mTransCode);mINRConnIP = ftpInOutParaInfo.getFtpinrconnip();mInRConnPort = ftpInOutParaInfo.getFtpinrconnport();mInRConnUser = ftpInOutParaInfo.getFtpinrconnuser();mInRConnPWD = ftpInOutParaInfo.getFtpinrconnpwd();mOutRConnIP = ftpInOutParaInfo.getFtpoutrconnip();mOutRConnPort = ftpInOutParaInfo.getFtpoutrconnport();mOutRConnUser = ftpInOutParaInfo.getFtpoutrconnuser();mOutRConnPWD = ftpInOutParaInfo.getFtpoutrconnpwd();}/*** Connecting common methods** @throws Exception*/private void connectingCommon() throws Exception {// OutNetWork ConnectFTPftpOut.initFtpClientPara(mOutRConnIP, mOutRConnPort, mOutRConnUser, mOutRConnPWD);// InNetWork ConnectFTPftpIn.initFtpClientPara(mINRConnIP, mInRConnPort, mInRConnUser, mInRConnPWD);// Print out the current working directoryftpOut.printWorkDir();ftpIn.printWorkDir();// Switch working directoryftpOut.changeDir(mSouFilePath);ftpIn.changeDir(mDesFilePath);// Print out the current working directoryftpOut.printWorkDir();ftpIn.printWorkDir();}/*** Common Variables In Trajectory** @param mDesFilePath*/public void commonVariablesInTrajectory(String mDesFilePath) {List<String> ftpInDirAllFileList;try {ftpInDirAllFileList = ftpIn.getFTPCurrentDateDirAllFileList(mDesFilePath);mFilesuccnum = ftpInDirAllFileList.size();mFisftpcallingtrace.setFilesuccnum(String.valueOf(mFilesuccnum));mFisftpcallingtrace.setResstatus("0");mFisftpcallingtrace.setResremark("文件上传成功");} catch (ParseException e) {e.printStackTrace();}}/****************** Public part encapsulation End **********************//****************** Abnormal Part Encapsulation Start **********************//*** 请求错误,返回响应** @return*/private String requestErrorDeal() {map.put("ResultCode", "1");map.put("ResultMsg", "请求参数格式不符合规约要求,请核实!!!");jsonObject = JSONObject.parseObject(JSON.toJSONString(map));jsonString = JSON.toJSONString(jsonObject);return jsonString;}/*** 原路径文件为空,返回响应** @return*/private String mSouFilePathErrorDeal() {map.put("ResultCode", "1");map.put("ResultMsg", "原路径中无符合条件的文件,请核实文件是否存在!!!");jsonObject = JSONObject.parseObject(JSON.toJSONString(map));jsonString = JSON.toJSONString(jsonObject);return jsonString;}/*** File Transfer Exception** @return*/private String FileTransferExceptionDeal(int mUploadallnum, int mFilesuccnum, int mFilefailnum) {tStartDate = new Date();tEndDate = new Date();FileReadAndWriteExceptionTrajectoryRecord(tStartDate, tEndDate, mUploadallnum, mFilesuccnum, mFilefailnum);map.put("ResultCode", "1");map.put("ResultMsg", "由于文件格式不符合规约要求,文件读写异常,请检查文件格式!!!");jsonObject = JSONObject.parseObject(JSON.toJSONString(map));jsonString = JSON.toJSONString(jsonObject);return jsonString;}/*** FileReadAndWriteException** @param tStartDate* @param tEndDate* @param mUploadallnum* @param mFilesuccnum* @param mFilefailnum*/private void FileReadAndWriteExceptionTrajectoryRecord(Date tStartDate, Date tEndDate, int mUploadallnum,int mFilesuccnum, int mFilefailnum) {mFisftpcallingtrace.setResremark("文件格式格式不符合规约要求,请核实!!!");CommonVariablesOfAbnormalTrajectories(tStartDate, tEndDate, mUploadallnum, mFilesuccnum, mFilefailnum);}/*** Common Variables of Abnormal Trajectories** @param tStartDate* @param tEndDate* @param mUploadallnum* @param mFilesuccnum* @param mFilefailnum*/private void CommonVariablesOfAbnormalTrajectories(Date tStartDate, Date tEndDate, int mUploadallnum,int mFilesuccnum, int mFilefailnum) {mUUID = (String) httpRequest.getAttribute(TraceEntity.Trace_UUID);mFisftpcallingtrace.setTraceid(mUUID);mFisftpcallingtrace.setServicename("File transfer platform");mFisftpcallingtrace.setServicetype(TraceEntity.Trace_HttpType);mFisftpcallingtrace.setReqip(httpRequest.getLocalAddr());mFisftpcallingtrace.setTranscode(mTransCode);mFisftpcallingtrace.setTranstype(mTransType);mFisftpcallingtrace.setUploadallnum(String.valueOf(mUploadallnum));mFilefailnum = mUploadallnum - mFilesuccnum;mFisftpcallingtrace.setFilesuccnum(String.valueOf(mFilesuccnum));mFisftpcallingtrace.setFilefailnum(String.valueOf(mFilefailnum));mFisftpcallingtrace.setReqstatus("1");mFisftpcallingtrace.setResstatus("1");mFisftpcallingtrace.setReqdate(DateUtil.getyyyyMMddDate(tStartDate));mFisftpcallingtrace.setReqtime(DateUtil.getTimeFormat(tStartDate));mFisftpcallingtrace.setHandledate(DateUtil.getyyyyMMddDate(tEndDate));mFisftpcallingtrace.setHandletime(DateUtil.getTimeFormat(tEndDate));httpRequest.setAttribute("FTPTrace", mFisftpcallingtrace);}/****************** Abnormal Part Encapsulation End **********************/
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/519402.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

java调用qq接口_用java代码怎么去请求腾讯接口并返回值

这是参看代码&#xff0c;你看一下&#xff0c;里面的HttpClient包你要自己去下public static void main(String[] args) {CloseableHttpClient httpclient HttpClients.createDefault();String url "http://m.weather.com.cn/data/101200101.html";URI uri URI.c…

刚发布!新型病毒下,程序员可在家免费学习了!

亲爱的CSDN家人们&#xff1a;疫情当前&#xff0c;这个春节有点“寒”。截止1月31号24时&#xff0c;新型冠状病毒在全国已确诊11791名&#xff08;数字取自&#xff1a;人民日报8:40分发布信息&#xff09;&#xff0c;疑似病例已1w&#xff0c;受其影响&#xff0c;全国各地…

阿里巴巴的微服务开源之路

2019阿里云峰会北京开发者专场 侠之大者&#xff0c;为国为民。 在金庸小说中&#xff0c;郭靖和黄蓉是“侠之大者&#xff0c;为国为民”的典范&#xff0c;他们以布衣之身帮助宋军守护襄阳十余年。 技术的世界里&#xff0c;并无大小之分。 但当一群程序员由服务公司内部…

一文纵览自然语言生成的发展

人们对人工智能的兴趣随着科幻电影的诞生和发展变得愈发浓厚。每当我们听到“人工智能”这个词&#xff0c;便会联想到《终结者》、《黑客帝国》、《我&#xff0c;机器人》等电影。 机器人具有独立思考的能力在目前看来还比较遥远&#xff0c;但机器学习和自然语言理解领域已经…

java生成html表格数据_使用Java将表格数据导出成Excel格式

前言&#xff1a;本文使用后台处理的办法导出前端表格中显示的数据。引入依赖org.apache.poipoi3.17书写PoiUtilspublic classPoiUtils {public static ResponseEntity exportExcel(List marketList) throwsIOException {HttpHeaders headersnull;//创建文档HSSFWorkbook workb…

sftp 工具类

<!--sftp操作工具类--><dependency><groupId>com.jcraft</groupId><artifactId>jsch</artifactId><version>0.1.54</version></dependency>package com.example.demo.util;import com.jcraft.jsch.*; import lombok.ext…

基于机器学习场景,如何搭建特征数据管理中台?

「免费学习 60 节公开课&#xff1a;投票页面&#xff0c;点击讲师头像」作者 | 陈迪豪&#xff0c;第四范式资深架构师编辑 | Jane来源 | AI科技大本营&#xff08;ID&#xff1a;rgznai100&#xff09;一、机器学习场景与高性能特征管理中台理想的机器学习场景是给到数据&…

十年再出发!阿里云智能总裁张建锋演讲全记录

3月21日&#xff0c;“十年再出发”阿里云峰会于国家会议中心正式召开。阿里云智能总裁张建锋&#xff08;行癫&#xff09;携核心管理团队首次悉数亮相&#xff0c;并对阿里云做了全面的战略解读。以下是演讲全文。 张建锋&#xff1a;今天是我们阿里云智能升级之后第一次和大…

文件解析工具类

package com.example.demo.util;import lombok.extern.slf4j.Slf4j;import java.io.*; import java.util.ArrayList; import java.util.List;/*** 文件解析公共工具类** author gblfy* date 2020-10-13*/ Slf4j public class FileUtil {//------------------------------------…

java简单题目_Java考点知识简单练习题

Java考点知识简单练习题Java 技术具有卓越的通用性、高效性、平台移植性和安全性&#xff0c;广泛应用于PC、数据中心、游戏控制台、科学超级计算机、移动电话和互联网&#xff0c;同时拥有全球最大的开发者专业社群。下面是小编为大家搜索整理的java考试强化训练题&#xff0c…

数据科学家为什要用Git?怎么用?

也许你在别的地方听说过Git。也许有人告诉过你&#xff0c;Git只适合软件开发人员。如果你是数据科学家&#xff0c;那么Git其实对你很重要。本文作者希望能够通过经验分享让你了解Git的重要性&#xff0c;以及如何在你的数据科学工作中使用它。 什么是Git&#xff1f; Git是…

抗疫进展:多家科研机构联合筛选出五种可能有效的抗病毒药物

2月3日&#xff0c;华中科技大学同济医学院基础医学院、华中科技大学同济医学院附属武汉儿童医院、西安交通大学第一附属医院、中科院北京基因组研究所、华为云联合科研团队宣布&#xff0c;筛选出五种可能对2019新型冠状病毒&#xff08;2019-nCoV&#xff09;有效的抗病毒药物…

GAN的一些很酷的应用

在GAN发展的最初几年里&#xff0c;我们取得了令人瞩目的进展。当然&#xff0c;现在不会是像恐怖电影里那样有邮票大小的面部照片了。2017年&#xff0c;Gan制作了10241024张能愚弄人才童子军的照片。在未来几年&#xff0c;我们可能会看到GAN生成的高质量视频&#xff0c;由此…

ant压缩和解压缩工具类

<!--文件压缩和解压工具类--><dependency><groupId>org.apache.ant</groupId><artifactId>ant</artifactId><version>1.7.1</version></dependency>package com.example.demo.util;import lombok.extern.slf4j.Slf4j; i…

java项目短信群发接口_JAVA实现第三方短信发送过程详解

想使代码生效需要注册&#xff1a;在muven项目里面导入jar包commons-codeccommons-codec1.4commons-httpclientcommons-httpclient3.1commons-loggingcommons-logging1.1.1org.apache.httpcomponentshttpclient4.3.1com.alibabadruid1.0.8com.alibabadruid1.0.8创建一个测试类&…

两亿人在家开会!钉钉紧急扩容1万台云服务器

2月3日是一个特殊的开工日&#xff0c;为防范疫情&#xff0c;在阿里巴巴钉钉上有超过1000万家企业组织的2亿上班族在线开工。为支持此次史无前例的办公需求&#xff0c;钉钉在阿里云上紧急扩容1万台云服务器来保障钉钉视频会议、群直播、办公协同等功能&#xff0c;保障用户流…

这些数据科学家必备的技能,你拥有哪些?

1.教育背景 88&#xff05;的数据科学家受过高等教育且拥有硕士学位&#xff0c;其中46&#xff05;拥有博士学位。虽然有些人是例外&#xff0c;但通常需要非常强大的教育背景才能拥有成为数据科学家所必需的知识深度。要想成为数据科学家&#xff0c;你可以先获得计算机科学、…

JAVA将ResultSet结果集遍历到List中

今天在使用jstl标签展示查询结果时遇到一个小问题&#xff0c;即如何将ResultSet对象传递给前台页面。 在默认情况中我们在使用数据库查询时 public List selectDataFromJdbc() throws SQLException, ClassNotFoundException {Class.forName("oracle.jdbc.driver.OracleD…

阿里敏捷教练:多团队开发一个产品的组织设计和思考

Scrum等敏捷开发框架&#xff0c;最初都是为5到9人的小团队设计的。通过保持专注和合理利用新技术&#xff0c;在相当长的时间里小团队仍然可以支撑业务发展。 随着业务成长&#xff0c;小团队的产出可能跟不上业务需要&#xff0c;团队就会面临规模化的问题。从1个团队拓展到…

10个你应该了解的Git命令(以及Git省时小窍门)

在本文中&#xff0c;我们将讨论那些作为开发人员、数据科学家或产品经理应该知道的各种各样的Git命令。并且将使用Git查看、删除和整理。此外&#xff0c;我们还将介绍如何使用Bash别名和Git编辑器配置转义Vim和节省时间的方法。 如果你不熟悉基本的git命令&#xff0c;那么在…