1 5 package com.oreilly.servlet; 6 7 import java.io.*; 8 import javax.servlet.*; 9 import javax.servlet.http.*; 10 11 66 public class MultipartResponse { 67 68 HttpServletResponse res; 69 ServletOutputStream out; 70 boolean endedLastResponse = true; 71 72 79 public MultipartResponse(HttpServletResponse response) throws IOException { 80 res = response; 82 out = res.getOutputStream(); 83 84 res.setContentType("multipart/x-mixed-replace;boundary=End"); 86 out.println(); 87 out.println("--End"); 88 } 89 90 98 public void startResponse(String contentType) throws IOException { 99 if (!endedLastResponse) { 101 endResponse(); 102 } 103 out.println("Content-type: " + contentType); 105 out.println(); 106 endedLastResponse = false; 107 } 108 109 114 public void endResponse() throws IOException { 115 out.println(); 117 out.println("--End"); 118 out.flush(); 119 endedLastResponse = true; 120 } 121 122 128 public void finish() throws IOException { 129 out.println("--End--"); 130 out.flush(); 131 } 132 } 133 | Popular Tags |