private void sendResponse(final String status,final String mime,final Map<String,String> header,final InputStream data){
  try {
    if (status == null)     throw new Error("sendResponse(): Status can't be null.");
    if (log.isInfoEnabled()) {
      log.info("status: [HTTP/1.0 " + status + "]"+ (mime == null ? "" : "[Content-Type: " + mime + "]"));
    }
    final OutputStream out=mySocket.getOutputStream();
    final PrintWriter pw=new PrintWriter(out);
    pw.print("HTTP/1.0 ");
    pw.print(status);
    pw.print(" ");
    pw.print(EOL);
    if (mime != null) {
      pw.print(CONTENT_TYPE);
      pw.print(": ");
      pw.print(mime);
      pw.print(EOL);
    }
    if (header == null || header.get(DATE) == null) {
      pw.print(DATE);
      pw.print(": ");
      pw.print(gmtFrmt.format(new Date()));
      pw.print(EOL);
    }
    if (header != null) {
      for (      Map.Entry<String,String> e : header.entrySet()) {
        final String key=(String)e.getKey();
        final String value=e.getValue();
        pw.print(key);
        pw.print(": ");
        pw.print(value);
        pw.print(EOL);
      }
    }
    pw.print(EOL);
    pw.flush();
    if (data != null) {
      final byte[] buff=new byte[2048];
      while (true) {
        final int read=data.read(buff,0,buff.length);
        if (read <= 0)         break;
        out.write(buff,0,read);
      }
    }
    out.flush();
    out.close();
  }
 catch (  IOException ioe) {
    try {
      mySocket.close();
    }
 catch (    Throwable t) {
    }
    log.error(ioe,ioe);
  }
 finally {
    if (data != null) {
      try {
        data.close();
      }
 catch (      Throwable t) {
      }
    }
  }
}

private void sendResponse ( final String status , final String mime , final Map < String , String > header , final InputStream data ) { try { if ( status == null ) throw new Error ( "sendResponse(): Status can't be null." ) ; if ( log . isInfoEnabled ( ) ) { log . info ( "status: [HTTP/1.0 " + status + "]" + ( mime == null ? "" : "[Content-Type: " + mime + "]" ) ) ; } final OutputStream out = mySocket . getOutputStream ( ) ; final PrintWriter pw = new PrintWriter ( out ) ; pw . print ( "HTTP/1.0 " ) ; pw . print ( status ) ; pw . print ( " " ) ; pw . print ( EOL ) ; if ( mime != null ) { pw . print ( CONTENT_TYPE ) ; pw . print ( ": " ) ; pw . print ( mime ) ; pw . print ( EOL ) ; } if ( header == null || header . get ( DATE ) == null ) { pw . print ( DATE ) ; pw . print ( ": " ) ; pw . print ( gmtFrmt . format ( new Date ( ) ) ) ; pw . print ( EOL ) ; } if ( header != null ) { for ( Map . Entry < String , String > e : header . entrySet ( ) ) { final String key = ( String ) e . getKey ( ) ; final String value = e . getValue ( ) ; pw . print ( key ) ; pw . print ( ": " ) ; pw . print ( value ) ; pw . print ( EOL ) ; } } pw . print ( EOL ) ; pw . flush ( ) ; if ( data != null ) { final byte [ ] buff = new byte [ 2048 ] ; while ( true ) { final int read = data . read ( buff , 0 , buff . length ) ; if ( read <= 0 ) break ; out . write ( buff , 0 , read ) ; } } out . flush ( ) ; out . close ( ) ; } catch ( IOException ioe ) { try { mySocket . close ( ) ; } catch ( Throwable t ) { } log . error ( ioe , ioe ) ; } finally { if ( data != null ) { try { data . close ( ) ; } catch ( Throwable t ) { } } } }
sends given response to the socket .
