You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by ja...@apache.org on 2007/02/28 21:18:17 UTC
svn commit: r512946 -
/ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilHttp.java
Author: jaz
Date: Wed Feb 28 12:18:16 2007
New Revision: 512946
URL: http://svn.apache.org/viewvc?view=rev&rev=512946
Log:
added method to send file name to browser when streaming data
Modified:
ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilHttp.java
Modified: ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilHttp.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilHttp.java?view=diff&rev=512946&r1=512945&r2=512946
==============================================================================
--- ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilHttp.java (original)
+++ ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilHttp.java Wed Feb 28 12:18:16 2007
@@ -548,9 +548,10 @@
* @param response HttpServletResponse object to get OutputStream from
* @param bytes Byte array of content to stream
* @param contentType The content type to pass to the browser
+ * @param fileName the fileName to tell the browser we are downloading
* @throws IOException
*/
- public static void streamContentToBrowser(HttpServletResponse response, byte[] bytes, String contentType) throws IOException {
+ public static void streamContentToBrowser(HttpServletResponse response, byte[] bytes, String contentType, String fileName) throws IOException {
// tell the browser not the cache
setResponseBrowserProxyNoCache(response);
@@ -559,6 +560,9 @@
if (contentType != null) {
response.setContentType(contentType);
}
+ if (fileName != null) {
+ response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
+ }
// create the streams
OutputStream out = response.getOutputStream();
@@ -581,6 +585,10 @@
out.close();
}
+ public static void streamContentToBrowser(HttpServletResponse response, byte[] bytes, String contentType) throws IOException {
+ streamContentToBrowser(response, bytes, contentType, null);
+ }
+
/**
* Streams content from InputStream to the ServletOutputStream
* This method will close the ServletOutputStream when finished
@@ -592,7 +600,7 @@
* @param contentType The content type to pass to the browser
* @throws IOException
*/
- public static void streamContentToBrowser(HttpServletResponse response, InputStream in, int length, String contentType) throws IOException {
+ public static void streamContentToBrowser(HttpServletResponse response, InputStream in, int length, String contentType, String fileName) throws IOException {
// tell the browser not the cache
setResponseBrowserProxyNoCache(response);
@@ -601,6 +609,9 @@
if (contentType != null) {
response.setContentType(contentType);
}
+ if (fileName != null) {
+ response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
+ }
// stream the content
OutputStream out = response.getOutputStream();
@@ -614,6 +625,10 @@
// close the servlet output stream
out.flush();
out.close();
+ }
+
+ public static void streamContentToBrowser(HttpServletResponse response, InputStream in, int length, String contentType) throws IOException {
+ streamContentToBrowser(response, in, length, contentType, null);
}
/**