/*
 * Copyright 2011-2017 the original author or authors.
 *
 * Licensed 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 io.lettuce.core.server;

import java.security.SecureRandom;
import java.util.Arrays;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

/**
 * Handler to generate random base64 data.
 */
public class RandomServerHandler extends ChannelInboundHandlerAdapter {

    private SecureRandom random = new SecureRandom();

    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) {
        byte initial[] = new byte[1];
        random.nextBytes(initial);

        byte[] response = new byte[Math.abs((int) initial[0])];

        Arrays.fill(response, "A".getBytes()[0]);

        ByteBuf buf = ctx.alloc().heapBuffer(response.length);

        ByteBuf encoded = buf.writeBytes(response);
        ctx.write(encoded);
    }

    @Override
    public void channelReadComplete(ChannelHandlerContext ctx) {
        ctx.flush();
    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
        // Close the connection when an exception is raised.
        cause.printStackTrace();
        ctx.close();
    }
}

@@ -663,29 +663,19 @@
 ava.
-security.SecureRandom
+util.Arrays
 ;%0Aim
@@ -689,22 +689,22 @@
 va.util.
-Arrays
+Random
 ;%0A%0Aimpor
@@ -972,48 +972,126 @@
 ate 
-SecureRandom random
+final int count;%0A%0A    public RandomServerHandler() %7B%0A%0A        int count;%0A        do %7B%0A            count
  = new 
-Secure
 Random()
 ;%0A%0A 
@@ -1086,17 +1086,94 @@
 Random()
-;
+.nextInt(50);%0A        %7D while (count %3C 1);%0A%0A        this.count = count;%0A%0A    %7D
 %0A%0A    @O
@@ -1252,81 +1252,8 @@
 g) %7B
-%0A        byte initial%5B%5D = new byte%5B1%5D;%0A        random.nextBytes(initial);
 %0A%0A  
@@ -1289,34 +1289,13 @@
 yte%5B
-Math.abs((int) initial%5B0%5D)
+count
 %5D;%0A%0A
@@ -1478,16 +1478,24 @@
 tx.write
+AndFlush
 (encoded

Make sure to write at least two bytes in RandomServerHandler #660