public static byte[] unchunkdata(byte[] contentBytes) throws IOException { byte[] unchunkedData = null; byte[] buffer = new byte[1024]; ByteArrayInputStream bis = new ByteArrayInputStream(contentBytes); ChunkedInputStream cis = new ChunkedInputStream(bis); ByteArrayOutputStream bos = new ByteArrayOutputStream(); int read = -1; while ((read = cis.read(buffer)) != -1) { bos.write(buffer, 0, read); } unchunkedData = bos.toByteArray(); bos.close(); return unchunkedData; }
private static String tryUnzip(byte[] zipped) { try { ByteArrayInputStream is = new ByteArrayInputStream(zipped); ChunkedInputStream cs = new ChunkedInputStream(is); GZIPInputStream zs = new GZIPInputStream(cs); BufferedReader r = new BufferedReader(new InputStreamReader(zs)); StringBuilder result = new StringBuilder(); String line; while ((line = r.readLine()) != null) { result.append(line).append("\n"); } return result.toString(); } catch (IOException e) { if (!"Not in GZIP format".equals(e.getMessage())) { e.printStackTrace(); } return null; } }
/** * Get a raw replay of the 'entity'. For the common case of * HTTP, this is the message-body after any (usually-unnecessary) * transfer-decoding but before any content-encoding (eg gzip) decoding * * @return A replay input stream. * @throws IOException */ public InputStream getEntityReplayInputStream() throws IOException { if(inputIsChunked) { return new ChunkedInputStream(getRecordedInput().getMessageBodyReplayInputStream()); } else { return getRecordedInput().getMessageBodyReplayInputStream(); } }