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


Java ContentType.APPLICATION_OCTET_STREAM属性代码示例

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


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

示例1: doUpload

private static void doUpload(CloseableHttpClient client, String path) throws IOException {

        String url = String.format(
                "http://%s:%s/%s",
                TestProperties.getProperty("com.guido.host"),
                TestProperties.getProperty("com.guido.port"),
                path
        );

        InputStreamEntity requestEntity = new InputStreamEntity(
                new FileInputStream(BIG_XML_FILE_PATH), -1,
                ContentType.APPLICATION_OCTET_STREAM);

        // set chunked transfer encoding ie. no Content-length
        requestEntity.setChunked(true);

        HttpPost httpPost = new HttpPost((url));
        httpPost.setEntity(requestEntity);
        HttpResponse response = client.execute(httpPost);

        assertThat(response.getStatusLine().getStatusCode(), equalTo(HttpStatus.SC_OK));

    }
 
开发者ID:guido-n,项目名称:mule-useful-experiments,代码行数:23,代码来源:Tests.java

示例2: upload

public void upload(LocalResource resource, URI destination) throws IOException {
    HttpPut method = new HttpPut(destination);
    final RepeatableInputStreamEntity entity = new RepeatableInputStreamEntity(resource, ContentType.APPLICATION_OCTET_STREAM);
    method.setEntity(entity);
    CloseableHttpResponse response = null;
    try {
        response = http.performHttpRequest(method);
        if (!http.wasSuccessful(response)) {
            throw new IOException(String.format("Could not PUT '%s'. Received status code %s from server: %s",
                destination, response.getStatusLine().getStatusCode(), response.getStatusLine().getReasonPhrase()));
        }
    } finally {
        HttpClientUtils.closeQuietly(response);
    }
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:15,代码来源:HttpResourceUploader.java

示例3: setDefaults

private void setDefaults() {

        this.url = "";
        this.port = DEFAULT_HTTP_PORT;

        this.uploadMethod = UPLOAD_METHOD__PUT;
        this.contentType = ContentType.APPLICATION_OCTET_STREAM;

        this.socketBufferSize = DEFAULT_SOCKET_BUFFER_SIZE;

        invalidateInternalClient();
    }
 
开发者ID:Axway,项目名称:ats-framework,代码行数:12,代码来源:FileTransferHttpClient.java

示例4: entities

@Test
public void entities() throws IOException {

    StringEntity entity = new StringEntity("important message", Consts.UTF_8);

    EntityUtils.toString(entity);
    EntityUtils.toByteArray(entity);

    StringBuilder sb = new StringBuilder();
    Map<String, String> env = System.getenv();
    for (Map.Entry<String, String> envEntry : env.entrySet()) {
        sb.append(envEntry.getKey())
                .append(": ").append(envEntry.getValue())
                .append("\r\n");
    }

    // construct without a character encoding (defaults to ISO-8859-1)
    HttpEntity myEntity1 = new StringEntity(sb.toString());

    // alternatively construct with an encoding (mime type defaults to "text/plain")
    HttpEntity myEntity2 = new StringEntity(sb.toString(), Consts.UTF_8);

    // alternatively construct with an encoding and a mime type
    HttpEntity myEntity3 = new StringEntity(sb.toString(),
            ContentType.create("text/plain", Consts.UTF_8));

    BasicHttpEntity myEntity = new BasicHttpEntity();
    myEntity.setContent(new FileInputStream(""));
    myEntity.setContentLength(340); // sets the length to 340

    new ByteArrayEntity(new byte[] {1,2,3},
            ContentType.APPLICATION_OCTET_STREAM);

    new FileEntity(new File(""),
            ContentType.create("application/java-archive"));
}
 
开发者ID:daishicheng,项目名称:outcomes,代码行数:36,代码来源:TestHttpCore.java


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