當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。