/*
 * Copyright (c) WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
 *
 * WSO2 Inc. licenses this file to you under the Apache License,
 * Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

package org.wso2.carbon.mss.example;


import com.google.common.base.Charsets;
import io.netty.buffer.ByteBuf;
import io.netty.handler.codec.http.HttpResponseStatus;
import org.wso2.carbon.mss.HttpResponder;
import org.wso2.carbon.mss.HttpStreamHandler;
import org.wso2.carbon.mss.HttpStreamer;

import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.core.Context;

/**
 * Streamer service resource class
 */
@Path("/streamer")
public class StreamerService {

    @POST
    @Path("/stream")
    @Consumes("text/plain")
    public void stream(@Context HttpStreamer httpStreamer) {
        final StringBuffer sb = new StringBuffer();
        httpStreamer.callback(new HttpStreamHandler() {
            @Override
            public void chunk(ByteBuf request, HttpResponder responder) {
                sb.append(request.toString(Charsets.UTF_8));
            }

            @Override
            public void finished(ByteBuf request, HttpResponder responder) {
                sb.append(request.toString(Charsets.UTF_8));
                responder.sendString(HttpResponseStatus.OK, sb.toString());
            }

            @Override
            public void error(Throwable cause) {
                sb.delete(0, sb.length());
            }
        });
    }

    @POST
    @Path("/aggregate")
    @Consumes("text/plain")
    public String aggregate(String content) {
        return content;
    }

}

@@ -1294,85 +1294,263 @@
     
-final StringBuffer sb = new StringBuffer()
+httpStreamer.callback(new HttpStreamHandlerImpl());%0A    %7D%0A%0A    @POST%0A    @Path(%22/aggregate%22)%0A    @Consumes(%22text/plain%22)%0A    public String aggregate(String content) %7B%0A        return content
 ;%0A    
+%7D%0A%0A
     
-httpStreamer.callback(new
+private static class HttpStreamHandlerImpl implements
  Htt
@@ -1567,17 +1567,64 @@
 dler
-()
  %7B%0A    
+    final StringBuffer sb = new StringBuffer();%0A%0A
     
@@ -1637,36 +1637,32 @@
 verride%0A        
-  
-  
 public void chun
@@ -1711,36 +1711,32 @@
 ) %7B%0A            
-    
 sb.append(reques
@@ -1768,35 +1768,27 @@
 ));%0A        
-  
-  
 %7D%0A%0A
-    
         @Ove
@@ -1793,36 +1793,32 @@
 verride%0A        
- 
-   
 public void fini
@@ -1870,36 +1870,32 @@
 ) %7B%0A            
-    
 sb.append(reques
@@ -1935,20 +1935,16 @@
         
- 
-   
 responde
@@ -1999,28 +1999,24 @@
 ));%0A        
-    
 %7D%0A%0A         
@@ -2010,28 +2010,24 @@
  %7D%0A%0A        
- 
-   
 @Override%0A  
@@ -2020,28 +2020,24 @@
   @Override%0A
-    
         publ
@@ -2081,20 +2081,16 @@
         
-    
 sb.delet
@@ -2104,28 +2104,24 @@
 .length());%0A
-    
         %7D%0A  
@@ -2122,159 +2122,8 @@
   %7D%0A
-        %7D);%0A    %7D%0A%0A    @POST%0A    @Path(%22/aggregate%22)%0A    @Consumes(%22text/plain%22)%0A    public String aggregate(String content) %7B%0A        return content;%0A
     

Fix findbugs issue