@Test public void testCreateByteHttpBody() throws IOException { String str = "Hello world"; byte[] content = str.getBytes(); InputStream is = new ByteArrayInputStream(content); RecordedHttpBody recordedHttpBody = RecordedHttpBodyFactory.create("image/gif", "identity", is, "UTF-8"); Assert.assertTrue(recordedHttpBody instanceof RecordedByteHttpBody); Assert.assertFalse(recordedHttpBody instanceof RecordedStringHttpBody); Assert.assertEquals(content, recordedHttpBody.getContent("UTF-8")); }
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);  }