Changeset 449 for tapas/web/src/com/ether/ControllerEther.java
- Timestamp:
- 04/02/12 18:22:23 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tapas/web/src/com/ether/ControllerEther.java
r446 r449 23 23 import javax.servlet.http.HttpServletRequest; 24 24 import javax.servlet.http.HttpServletResponse; 25 import java.io.BufferedInputStream;26 import java.io.File;27 import java.io.FileInputStream;28 25 import java.io.IOException; 29 import java.io.InputStream;30 import java.io.OutputStream;31 26 import java.io.UnsupportedEncodingException; 32 27 import java.lang.annotation.Annotation; … … 186 181 final String fileName = methodDescription.getDownloadFile(); 187 182 final String downloadPath = getProperty( "downloadPath" ); 188 189 response.setContentType( "multipart/zip" ); 190 response.setHeader( "Content-Disposition", "attachment; filename=\"" + fileName.trim() + "\";" ); 191 192 final File file = new File( downloadPath + fileName ); 193 if( !file.exists() ) 194 throw new WebException( WebException.WebCode.ERROR_TO_DOWNLOAD_FILE, file.getPath() ); 195 196 response.setContentLength( (int) file.length() ); 197 try 198 { 199 final OutputStream outputStream = response.getOutputStream(); 200 final FileInputStream fileInputStream = new FileInputStream( file ); 201 202 final BufferedInputStream bufferedInputStream = new BufferedInputStream( fileInputStream ); 203 final InputStream inputStream = new BufferedInputStream( bufferedInputStream ); 204 205 int count; 206 final byte[] buf = new byte[4096]; 207 while( ( count = inputStream.read( buf ) ) > -1 ) 208 outputStream.write( buf, 0, count ); 209 inputStream.close(); 210 outputStream.close(); 211 } 212 catch( Exception ex ) 213 { 214 throw new WebException( WebException.WebCode.ERROR_TO_DOWNLOAD_FILE, ex ); 215 } 183 WebHelper.downloadFileToResponse( fileName, downloadPath, response ); 216 184 return null; 217 185 }
Note: See TracChangeset
for help on using the changeset viewer.