CachedResponseTranscoder implements Transcoder<CachedResponse> { @Override public CachedResponse decode(CachedData d) { try { byte[] cachedData = d.getData(); int headerSeparatorIndex = Bytes.indexOf(cachedData, HEADER_SEPARATOR); if (headerSeparatorIndex < 0) { return null; } BufferedReader headerReader = new BufferedReader(new InputStreamReader( new ByteArrayInputStream(cachedData, 0, headerSeparatorIndex), Charsets.US_ASCII) ); int statusCode = readStatusCode(headerReader); MultivaluedMap<String, String> headers = readHeaders(headerReader); byte[] responseContent = Arrays.copyOfRange(cachedData, headerSeparatorIndex + HEADER_SEPARATOR.length, cachedData.length); return new CachedResponse(statusCode, headers, responseContent); } catch (IOException ex) { throw new RuntimeException("Corrupted cache entry", 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 decode(CachedResponse response, byte[] encoded) { CachedResponse decoded = CachedResponseTranscoder.INSTANCE.decode(new CachedData(0, encoded, CachedResponseTranscoder.INSTANCE.getMaxSize())); assertEquals(decoded, response); }