class CachedResponseTranscoder implements Transcoder<CachedResponse> {

    @Override
    public CachedData encode(CachedResponse o) {
        try {
            ByteArrayOutputStream buffer = new ByteArrayOutputStream();
            OutputStreamWriter writer = new OutputStreamWriter(buffer, Charsets.US_ASCII);

            writer.write(format("HTTP/1.1 %d \r\n", o.getStatusCode()));

            for (Map.Entry<String, List<String>> entry : o.getResponseHeaders().entrySet()) {
                for (String value : entry.getValue()) {
                    writer.write(entry.getKey());
                    writer.write(": ");
                    writer.write(value);
                    writer.write("\r\n");
                }
            }

            writer.write("\r\n");
            writer.flush();

            buffer.write(o.getResponseContent());

            return new CachedData(0, buffer.toByteArray(), getMaxSize());
        } catch (IOException ex) {
            // There should be no IO exceptions since the operations are done with a memory stream
            throw Throwables.propagate(ex);
        }
    }

    private  CachedResponseTranscoder();

}