本文整理汇总了Java中com.epam.reportportal.apache.http.entity.ContentType.TEXT_PLAIN属性的典型用法代码示例。如果您正苦于以下问题:Java ContentType.TEXT_PLAIN属性的具体用法?Java ContentType.TEXT_PLAIN怎么用?Java ContentType.TEXT_PLAIN使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类com.epam.reportportal.apache.http.entity.ContentType
的用法示例。
在下文中一共展示了ContentType.TEXT_PLAIN属性的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testBasics
@Test
public void testBasics() throws Exception {
final File tmpfile = File.createTempFile("testfile", ".txt");
tmpfile.deleteOnExit();
final FileEntity httpentity = new FileEntity(tmpfile, ContentType.TEXT_PLAIN);
Assert.assertEquals(tmpfile.length(), httpentity.getContentLength());
final InputStream content = httpentity.getContent();
Assert.assertNotNull(content);
content.close();
Assert.assertTrue(httpentity.isRepeatable());
Assert.assertFalse(httpentity.isStreaming());
if (!tmpfile.delete()){
Assert.fail("Failed to delete: "+tmpfile);
}
}
示例2: testBasics
@Test
public void testBasics() throws Exception {
final String s = "Message content";
final StringEntity httpentity = new StringEntity(s, ContentType.TEXT_PLAIN);
final byte[] bytes = s.getBytes(Consts.ISO_8859_1.name());
Assert.assertEquals(bytes.length, httpentity.getContentLength());
Assert.assertNotNull(httpentity.getContent());
Assert.assertTrue(httpentity.isRepeatable());
Assert.assertFalse(httpentity.isStreaming());
}
示例3: testIllegalConstructor
@Test
public void testIllegalConstructor() throws Exception {
try {
new FileEntity(null, ContentType.TEXT_PLAIN);
Assert.fail("IllegalArgumentException should have been thrown");
} catch (final IllegalArgumentException ex) {
// expected
}
}
示例4: testWriteTo
@Test
public void testWriteTo() throws Exception {
final File tmpfile = File.createTempFile("testfile", ".txt");
tmpfile.deleteOnExit();
final FileOutputStream outstream = new FileOutputStream(tmpfile);
outstream.write(0);
outstream.write(1);
outstream.write(2);
outstream.write(3);
outstream.close();
final FileEntity httpentity = new FileEntity(tmpfile, ContentType.TEXT_PLAIN);
final ByteArrayOutputStream out = new ByteArrayOutputStream();
httpentity.writeTo(out);
final byte[] bytes = out.toByteArray();
Assert.assertNotNull(bytes);
Assert.assertEquals(tmpfile.length(), bytes.length);
for (int i = 0; i < 4; i++) {
Assert.assertEquals(i, bytes[i]);
}
if (!tmpfile.delete()){
Assert.fail("Failed to delete: "+tmpfile);
}
try {
httpentity.writeTo(null);
Assert.fail("IllegalArgumentException should have been thrown");
} catch (final IllegalArgumentException ex) {
// expected
}
}
示例5: testBasics
@Test
public void testBasics() throws Exception {
final String s = "Message content";
final StringEntity httpentity = new StringEntity(s, ContentType.TEXT_PLAIN);
httpentity.setContentEncoding(HTTP.IDENTITY_CODING);
final HttpEntityWrapper wrapped = new HttpEntityWrapper(httpentity);
Assert.assertEquals(httpentity.getContentLength(), wrapped.getContentLength());
Assert.assertEquals(httpentity.getContentType(), wrapped.getContentType());
Assert.assertEquals(httpentity.getContentEncoding(), wrapped.getContentEncoding());
Assert.assertEquals(httpentity.isChunked(), wrapped.isChunked());
Assert.assertEquals(httpentity.isRepeatable(), wrapped.isRepeatable());
Assert.assertEquals(httpentity.isStreaming(), wrapped.isStreaming());
Assert.assertNotNull(wrapped.getContent());
}
示例6: testBasic
@Test
public void testBasic() throws Exception {
final String s = "some kind of text";
final StringEntity e = new StringEntity(s, ContentType.TEXT_PLAIN);
e.setChunked(false);
final GzipCompressingEntity gzipe = new GzipCompressingEntity(e);
Assert.assertTrue(gzipe.isChunked());
Assert.assertEquals(-1, gzipe.getContentLength());
Assert.assertNotNull(gzipe.getContentEncoding());
Assert.assertEquals("gzip", gzipe.getContentEncoding().getValue());
}
示例7: testCompressionDecompression
@Test
public void testCompressionDecompression() throws Exception {
final StringEntity in = new StringEntity("some kind of text", ContentType.TEXT_PLAIN);
final GzipCompressingEntity gzipe = new GzipCompressingEntity(in);
final ByteArrayOutputStream buf = new ByteArrayOutputStream();
gzipe.writeTo(buf);
final ByteArrayEntity out = new ByteArrayEntity(buf.toByteArray());
final GzipDecompressingEntity gunzipe = new GzipDecompressingEntity(out);
Assert.assertEquals("some kind of text", EntityUtils.toString(gunzipe, Consts.ASCII));
}