String file_type,
InputStream input_stream )
throws IOException
{
OutputStream os = getOutputStream();
String response_type = HTTPUtils.guessContentTypeFromFileType(file_type);
if ( explicit_gzip != 2 && HTTPUtils.useCompressionForFileType(response_type)){
Map headers = request.getHeaders();
String accept_encoding = (String)headers.get("accept-encoding");
if ( HTTPUtils.canGZIP(accept_encoding)){
is_gzipped = true;
os = new GZIPOutputStream(os);
header_map.put("Content-Encoding", "gzip");
}
}
setContentType( response_type );
byte[] buffer = new byte[4096];
while(true){
int len = input_stream.read(buffer);
if ( len <= 0 ){
break;
}
os.write( buffer, 0, len );
}
if ( os instanceof GZIPOutputStream ){
((GZIPOutputStream)os).finish();