Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.fasterxml.clustermate.service.servlet;
  
  
  
com.fasterxml.clustermate.service.ServiceResponse implemented over native Servlet response.
 
 public class ServletServiceResponse extends ServiceResponse
 {
    
Underlying response object exposed by Servlet API.
 
     protected final HttpServletResponse _response;

    
Since 'getStatus()' was only added in Servlet 3.0, let's actually keep track of it here.
 
     protected int _statusCode;
     
     protected long _responseLength;
 
     protected StatsCollectingOutputStream _output;
     
     /*
     /**********************************************************************
     /* Life-cycle
     /**********************************************************************
      */
     
     {
          = r;
     }
 
     public void writeOut(ObjectWriter writerthrows IOException
     {
         if ( == null) {
              = _constructOutput();
         }
         if ( != null) {
             long len = .getLength();
             if (len >= 0L) {
                 setContentLength(len);
             }
             .writeContent();
         } else if ( != null) {
             writer.writeValue();
         }
     }
 
     public void writeText(String msgthrows IOException
     {
         writeRaw(msg.getBytes("UTF-8"));
     }
     
     public void writeRaw(byte[] rawthrows IOException
     {
         setContentLength(raw.length);
         if ( == null) {
              = _constructOutput();
         }
         .write(raw);
     }
 
         return new StatsCollectingOutputStream(.getOutputStream());
     }
     
     /*
     /**********************************************************************
     /* Basic ServiceResponse impl
     /**********************************************************************
      */
 
     @Override
     public long getBytesWritten() {
         if ( != null) {
             return .getBytesWritten();
         }
         return ;
     }
     
     @Override
     public int getStatus() {
         return ;
     }
     
     @SuppressWarnings("unchecked")
     @Override
     public ServletServiceResponse set(int codeObject entity)
    {
        return setStatus(code).setEntity(entity);
    }
    
    @SuppressWarnings("unchecked")
    @Override
    public ServletServiceResponse setStatus(int code)
    {
         = code;
        .setStatus(code);
        return this;
    }
    @Override
    public ServletServiceResponse setContentType(String contentType) {
        .setContentType(contentType);
        return this;
    }
 
    @Override
    public ServletServiceResponse setContentLength(long length)
    {
         = length;        
        // not sure if this would work but:
        if (length > .) {
            return addHeader(.length);
        }
        .setContentLength((intlength);
        return this;
    }
    
    @Override
    public ServletServiceResponse addHeader(String keyString value)
    {
        .addHeader(keyvalue);
        return this;
    }
    @Override
    public ServletServiceResponse addHeader(String keyint value)
    {
        .addIntHeader(keyvalue);
        return this;
    }
    @Override
    public ServletServiceResponse addHeader(String keylong value)
    {
        .addHeader(key, String.valueOf(value));
        return this;
    }
New to GrepCode? Check out our FAQ X