当前位置: 首页>>代码示例>>Java>>正文


Java ContentType.create方法代码示例

本文整理汇总了Java中com.epam.reportportal.apache.http.entity.ContentType.create方法的典型用法代码示例。如果您正苦于以下问题:Java ContentType.create方法的具体用法?Java ContentType.create怎么用?Java ContentType.create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.epam.reportportal.apache.http.entity.ContentType的用法示例。


在下文中一共展示了ContentType.create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testDefaultContent

import com.epam.reportportal.apache.http.entity.ContentType; //导入方法依赖的package包/类
@Test
public void testDefaultContent() throws Exception {
    final String s = "Message content";
    StringEntity httpentity = new StringEntity(s, ContentType.create("text/csv", "ANSI_X3.4-1968"));
    Assert.assertEquals("text/csv; charset=US-ASCII",
            httpentity.getContentType().getValue());
    httpentity = new StringEntity(s, Consts.ASCII.name());
    Assert.assertEquals("text/plain; charset=US-ASCII",
            httpentity.getContentType().getValue());
    httpentity = new StringEntity(s, Consts.ASCII);
    Assert.assertEquals("text/plain; charset=US-ASCII",
            httpentity.getContentType().getValue());
    httpentity = new StringEntity(s);
    Assert.assertEquals("text/plain; charset=ISO-8859-1",
            httpentity.getContentType().getValue());
}
 
开发者ID:reportportal,项目名称:client-java-httpclient-repacked,代码行数:17,代码来源:TestStringEntity.java

示例2: testNullCharset

import com.epam.reportportal.apache.http.entity.ContentType; //导入方法依赖的package包/类
@Test
public void testNullCharset() throws Exception {
    final String s = constructString(SWISS_GERMAN_HELLO);
    StringEntity httpentity = new StringEntity(s, ContentType.create("text/plain", (Charset) null));
    Assert.assertNotNull(httpentity.getContentType());
    Assert.assertEquals("text/plain", httpentity.getContentType().getValue());
    Assert.assertEquals(s, EntityUtils.toString(httpentity));
    httpentity = new StringEntity(s, (Charset) null);
    Assert.assertNotNull(httpentity.getContentType());
    Assert.assertEquals("text/plain", httpentity.getContentType().getValue());
    Assert.assertEquals(s, EntityUtils.toString(httpentity));
    httpentity = new StringEntity(s, (String) null);
    Assert.assertNotNull(httpentity.getContentType());
    Assert.assertEquals("text/plain", httpentity.getContentType().getValue());
    Assert.assertEquals(s, EntityUtils.toString(httpentity));
}
 
开发者ID:reportportal,项目名称:client-java-httpclient-repacked,代码行数:17,代码来源:TestStringEntity.java

示例3: testParseEntityDefaultContentType

import com.epam.reportportal.apache.http.entity.ContentType; //导入方法依赖的package包/类
@Test
public void testParseEntityDefaultContentType() throws Exception {
    final String ch_hello = constructString(SWISS_GERMAN_HELLO);
    final String us_hello = "hi there";
    final List <NameValuePair> parameters = new ArrayList<NameValuePair>();
    parameters.add(new BasicNameValuePair("english", us_hello));
    parameters.add(new BasicNameValuePair("swiss", ch_hello));

    final String s = URLEncodedUtils.format(parameters, HTTP.DEF_CONTENT_CHARSET);

    Assert.assertEquals("english=hi+there&swiss=Gr%FCezi_z%E4m%E4", s);

    final StringEntity entity = new StringEntity(s, ContentType.create(
            URLEncodedUtils.CONTENT_TYPE, HTTP.DEF_CONTENT_CHARSET));
    final List <NameValuePair> result = URLEncodedUtils.parse(entity);
    Assert.assertEquals(2, result.size());
    assertNameValuePair(result.get(0), "english", us_hello);
    assertNameValuePair(result.get(1), "swiss", ch_hello);
}
 
开发者ID:reportportal,项目名称:client-java-httpclient-repacked,代码行数:20,代码来源:TestURLEncodedUtils.java

示例4: testStringBody

import com.epam.reportportal.apache.http.entity.ContentType; //导入方法依赖的package包/类
@Test
public void testStringBody() throws Exception {
    final StringBody b1 = new StringBody("text", ContentType.DEFAULT_TEXT);
    Assert.assertEquals(4, b1.getContentLength());

    Assert.assertEquals("ISO-8859-1", b1.getCharset());

    Assert.assertNull(b1.getFilename());
    Assert.assertEquals("text/plain", b1.getMimeType());
    Assert.assertEquals("text", b1.getMediaType());
    Assert.assertEquals("plain", b1.getSubType());

    Assert.assertEquals(MIME.ENC_8BIT, b1.getTransferEncoding());

    final StringBody b2 = new StringBody("more text",
            ContentType.create("text/other", MIME.DEFAULT_CHARSET));
    Assert.assertEquals(9, b2.getContentLength());
    Assert.assertEquals(MIME.DEFAULT_CHARSET.name(), b2.getCharset());

    Assert.assertNull(b2.getFilename());
    Assert.assertEquals("text/other", b2.getMimeType());
    Assert.assertEquals("text", b2.getMediaType());
    Assert.assertEquals("other", b2.getSubType());

    Assert.assertEquals(MIME.ENC_8BIT, b2.getTransferEncoding());
}
 
开发者ID:reportportal,项目名称:client-java-httpclient-repacked,代码行数:27,代码来源:TestMultipartContentBody.java

示例5: testInputStreamBody

import com.epam.reportportal.apache.http.entity.ContentType; //导入方法依赖的package包/类
@Test
public void testInputStreamBody() throws Exception {
    final byte[] stuff = "Stuff".getBytes("US-ASCII");
    final InputStreamBody b1 = new InputStreamBody(new ByteArrayInputStream(stuff), "stuff");
    Assert.assertEquals(-1, b1.getContentLength());

    Assert.assertNull(b1.getCharset());
    Assert.assertEquals("stuff", b1.getFilename());
    Assert.assertEquals("application/octet-stream", b1.getMimeType());
    Assert.assertEquals("application", b1.getMediaType());
    Assert.assertEquals("octet-stream", b1.getSubType());

    Assert.assertEquals(MIME.ENC_BINARY, b1.getTransferEncoding());

    final InputStreamBody b2 = new InputStreamBody(
            new ByteArrayInputStream(stuff), ContentType.create("some/stuff"), "stuff");
    Assert.assertEquals(-1, b2.getContentLength());
    Assert.assertNull(b2.getCharset());
    Assert.assertEquals("stuff", b2.getFilename());
    Assert.assertEquals("some/stuff", b2.getMimeType());
    Assert.assertEquals("some", b2.getMediaType());
    Assert.assertEquals("stuff", b2.getSubType());

    Assert.assertEquals(MIME.ENC_BINARY, b2.getTransferEncoding());
}
 
开发者ID:reportportal,项目名称:client-java-httpclient-repacked,代码行数:26,代码来源:TestMultipartContentBody.java

示例6: testParseUTF8Entity

import com.epam.reportportal.apache.http.entity.ContentType; //导入方法依赖的package包/类
@Test
public void testParseUTF8Entity() throws Exception {
    final String ru_hello = constructString(RUSSIAN_HELLO);
    final String ch_hello = constructString(SWISS_GERMAN_HELLO);
    final List <NameValuePair> parameters = new ArrayList<NameValuePair>();
    parameters.add(new BasicNameValuePair("russian", ru_hello));
    parameters.add(new BasicNameValuePair("swiss", ch_hello));

    final String s = URLEncodedUtils.format(parameters, Consts.UTF_8);

    Assert.assertEquals("russian=%D0%92%D1%81%D0%B5%D0%BC_%D0%BF%D1%80%D0%B8%D0%B2%D0%B5%D1%82" +
            "&swiss=Gr%C3%BCezi_z%C3%A4m%C3%A4", s);

    final StringEntity entity = new StringEntity(s, ContentType.create(
            URLEncodedUtils.CONTENT_TYPE, Consts.UTF_8));
    final List <NameValuePair> result = URLEncodedUtils.parse(entity);
    Assert.assertEquals(2, result.size());
    assertNameValuePair(result.get(0), "russian", ru_hello);
    assertNameValuePair(result.get(1), "swiss", ch_hello);
}
 
开发者ID:reportportal,项目名称:client-java-httpclient-repacked,代码行数:21,代码来源:TestURLEncodedUtils.java

示例7: FileBody

import com.epam.reportportal.apache.http.entity.ContentType; //导入方法依赖的package包/类
/**
 * @since 4.1
 *
 * @deprecated (4.3) use {@link FileBody#FileBody(File, ContentType, String)}
 *   or {@link MultipartEntityBuilder}
 */
@Deprecated
public FileBody(final File file,
                final String filename,
                final String mimeType,
                final String charset) {
    this(file, ContentType.create(mimeType, charset), filename);
}
 
开发者ID:reportportal,项目名称:client-java-httpclient-repacked,代码行数:14,代码来源:FileBody.java

示例8: testBasis

import com.epam.reportportal.apache.http.entity.ContentType; //导入方法依赖的package包/类
@Test
public void testBasis() throws Exception {
    final ContentType contentType = ContentType.create("text/plain", "US-ASCII");
    Assert.assertEquals("text/plain", contentType.getMimeType());
    Assert.assertEquals("US-ASCII", contentType.getCharset().name());
    Assert.assertEquals("text/plain; charset=US-ASCII", contentType.toString());
}
 
开发者ID:reportportal,项目名称:client-java-httpclient-repacked,代码行数:8,代码来源:TestContentType.java

示例9: testWithCharset

import com.epam.reportportal.apache.http.entity.ContentType; //导入方法依赖的package包/类
@Test
public void testWithCharset() throws Exception {
    ContentType contentType = ContentType.create("text/plain", "US-ASCII");
    Assert.assertEquals("text/plain", contentType.getMimeType());
    Assert.assertEquals("US-ASCII", contentType.getCharset().name());
    Assert.assertEquals("text/plain; charset=US-ASCII", contentType.toString());
    contentType = contentType.withCharset(Charset.forName("UTF-8"));
    Assert.assertEquals("text/plain", contentType.getMimeType());
    Assert.assertEquals("UTF-8", contentType.getCharset().name());
    Assert.assertEquals("text/plain; charset=UTF-8", contentType.toString());
}
 
开发者ID:reportportal,项目名称:client-java-httpclient-repacked,代码行数:12,代码来源:TestContentType.java

示例10: testWithCharsetString

import com.epam.reportportal.apache.http.entity.ContentType; //导入方法依赖的package包/类
@Test
public void testWithCharsetString() throws Exception {
    ContentType contentType = ContentType.create("text/plain", "US-ASCII");
    Assert.assertEquals("text/plain", contentType.getMimeType());
    Assert.assertEquals("US-ASCII", contentType.getCharset().name());
    Assert.assertEquals("text/plain; charset=US-ASCII", contentType.toString());
    contentType = contentType.withCharset("UTF-8");
    Assert.assertEquals("text/plain", contentType.getMimeType());
    Assert.assertEquals("UTF-8", contentType.getCharset().name());
    Assert.assertEquals("text/plain; charset=UTF-8", contentType.toString());
}
 
开发者ID:reportportal,项目名称:client-java-httpclient-repacked,代码行数:12,代码来源:TestContentType.java

示例11: testMultipartFormStringParts

import com.epam.reportportal.apache.http.entity.ContentType; //导入方法依赖的package包/类
@Test
public void testMultipartFormStringParts() throws Exception {
    final FormBodyPart p1 = new FormBodyPart(
            "field1",
            new StringBody("this stuff", ContentType.DEFAULT_TEXT));
    final FormBodyPart p2 = new FormBodyPart(
            "field2",
            new StringBody("that stuff", ContentType.create(
                    ContentType.TEXT_PLAIN.getMimeType(), Consts.UTF_8)));
    final FormBodyPart p3 = new FormBodyPart(
            "field3",
            new StringBody("all kind of stuff", ContentType.DEFAULT_TEXT));
    final HttpStrictMultipart multipart = new HttpStrictMultipart("form-data", null, "foo",
            Arrays.asList(p1, p2, p3));

    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    multipart.writeTo(out);
    out.close();

    final String expected =
        "--foo\r\n" +
        "Content-Disposition: form-data; name=\"field1\"\r\n" +
        "Content-Type: text/plain; charset=ISO-8859-1\r\n" +
        "Content-Transfer-Encoding: 8bit\r\n" +
        "\r\n" +
        "this stuff\r\n" +
        "--foo\r\n" +
        "Content-Disposition: form-data; name=\"field2\"\r\n" +
        "Content-Type: text/plain; charset=UTF-8\r\n" +
        "Content-Transfer-Encoding: 8bit\r\n" +
        "\r\n" +
        "that stuff\r\n" +
        "--foo\r\n" +
        "Content-Disposition: form-data; name=\"field3\"\r\n" +
        "Content-Type: text/plain; charset=ISO-8859-1\r\n" +
        "Content-Transfer-Encoding: 8bit\r\n" +
        "\r\n" +
        "all kind of stuff\r\n" +
        "--foo--\r\n";
    final String s = out.toString("US-ASCII");
    Assert.assertEquals(expected, s);
    Assert.assertEquals(s.length(), multipart.getTotalLength());
}
 
开发者ID:reportportal,项目名称:client-java-httpclient-repacked,代码行数:44,代码来源:TestMultipartForm.java

示例12: testMultipartFormStrict

import com.epam.reportportal.apache.http.entity.ContentType; //导入方法依赖的package包/类
@Test
public void testMultipartFormStrict() throws Exception {
    tmpfile = File.createTempFile("tmp", ".bin");
    final Writer writer = new FileWriter(tmpfile);
    try {
        writer.append("some random whatever");
    } finally {
        writer.close();
    }

    final FormBodyPart p1 = new FormBodyPart(
            "field1",
            new FileBody(tmpfile));
    final FormBodyPart p2 = new FormBodyPart(
            "field2",
            new FileBody(tmpfile, ContentType.create("text/plain", "ANSI_X3.4-1968"), "test-file"));
    final FormBodyPart p3 = new FormBodyPart(
            "field3",
            new InputStreamBody(new FileInputStream(tmpfile), "file.tmp"));
    final HttpStrictMultipart multipart = new HttpStrictMultipart("form-data", null, "foo",
            Arrays.asList(p1, p2, p3));

    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    multipart.writeTo(out);
    out.close();

    final String expected =
        "--foo\r\n" +
        "Content-Disposition: form-data; name=\"field1\"; " +
            "filename=\"" + tmpfile.getName() + "\"\r\n" +
        "Content-Type: application/octet-stream\r\n" +
        "Content-Transfer-Encoding: binary\r\n" +
        "\r\n" +
        "some random whatever\r\n" +
        "--foo\r\n" +
        "Content-Disposition: form-data; name=\"field2\"; " +
            "filename=\"test-file\"\r\n" +
        "Content-Type: text/plain; charset=US-ASCII\r\n" +
        "Content-Transfer-Encoding: binary\r\n" +
        "\r\n" +
        "some random whatever\r\n" +
        "--foo\r\n" +
        "Content-Disposition: form-data; name=\"field3\"; " +
            "filename=\"file.tmp\"\r\n" +
        "Content-Type: application/octet-stream\r\n" +
        "Content-Transfer-Encoding: binary\r\n" +
        "\r\n" +
        "some random whatever\r\n" +
        "--foo--\r\n";
    final String s = out.toString("US-ASCII");
    Assert.assertEquals(expected, s);
    Assert.assertEquals(-1, multipart.getTotalLength());
}
 
开发者ID:reportportal,项目名称:client-java-httpclient-repacked,代码行数:54,代码来源:TestMultipartForm.java

示例13: testMultipartFormRFC6532

import com.epam.reportportal.apache.http.entity.ContentType; //导入方法依赖的package包/类
@Test
public void testMultipartFormRFC6532() throws Exception {
    tmpfile = File.createTempFile("tmp", ".bin");
    final Writer writer = new FileWriter(tmpfile);
    try {
        writer.append("some random whatever");
    } finally {
        writer.close();
    }

    final FormBodyPart p1 = new FormBodyPart(
            "field1\u0414",
            new FileBody(tmpfile));
    final FormBodyPart p2 = new FormBodyPart(
            "field2",
            new FileBody(tmpfile, ContentType.create("text/plain", "ANSI_X3.4-1968"), "test-file"));
    final FormBodyPart p3 = new FormBodyPart(
            "field3",
            new InputStreamBody(new FileInputStream(tmpfile), "file.tmp"));
    final HttpRFC6532Multipart multipart = new HttpRFC6532Multipart("form-data", null, "foo",
            Arrays.asList(p1, p2, p3));

    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    multipart.writeTo(out);
    out.close();

    final String expected =
        "--foo\r\n" +
        "Content-Disposition: form-data; name=\"field1\u0414\"; " +
            "filename=\"" + tmpfile.getName() + "\"\r\n" +
        "Content-Type: application/octet-stream\r\n" +
        "Content-Transfer-Encoding: binary\r\n" +
        "\r\n" +
        "some random whatever\r\n" +
        "--foo\r\n" +
        "Content-Disposition: form-data; name=\"field2\"; " +
            "filename=\"test-file\"\r\n" +
        "Content-Type: text/plain; charset=US-ASCII\r\n" +
        "Content-Transfer-Encoding: binary\r\n" +
        "\r\n" +
        "some random whatever\r\n" +
        "--foo\r\n" +
        "Content-Disposition: form-data; name=\"field3\"; " +
            "filename=\"file.tmp\"\r\n" +
        "Content-Type: application/octet-stream\r\n" +
        "Content-Transfer-Encoding: binary\r\n" +
        "\r\n" +
        "some random whatever\r\n" +
        "--foo--\r\n";
    final String s = out.toString("UTF-8");
    Assert.assertEquals(expected, s);
    Assert.assertEquals(-1, multipart.getTotalLength());
}
 
开发者ID:reportportal,项目名称:client-java-httpclient-repacked,代码行数:54,代码来源:TestMultipartForm.java

示例14: testMultipartFormStringPartsMultiCharsets

import com.epam.reportportal.apache.http.entity.ContentType; //导入方法依赖的package包/类
@Test
public void testMultipartFormStringPartsMultiCharsets() throws Exception {
    final String s1 = constructString(SWISS_GERMAN_HELLO);
    final String s2 = constructString(RUSSIAN_HELLO);

    final FormBodyPart p1 = new FormBodyPart(
            "field1",
            new StringBody(s1, ContentType.create("text/plain", Charset.forName("ISO-8859-1"))));
    final FormBodyPart p2 = new FormBodyPart(
            "field2",
            new StringBody(s2, ContentType.create("text/plain", Charset.forName("KOI8-R"))));
    final HttpStrictMultipart multipart = new HttpStrictMultipart("form-data", null, "foo",
            Arrays.asList(p1, p2));

    final ByteArrayOutputStream out1 = new ByteArrayOutputStream();
    multipart.writeTo(out1);
    out1.close();

    final ByteArrayOutputStream out2 = new ByteArrayOutputStream();

    out2.write((
        "--foo\r\n" +
        "Content-Disposition: form-data; name=\"field1\"\r\n" +
        "Content-Type: text/plain; charset=ISO-8859-1\r\n" +
        "Content-Transfer-Encoding: 8bit\r\n" +
        "\r\n").getBytes("US-ASCII"));
    out2.write(s1.getBytes("ISO-8859-1"));
    out2.write(("\r\n" +
        "--foo\r\n" +
        "Content-Disposition: form-data; name=\"field2\"\r\n" +
        "Content-Type: text/plain; charset=KOI8-R\r\n" +
        "Content-Transfer-Encoding: 8bit\r\n" +
        "\r\n").getBytes("US-ASCII"));
    out2.write(s2.getBytes("KOI8-R"));
    out2.write(("\r\n" +
        "--foo--\r\n").getBytes("US-ASCII"));
    out2.close();

    final byte[] actual = out1.toByteArray();
    final byte[] expected = out2.toByteArray();

    Assert.assertEquals(expected.length, actual.length);
    for (int i = 0; i < actual.length; i++) {
        Assert.assertEquals(expected[i], actual[i]);
    }
    Assert.assertEquals(expected.length, multipart.getTotalLength());
}
 
开发者ID:reportportal,项目名称:client-java-httpclient-repacked,代码行数:48,代码来源:TestMultipartForm.java

示例15: StringBody

import com.epam.reportportal.apache.http.entity.ContentType; //导入方法依赖的package包/类
/**
 * Create a StringBody from the specified text, MIME type and character set.
 *
 * @param text to be used for the body, not {@code null}
 * @param mimeType the MIME type, not {@code null}
 * @param charset the character set, may be {@code null}, in which case the US-ASCII charset is used
 * @throws UnsupportedEncodingException
 * @throws IllegalArgumentException if the {@code text} parameter is null
 *
 * @deprecated (4.3) use {@link StringBody#StringBody(String, ContentType)}
 *   or {@link MultipartEntityBuilder}
 */
@Deprecated
public StringBody(
        final String text,
        final String mimeType,
        final Charset charset) throws UnsupportedEncodingException {
    this(text, ContentType.create(mimeType, charset));
}
 
开发者ID:reportportal,项目名称:client-java-httpclient-repacked,代码行数:20,代码来源:StringBody.java


注:本文中的com.epam.reportportal.apache.http.entity.ContentType.create方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。