Java 下载队列并对文件进行MD5校验,可获取文件名可分不同时间段进行下载

package cn.com.ebidding.impl.outer.trading;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLDecoder;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Vector;

import org.apache.commons.io.IOUtils;
import org.net.plat4j.common.utils.AppConfig;
import org.net.plat4j.common.utils.FileUtil;
import org.net.plat4j.sr.core.utils.LogHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.com.ebidding.api.outer.trading.ITradingPlatformFile;
import cn.com.ebidding.web.mapper.PTradingfileinfoMapper;
import cn.com.ebidding.web.model.PTradingfileinfo;

@Service("ITradingPlatformFile")
public class TradingPlatformFileService implements ITradingPlatformFile {

	public final static boolean DEBUG = true;// 调试用
	@SuppressWarnings("unused")
	private static int BUFFER_SIZE = 8096;// 缓冲区大小
	@SuppressWarnings("rawtypes")
	private Vector vPTradingfileinfo = new Vector();// 下载信息

	private static final LogHelper log = new LogHelper(TradingPlatformFileService.class);
	
	@Autowired
	private PTradingfileinfoMapper mapper;
	
	/**
	 * 构造方法
	 */
	public TradingPlatformFileService() {
		log.info("*********************************** 进入交易平台附件下载 ***********************************");
	}

	/**
	 * 清除下载列表
	 */
	public void resetList() {
		log.info("清除下载列表");
		vPTradingfileinfo.clear();
	}

	/**
	 * 增加下载列表项
	 *
	 * @param url
	 *            String
	 * @param filename
	 *            String
	 */
	@SuppressWarnings("unchecked")
	public void addItem(PTradingfileinfo pTradingfileinfo) {
		log.info("添加下载列表:" + pTradingfileinfo.getFileurl() + "   fileVeriCode:" + pTradingfileinfo.getFilevericode());
		vPTradingfileinfo.add(pTradingfileinfo);
	}

	public String getFileName(String urlStr){
		String fileName = null;
		try {
			URL url = new URL(urlStr);
	        URLConnection uc = url.openConnection();
	        fileName = uc.getHeaderField("Content-Disposition");
	        fileName = new String(fileName.getBytes("ISO-8859-1"), "GBK");
	        fileName = URLDecoder.decode(fileName.substring(fileName.indexOf("filename=")+9),"UTF-8");
	        log.info("文件名为:" + fileName + "  大小" + (uc.getContentLength()/1024)+"KB");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return fileName;
	}

	/**
	 * 将HTTP资源另存为文件并进行MD5校验
	 * @param urlStr
	 * @param fileName
	 * @throws IOException
	 */
	public void getTradingPlatFormFile() throws Exception {
		
		// 根据列表下载资源
		if(vPTradingfileinfo != null && vPTradingfileinfo.size()>0){
			for(int i=0; i list = new ArrayList();
		if(belongCalendar()){
			list = mapper.queryTradingPlatFileBusy();
		} else {
			list = mapper.queryTradingPlatFileIdle();
		}
		try {
			if(list != null && list.size()>0){
				for(int i=0; i

你可能感兴趣的:(JAVA)