Ignore:
Timestamp:
04/02/12 18:22:23 (12 years ago)
Author:
vmipsl
Message:

downloadFile to response

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tapas/web/src/com/ether/ControllerEther.java

    r446 r449  
    2323import javax.servlet.http.HttpServletRequest; 
    2424import javax.servlet.http.HttpServletResponse; 
    25 import java.io.BufferedInputStream; 
    26 import java.io.File; 
    27 import java.io.FileInputStream; 
    2825import java.io.IOException; 
    29 import java.io.InputStream; 
    30 import java.io.OutputStream; 
    3126import java.io.UnsupportedEncodingException; 
    3227import java.lang.annotation.Annotation; 
     
    186181                final String fileName = methodDescription.getDownloadFile(); 
    187182                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 ); 
    216184                return null; 
    217185            } 
Note: See TracChangeset for help on using the changeset viewer.