`
CodeToMyLaw
  • 浏览: 7193 次
  • 性别: Icon_minigender_1
  • 来自: 北京
最近访客 更多访客>>
社区版块
存档分类
最新评论

Spring 定时器

阅读更多
package cn.hs.dpl.web.action;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.sql.Timestamp;


import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.scheduling.quartz.QuartzJobBean;


import cn.hs.dpl.service.IMenuService;
import cn.hs.dpl.utils.LoggerUtil;

/**
 * 关于版本自动定制化的Action
 * @author bWX62796
 *
 */
public class TimerAction extends QuartzJobBean {

	//版本定制化service
	private IMenuService menuService;

	public void setMenuService(IMenuService menuService) {
		this.menuService = menuService;
	}

	/**
	 * 自动化的版本定制化
	 * @return
	 * @throws Exception
	 */
	@Override
	protected void executeInternal(JobExecutionContext arg0)
			throws JobExecutionException {
		System.out.println("开始版本定制化...");
		LoggerUtil.tranceINFO("版本自动定制化...");
		String xmlString = menuService.addAutoRule();
		BufferedInputStream in = null;
		BufferedOutputStream out = null;
		
		
		String temp = Thread.currentThread().getContextClassLoader().getResource("").getPath() ;
		temp = temp.substring(0, temp.lastIndexOf("WEB-INF"));  //WEB-INF 上一級就是項目的根目錄 
		String uploadPath = temp + "\\auto_version";
		File file = new File(uploadPath); 
		try {
			in = new BufferedInputStream(new ByteArrayInputStream(xmlString.getBytes("UTF-8")));
			//File file = new File(uploadPath);
			if(!file.exists()) {
				file.mkdir();
			}
			out = new BufferedOutputStream( new FileOutputStream( uploadPath+ File.separator + new Timestamp(System.currentTimeMillis()).toString().substring(0, 10) +"_rule.xml"));
			
			int j = 0;
			while ( ( j = in.read() ) != -1 ) {
				out.write(j);
			}	
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		finally {
			if(in != null){
				try {
					in.close();
				} catch (IOException e) {
					e.printStackTrace();
				}						
			}
			if(out!= null){
				try {
					out.close();
				} catch (IOException e) {
					e.printStackTrace();
				}	
			}
		}
	}
}

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics