package com.highcom.object.common;
import java.io.*;import javax.servlet.*;import com.jspsmart.upload.*;import com.highcom.hcgip.basic.common.*;import javax.servlet.http.*;
/** * 处理系统中的各类附件。这些附件被保存到在config.properties中attachmentpath指定的路径下。 *
Title: Objective Management System *
Description: *
Copyright: Copyright (c) 2004 * @version 1.0 */
public class FileKeeper extends javax.servlet.http.HttpServlet { public static String base_dir; static { base_dir = PropertiesReader.getConfigValue("attachmentpath"); }
public FileKeeper() { }
public static String getRelativePath(java.io.File abs_path){ String fullpath= abs_path.getAbsolutePath(); String new_fullpath = fullpath.replaceAll("/","\\").toLowerCase(); String new_base_dir = base_dir.replaceAll("/","\\").toLowerCase(); int i=new_fullpath.indexOf(new_base_dir); if(i 0) { response.setContentType(mime); } else { response.setContentType("application/*"); } response.setHeader("Content-Disposition", "attachment;filename=" + filename);
InputStream in = download(relative_path);
if (in == null) { Log.debug("文件" + filename + "不存在.", this); response.getOutputStream().close(); return; } byte[] b = new byte[1024]; int len; while ( (len = in.read(b)) > 0) { response.getOutputStream().write(b, 0, len); } in.close(); response.getOutputStream().flush(); response.getOutputStream().close();
}
}

