@Test public void testCreateGZipEncodedStringHttpBody() throws IOException { String str = "Hello world. This is some extra text to make the string longer so that gzip makes it smaller"; byte[] content = str.getBytes(); byte[] compressedContent = new GzipCompressor().compress(content); InputStream is = new ByteArrayInputStream(compressedContent); RecordedHttpBody recordedHttpBody = RecordedHttpBodyFactory.create("text/html", "gzip", is, "UTF-8"); Assert.assertTrue(recordedHttpBody instanceof RecordedEncodedHttpBody); RecordedEncodedHttpBody encodedBody = (RecordedEncodedHttpBody) recordedHttpBody; Assert.assertEquals(encodedBody.getEncodingName(), "gzip"); Assert.assertTrue(encodedBody.getDecodedBody() instanceof RecordedStringHttpBody); Assert.assertEquals(encodedBody.getDecodedBody().getContent("UTF-8"), content); Assert.assertEquals(encodedBody.getContent("UTF-8"), compressedContent); }
public static RecordedHttpBody create(String contentType, String contentEncoding, final InputStream inputStream, final String charset) throws IOException { if (HttpUtilities.isCompressedContentEncoding(contentEncoding)) { return new RecordedEncodedHttpBody(IOUtils.toByteArray(inputStream), contentEncoding, charset, contentType); } else if (HttpUtilities.isTextContentType(contentType)) { return new RecordedStringHttpBody(IOUtils.toString(inputStream, charset)); } else { return new RecordedByteHttpBody(IOUtils.toByteArray(inputStream)); } }
RecordedHttpBodyFactory { public static RecordedHttpBody create(String contentType, String contentEncoding, final InputStream inputStream, final String charset) throws IOException { if (HttpUtilities.isCompressedContentEncoding(contentEncoding)) { return new RecordedEncodedHttpBody(IOUtils.toByteArray(inputStream), contentEncoding, charset, contentType); } else if (HttpUtilities.isTextContentType(contentType)) { return new RecordedStringHttpBody(IOUtils.toString(inputStream, charset)); } else { return new RecordedByteHttpBody(IOUtils.toByteArray(inputStream)); } } }
RecordedHttpBodyFactory { public static RecordedHttpBody create(String contentType, String contentEncoding, final InputStream inputStream, final String charset) throws IOException { if (HttpUtilities.isCompressedContentEncoding(contentEncoding)) { return new RecordedEncodedHttpBody(IOUtils.toByteArray(inputStream), contentEncoding, charset, contentType); } else if (HttpUtilities.isTextContentType(contentType)) { return new RecordedStringHttpBody(IOUtils.toString(inputStream, charset)); } else { return new RecordedByteHttpBody(IOUtils.toByteArray(inputStream)); } } private  RecordedHttpBodyFactory(); }
RecordedHttpBodyFactory { public static RecordedHttpBody create(String contentType, String contentEncoding, final InputStream inputStream, final String charset) throws IOException { if (HttpUtilities.isCompressedContentEncoding(contentEncoding)) { return new RecordedEncodedHttpBody(IOUtils.toByteArray(inputStream), contentEncoding, charset, contentType); } else if (HttpUtilities.isTextContentType(contentType)) { return new RecordedStringHttpBody(IOUtils.toString(inputStream, charset)); } else { return new RecordedByteHttpBody(IOUtils.toByteArray(inputStream)); } } private  RecordedHttpBodyFactory(); static RecordedHttpBody create(String contentType, String contentEncoding, final InputStream inputStream,
      final String charset); }
RecordedHttpBodyFactory { public static RecordedHttpBody create(String contentType, String contentEncoding, final InputStream inputStream, final String charset) throws IOException { if (HttpUtilities.isCompressedContentEncoding(contentEncoding)) { return new RecordedEncodedHttpBody(IOUtils.toByteArray(inputStream), contentEncoding, charset, contentType); } else if (HttpUtilities.isTextContentType(contentType)) { return new RecordedStringHttpBody(IOUtils.toString(inputStream, charset)); } else { return new RecordedByteHttpBody(IOUtils.toByteArray(inputStream)); } } private  RecordedHttpBodyFactory(); static RecordedHttpBody create(String contentType, String contentEncoding, final InputStream inputStream,
      final String charset);  }