本文整理汇总了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));
}
示例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);
}
}
示例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();
}
示例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"));
}