1 2 package org.enhydra.snapper.presentation; 3 4 import java.io.BufferedOutputStream ; 5 import java.io.File ; 6 import java.io.FileInputStream ; 7 import java.io.FileNotFoundException ; 8 9 import org.enhydra.snapper.Log; 10 11 12 13 14 import com.lutris.appserver.server.httpPresentation.HttpPresentationComms; 15 import com.lutris.appserver.server.httpPresentation.HttpPresentationException; 16 17 18 public class FileDownloadBO{ 19 20 private File fDown = null; 21 private HttpPresentationComms comms = null; 22 private boolean isForDelete = false; 23 24 public static final String EXCEL_CONTENT_TYPE = "application/vnd.ms-excel"; 25 public static final String WORD_CONTENT_TYPE = "application/vnd.ms-word"; 26 public static final String HTML_CONTENT_TYPE = "text/html"; 27 public static final String PDF_CONTENT_TYPE = "application/pdf"; 28 public static final String ZIP_CONTENT_TYPE = "application/x-zip"; 29 public static final String RTF_CONTENT_TYPE = "application/rtf"; 30 public static final String PPT_CONTENT_TYPE = "application/vnd.ms-powerpoint"; 31 public static final String PPS_CONTENT_TYPE = "application/vnd.ms-powerpoint"; 32 public static final String EML_CONTENT_TYPE = "application/vnd.ms-outlook"; 33 34 public static final String SXW_CONTENT_TYPE = "application/vnd.sun.xml.writer"; 35 public static final String STW_CONTENT_TYPE = "application/vnd.sun.xml.writer.template"; 36 public static final String SXG_CONTENT_TYPE = "application/vnd.sun.xml.writer.global"; 37 public static final String SXC_CONTENT_TYPE = "application/vnd.sun.xml.calc"; 38 public static final String STC_CONTENT_TYPE = "application/vnd.sun.xml.calc.template"; 39 public static final String SXI_CONTENT_TYPE = "application/vnd.sun.xml.impress"; 40 public static final String STI_CONTENT_TYPE = "application/vnd.sun.xml.impress.template"; 41 public static final String SXD_CONTENT_TYPE = "application/vnd.sun.xml.draw"; 42 public static final String STD_CONTENT_TYPE = "application/vnd.sun.xml.draw.template"; 43 public static final String SXM_CONTENT_TYPE = "application/vnd.sun.xml.math"; 44 45 57 58 public FileDownloadBO(File file, HttpPresentationComms comms) { 59 this.fDown = file; 60 this.comms = comms; 61 } 62 63 public void setContentType(String type) throws HttpPresentationException { 64 this.comms.response.setContentType(type); 65 this.comms.response.setHeader("Content-Disposition", 66 "inline; filename=\"" + fDown.getName() + "\""); 67 } 68 69 public void download() { 70 try { 71 FileInputStream fi = new FileInputStream (fDown); 72 73 byte[] buffer = new byte[4096]; 74 BufferedOutputStream bu = new BufferedOutputStream (comms.response.getOutputStream()); 75 int no = fi.read(buffer); 76 while (no > -1) { 77 bu.write(buffer, 0, no); 78 no = fi.read(buffer); 79 } 80 bu.flush(); 81 comms.response.flush(); 82 fi.close(); 83 fi = null; 84 }catch (FileNotFoundException e) { 85 Log.log(e.getMessage()); 86 87 }catch (Exception e) { 88 } 89 } 90 91 } 92 | Popular Tags |