// Path: serializer-base64/src/test/java/com/vlkan/hrrs/serializer/HttpRequestRecordPipe.java
// public class HttpRequestRecordPipe implements HttpRequestRecordReaderSource<String>, HttpRequestRecordWriterTarget<String> {
// 
//     private final Writer writer;
// 
//     private final BufferedReader reader;
// 
//     public HttpRequestRecordPipe(int pipeSize) {
//         PipedOutputStream outputStream = new PipedOutputStream();
//         this.writer = new OutputStreamWriter(outputStream);
//         try {
//             PipedInputStream inputStream = new PipedInputStream(outputStream, pipeSize);
//             this.reader = new BufferedReader(new InputStreamReader(inputStream));
//         } catch (IOException error) {
//             throw new RuntimeException("failed creating piped input stream", error);
//         }
//     }
// 
//     @Override
//     public void write(String value) {
//         try {
//             writer.write(value);
//         } catch (IOException error) {
//             throw new RuntimeException("write failure", error);
//         }
//     }
// 
//     @Nullable
//     @Override
//     public String read() {
//         try {
//             return reader.readLine();
//         } catch (IOException error) {
//             throw new RuntimeException("read failure", error);
//         }
//     }
// 
//     @Override
//     public void flush() {
//         try {
//             writer.flush();
//         } catch (IOException error) {
//             throw new RuntimeException("flush failure", error);
//         }
//     }
// 
//     @Override
//     public void close() throws IOException {
//         writer.close();
//         reader.close();
//     }
// 
// }
// 
// Path: serializer-base64/src/main/java/com/vlkan/hrrs/serializer/base64/guava/GuavaBase64Decoder.java
// public class GuavaBase64Decoder implements Base64Decoder {
// 
//     private static final GuavaBase64Decoder INSTANCE = new GuavaBase64Decoder();
// 
//     private GuavaBase64Decoder() {
//         // Do nothing.
//     }
// 
//     public static GuavaBase64Decoder getInstance() {
//         return INSTANCE;
//     }
// 
//     @Override
//     public byte[] decode(String encodedBytes) {
//         checkNotNull(encodedBytes, "encodedBytes");
//         return GuavaBase64.BASE_ENCODING.decode(encodedBytes);
//     }
// 
// }
// 
// Path: serializer-base64/src/main/java/com/vlkan/hrrs/serializer/base64/guava/GuavaBase64Encoder.java
// public class GuavaBase64Encoder implements Base64Encoder {
// 
//     private static final GuavaBase64Encoder INSTANCE = new GuavaBase64Encoder();
// 
//     private GuavaBase64Encoder() {
//         // Do nothing.
//     }
// 
//     public static GuavaBase64Encoder getInstance() {
//         return INSTANCE;
//     }
// 
//     @Override
//     public String encode(byte[] bytes) {
//         checkNotNull(bytes, "bytes");
//         return GuavaBase64.BASE_ENCODING.encode(bytes);
//     }
// 
// }


import com.vlkan.hrrs.api.*;
import com.vlkan.hrrs.serializer.HttpRequestRecordPipe;
import com.vlkan.hrrs.serializer.base64.guava.GuavaBase64Decoder;
import com.vlkan.hrrs.serializer.base64.guava.GuavaBase64Encoder;
import org.junit.Test;
import java.util.*;
import static com.google.common.base.Preconditions.checkArgument;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;

    private static void should_write_and_read(HttpRequestRecord record) {
        HttpRequestRecordPipe pipe = new HttpRequestRecordPipe(MAX_BYTE_COUNT * 8);
        HttpRequestRecordReader<String> reader = new Base64HttpRequestRecordReader(pipe, GuavaBase64Decoder.getInstance());
        HttpRequestRecordWriter<String> writer = new Base64HttpRequestRecordWriter(pipe, GuavaBase64Encoder.getInstance());
        writer.write(record);
        pipe.flush();
        Iterator<HttpRequestRecord> iterator = reader.read().iterator();
        assertThat(iterator.hasNext(), is(true));
        HttpRequestRecord readRecord = iterator.next();
        assertThat(readRecord, is(equalTo(record)));
    }

    private static HttpRequestRecord generateHttpRequestRecord(Random random) {

        // Populate fields.
        String id = Integer.toString(generateInt(random, 0, Integer.MAX_VALUE), Character.MAX_RADIX);
        int groupId = Math.abs(id.hashCode()) % MAX_GROUP_COUNT;
        String groupName = String.format("group-%d", groupId);
        Date timestamp = new Date();
        String uri = String.format("/hello/%s?id=%s", groupName, id);
        HttpRequestMethod method = generateHttpRequestMethod(random);
        List<HttpRequestHeader> headers = generateHttpRequestHeaders(random);
        HttpRequestPayload payload = generateHttpRequestPayload(random);

        // Create the record.
        return ImmutableHttpRequestRecord
                .newBuilder()
                .setId(id)
                .setTimestamp(timestamp)
// Path: serializer-base64/src/test/java/com/vlkan/hrrs/serializer/HttpRequestRecordPipe.java
// public class HttpRequestRecordPipe implements HttpRequestRecordReaderSource<String>, HttpRequestRecordWriterTarget<String> {
// 
//     private final Writer writer;
// 
//     private final BufferedReader reader;
// 
//     public HttpRequestRecordPipe(int pipeSize) {
//         PipedOutputStream outputStream = new PipedOutputStream();
//         this.writer = new OutputStreamWriter(outputStream);
//         try {
//             PipedInputStream inputStream = new PipedInputStream(outputStream, pipeSize);
//             this.reader = new BufferedReader(new InputStreamReader(inputStream));
//         } catch (IOException error) {
//             throw new RuntimeException("failed creating piped input stream", error);
//         }
//     }
// 
//     @Override
//     public void write(String value) {
//         try {
//             writer.write(value);
//         } catch (IOException error) {
//             throw new RuntimeException("write failure", error);
//         }
//     }
// 
//     @Nullable
//     @Override
//     public String read() {
//         try {
//             return reader.readLine();
//         } catch (IOException error) {
//             throw new RuntimeException("read failure", error);
//         }
//     }
// 
//     @Override
//     public void flush() {
//         try {
//             writer.flush();
//         } catch (IOException error) {
//             throw new RuntimeException("flush failure", error);
//         }
//     }
// 
//     @Override
//     public void close() throws IOException {
//         writer.close();
//         reader.close();
//     }
// 
// }
// 
// Path: serializer-base64/src/main/java/com/vlkan/hrrs/serializer/base64/guava/GuavaBase64Decoder.java
// public class GuavaBase64Decoder implements Base64Decoder {
// 
//     private static final GuavaBase64Decoder INSTANCE = new GuavaBase64Decoder();
// 
//     private GuavaBase64Decoder() {
//         // Do nothing.
//     }
// 
//     public static GuavaBase64Decoder getInstance() {
//         return INSTANCE;
//     }
// 
//     @Override
//     public byte[] decode(String encodedBytes) {
//         checkNotNull(encodedBytes, "encodedBytes");
//         return GuavaBase64.BASE_ENCODING.decode(encodedBytes);
//     }
// 
// }
// 
// Path: serializer-base64/src/main/java/com/vlkan/hrrs/serializer/base64/guava/GuavaBase64Encoder.java
// public class GuavaBase64Encoder implements Base64Encoder {
// 
//     private static final GuavaBase64Encoder INSTANCE = new GuavaBase64Encoder();
// 
//     private GuavaBase64Encoder() {
//         // Do nothing.
//     }
// 
//     public static GuavaBase64Encoder getInstance() {
//         return INSTANCE;
//     }
// 
//     @Override
//     public String encode(byte[] bytes) {
//         checkNotNull(bytes, "bytes");
//         return GuavaBase64.BASE_ENCODING.encode(bytes);
//     }
// 
// }


// Path: serializer-base64/src/test/java/com/vlkan/hrrs/serializer/base64/HttpRequestSerializationTest.java
import com.vlkan.hrrs.api.*;
import com.vlkan.hrrs.serializer.HttpRequestRecordPipe;
import com.vlkan.hrrs.serializer.base64.guava.GuavaBase64Decoder;
import com.vlkan.hrrs.serializer.base64.guava.GuavaBase64Encoder;
import org.junit.Test;
import java.util.*;
import static com.google.common.base.Preconditions.checkArgument;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;


    private static void should_write_and_read(HttpRequestRecord record) {
        HttpRequestRecordPipe pipe = new HttpRequestRecordPipe(MAX_BYTE_COUNT * 8);
        HttpRequestRecordReader<String> reader = new Base64HttpRequestRecordReader(pipe, GuavaBase64Decoder.getInstance());
        HttpRequestRecordWriter<String> writer = new Base64HttpRequestRecordWriter(pipe, GuavaBase64Encoder.getInstance());
        writer.write(record);
        pipe.flush();
        Iterator<HttpRequestRecord> iterator = reader.read().iterator();
        assertThat(iterator.hasNext(), is(true));
        HttpRequestRecord readRecord = iterator.next();
        assertThat(readRecord, is(equalTo(record)));
    }

    private static HttpRequestRecord generateHttpRequestRecord(Random random) {

        // Populate fields.
        String id = Integer.toString(generateInt(random, 0, Integer.MAX_VALUE), Character.MAX_RADIX);
        int groupId = Math.abs(id.hashCode()) % MAX_GROUP_COUNT;
        String groupName = String.format("group-%d", groupId);
        Date timestamp = new Date();
        String uri = String.format("/hello/%s?id=%s", groupName, id);
        HttpRequestMethod method = generateHttpRequestMethod(random);
        List<HttpRequestHeader> headers = generateHttpRequestHeaders(random);
        HttpRequestPayload payload = generateHttpRequestPayload(random);

        // Create the record.
        return ImmutableHttpRequestRecord
                .newBuilder()
                .setId(id)
                .setTimestamp(timestamp)
                .setGroupName(groupName)