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) { throw Throwables.propagate(ex); } } private  CachedResponseTranscoder(); @Override boolean asyncDecode(CachedData d); @Override CachedData encode(CachedResponse o); @Override CachedResponse decode(CachedData d); @Override int getMaxSize(); static final CachedResponseTranscoder INSTANCE; }
@Test(dataProvider = "encodeData") public void encode(CachedResponse response, byte[] encoded) { CachedData data = CachedResponseTranscoder.INSTANCE.encode(response); assertEquals(data.getData(), encoded); assertEquals(data.getFlags(), 0); }