本文整理汇总了Java中org.apache.http.entity.InputStreamEntity.setContentType方法的典型用法代码示例。如果您正苦于以下问题:Java InputStreamEntity.setContentType方法的具体用法?Java InputStreamEntity.setContentType怎么用?Java InputStreamEntity.setContentType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.http.entity.InputStreamEntity
的用法示例。
在下文中一共展示了InputStreamEntity.setContentType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: transformResponse
import org.apache.http.entity.InputStreamEntity; //导入方法依赖的package包/类
private static HttpResponse transformResponse(Response response) {
int code = response.code();
String message = response.message();
BasicHttpResponse httpResponse = new BasicHttpResponse(HTTP_1_1, code, message);
ResponseBody body = response.body();
InputStreamEntity entity = new InputStreamEntity(body.byteStream(), body.contentLength());
httpResponse.setEntity(entity);
Headers headers = response.headers();
for (int i = 0, size = headers.size(); i < size; i++) {
String name = headers.name(i);
String value = headers.value(i);
httpResponse.addHeader(name, value);
if ("Content-Type".equalsIgnoreCase(name)) {
entity.setContentType(value);
} else if ("Content-Encoding".equalsIgnoreCase(name)) {
entity.setContentEncoding(value);
}
}
return httpResponse;
}
示例2: transformResponse
import org.apache.http.entity.InputStreamEntity; //导入方法依赖的package包/类
private static HttpResponse transformResponse(Response response) throws IOException {
int code = response.code();
String message = response.message();
BasicHttpResponse httpResponse = new BasicHttpResponse(HTTP_1_1, code, message);
ResponseBody body = response.body();
InputStreamEntity entity = new InputStreamEntity(body.byteStream(), body.contentLength());
httpResponse.setEntity(entity);
Headers headers = response.headers();
for (int i = 0, size = headers.size(); i < size; i++) {
String name = headers.name(i);
String value = headers.value(i);
httpResponse.addHeader(name, value);
if ("Content-Type".equalsIgnoreCase(name)) {
entity.setContentType(value);
} else if ("Content-Encoding".equalsIgnoreCase(name)) {
entity.setContentEncoding(value);
}
}
return httpResponse;
}
示例3: sendPostStream
import org.apache.http.entity.InputStreamEntity; //导入方法依赖的package包/类
/**
* 向指定URL发送POST方法的数据流请求
*
* @param url 发送请求的URL
* @param message 请求数据
* @param isProxy 是否使用代理
* @return URL所代表远程资源的响应
*/
public static String sendPostStream(String url, String message, String encode, boolean isProxy) {
SafeHttpClient httpClient = HttpClientFactory.getHttpClient(isProxy);
HttpPost httpReq = new HttpPost(url);
try {
if (StringUtils.isNotBlank(message)) {
// 构造最简单的字符串数据
byte[] content = message.getBytes();
InputStream inputStream = new ByteArrayInputStream(content);
InputStreamEntity reqEntity = new InputStreamEntity(inputStream, content.length);
reqEntity.setContentType("application/x-www-form-urlencoded");
// 设置请求的数据
httpReq.setEntity(reqEntity);
}
ResponseHandler<String> responseHandler = new SimpleResponseHandler(encode);
return httpClient.execute(httpReq, responseHandler, new BasicHttpContext());
} catch (Exception e) {
LOGGER.error("sendPostStream请求远程地址失败,url:{},message:{},encode:{},isProxy:{},Exception:{}", url, message,
encode, isProxy, ExceptionUtil.getException(e));
httpReq.abort();
httpClient.closeExpiredConnections();
}
return null;
}
示例4: doInBackground
import org.apache.http.entity.InputStreamEntity; //导入方法依赖的package包/类
protected String doInBackground(String... urls) {
String url = "";
File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath(),"/audiorecordtest.3gp");
try {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(new URI(url));
InputStreamEntity reqEntity = new InputStreamEntity(
new FileInputStream(file), -1);
reqEntity.setContentType("binary/octet-stream");
reqEntity.setChunked(true); // Send in multiple parts if needed
httppost.setEntity(reqEntity);
HttpResponse response = httpclient.execute(httppost);
return response.toString();
} catch (Exception e) {
return e.getMessage().toString();
}
}
示例5: testErrorResponse
import org.apache.http.entity.InputStreamEntity; //导入方法依赖的package包/类
@Test(expected = AciErrorException.class)
public void testErrorResponse() throws IOException, ProcessorException, AciErrorException {
// Create the "response" and give it a content type...
final InputStreamEntity inputStreamEntity = new InputStreamEntity(getClass().getResourceAsStream("/AciException-1.xml"), -1);
inputStreamEntity.setContentType("text/xml");
// Create a response...
final BasicHttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK");
response.setEntity(inputStreamEntity);
// Set the AciResponseInputStream...
final AciResponseInputStream stream = new AciResponseInputStreamImpl(response);
// Process...
processor.process(stream);
fail("Should have thrown a AciErrorException.");
}
示例6: testXmlResponse
import org.apache.http.entity.InputStreamEntity; //导入方法依赖的package包/类
@Test(expected = AciErrorException.class)
public void testXmlResponse() throws IOException, ProcessorException, AciErrorException {
// Create the "response" and give it a content type...
final InputStreamEntity inputStreamEntity = new InputStreamEntity(getClass().getResourceAsStream("/GetVersion.xml"), -1);
inputStreamEntity.setContentType("text/xml");
// Create a response...
final BasicHttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK");
response.setEntity(inputStreamEntity);
// Set the AciResponseInputStream...
final AciResponseInputStream stream = new AciResponseInputStreamImpl(response);
// Process...
processor.process(stream);
fail("Should have thrown a AciErrorException.");
}
示例7: addImage
import org.apache.http.entity.InputStreamEntity; //导入方法依赖的package包/类
public static int addImage(String baseUrl, String imagePlantId, String filePath) {
File file = new File(filePath);
try {
HttpClient client = getClient();
String url = baseUrl + imagePlantId + "/images";
HttpPost httppost = new HttpPost(url);
InputStreamEntity reqEntity = new InputStreamEntity(new FileInputStream(file), -1);
reqEntity.setContentType("binary/octet-stream");
reqEntity.setChunked(true);
httppost.setEntity(reqEntity);
HttpResponse response = client.execute(httppost);
return response.getStatusLine().getStatusCode();
}
catch (Exception e) {
return -1;
}
}
示例8: transformResponse
import org.apache.http.entity.InputStreamEntity; //导入方法依赖的package包/类
public static HttpResponse transformResponse(Response response) {
int code = response.code();
String message = response.message();
BasicHttpResponse httpResponse = new BasicHttpResponse(HTTP_1_1, code, message);
ResponseBody body = response.body();
InputStreamEntity entity = new InputStreamEntity(body.byteStream(), body.contentLength());
httpResponse.setEntity(entity);
Headers headers = response.headers();
for (int i = 0; i < headers.size(); i++) {
String name = headers.name(i);
String value = headers.value(i);
httpResponse.addHeader(name, value);
if ("Content-Type".equalsIgnoreCase(name)) {
entity.setContentType(value);
} else if ("Content-Encoding".equalsIgnoreCase(name)) {
entity.setContentEncoding(value);
}
}
return httpResponse;
}
示例9: transformResponse
import org.apache.http.entity.InputStreamEntity; //导入方法依赖的package包/类
private static HttpResponse transformResponse(Response response) {
int code = response.code();
String message = response.message();
BasicHttpResponse httpResponse = new BasicHttpResponse(HTTP_1_1, code, message);
ResponseBody body = response.body();
InputStreamEntity entity = new InputStreamEntity(body.byteStream(), body.contentLength());
httpResponse.setEntity(entity);
Headers headers = response.headers();
for (int i = 0; i < headers.size(); i++) {
String name = headers.name(i);
String value = headers.value(i);
httpResponse.addHeader(name, value);
if ("Content-Type".equalsIgnoreCase(name)) {
entity.setContentType(value);
} else if ("Content-Encoding".equalsIgnoreCase(name)) {
entity.setContentEncoding(value);
}
}
return httpResponse;
}
示例10: getHttpMethod
import org.apache.http.entity.InputStreamEntity; //导入方法依赖的package包/类
/**
* HTTPメソッドを取得する
*
* @param endpointPath エンドポイント
* @param stream リクエストボディのInputStream
* @param length InputStreamの長さ
* @return HttpUriRequest
*/
private HttpUriRequest getHttpMethod(String endpointPath, String contentType,
HttpMethod method, InputStream stream, long length)
throws IOException {
InputStreamEntity entity = new InputStreamEntity(stream, length);
entity.setContentType(contentType);
switch (method) {
case POST:
HttpPost postMethod = new HttpPost(Constants.GRAPH_BASE_URL + endpointPath);
postMethod.setEntity(entity);
return postMethod;
case PUT:
HttpPut putMethod = new HttpPut(Constants.GRAPH_BASE_URL + endpointPath);
putMethod.setEntity(entity);
return putMethod;
default:
Log.e(TAG, "Unsupported http method");
throw new IllegalArgumentException("Unsupported HttpMethod parameter:" + method);
}
}
示例11: storeObject
import org.apache.http.entity.InputStreamEntity; //导入方法依赖的package包/类
/**
* Store a file on the server, including metadata, with the contents coming from an input stream. This allows you to
* not know the entire length of your content when you start to write it. Nor do you have to hold it entirely in memory
* at the same time.
*
* @param region The name of the storage region
* @param container The name of the container
* @param data Any object that implements InputStream
* @param contentType The MIME type of the file
* @param name The name of the file on the server
* @param metadata A map with the metadata as key names and values as the metadata values
* @return the file ETAG if response code is 201
* @throws GenericException Unexpected response
*/
public String storeObject(Region region, String container, InputStream data, String contentType, String name, Map<String, String> metadata) throws IOException {
HttpPut method = new HttpPut(region.getStorageUrl(container, name));
InputStreamEntity entity = new InputStreamEntity(data, -1);
entity.setChunked(true);
entity.setContentType(contentType);
method.setEntity(entity);
for(Map.Entry<String, String> key : this.renameObjectMetadata(metadata).entrySet()) {
method.setHeader(key.getKey(), key.getValue());
}
Response response = this.execute(method, new DefaultResponseHandler());
if(response.getStatusCode() == HttpStatus.SC_CREATED) {
return response.getResponseHeader(HttpHeaders.ETAG).getValue();
}
else {
throw new GenericException(response);
}
}
示例12: setAudioContent
import org.apache.http.entity.InputStreamEntity; //导入方法依赖的package包/类
private InputStreamEntity setAudioContent() throws NumberFormatException, Exception
{
File f = new File(audioFile);
if( !f.exists() )
{
System.out.println("Audio file does not exist: " + audioFile);
return null;
}
if( !isStreamed )
{
fileSize = f.length();
}
FileAudioStreamer fs = new FileAudioStreamer(audioFile, isStreamed , encodeToSpeex, Integer.parseInt(sampleRate));
InputStreamEntity reqEntity = new InputStreamEntity(fs.getInputStream(), -1);
fs.start();
reqEntity.setContentType(CODEC);
//reqEntity.setChunked(true);
return reqEntity;
}
示例13: getPut
import org.apache.http.entity.InputStreamEntity; //导入方法依赖的package包/类
protected HttpPut getPut(String url, File file, Object... paramNameValues) throws IOException
{
final HttpPut put = new HttpPut(appendQueryString(url, queryString(paramNameValues)));
if( file != null )
{
InputStreamEntity inputStreamEntity = new InputStreamEntity(new FileInputStream(file), file.length());
inputStreamEntity.setContentType("application/octet-stream");
put.setEntity(inputStreamEntity);
}
return put;
}
示例14: uploadFile
import org.apache.http.entity.InputStreamEntity; //导入方法依赖的package包/类
protected void uploadFile(String stagingDirUrl, String filename, URL resource, Object... params) throws IOException
{
String avatarUrl = stagingDirUrl + '/' + com.tle.common.URLUtils.urlEncode(filename);
HttpPut putfile = new HttpPut(appendQueryString(avatarUrl, queryString(params)));
URLConnection file = resource.openConnection();
InputStreamEntity inputStreamEntity = new InputStreamEntity(file.getInputStream(), file.getContentLength());
inputStreamEntity.setContentType("application/octet-stream");
putfile.setEntity(inputStreamEntity);
HttpResponse putfileResponse = execute(putfile, true);
assertResponse(putfileResponse, 200, "200 not returned from file upload");
}
示例15: createRequest
import org.apache.http.entity.InputStreamEntity; //导入方法依赖的package包/类
public HttpUriRequest createRequest(URI uri) {
HttpPost post = new HttpPost(uri);
post.addHeader(X_HTTP_METHOD_OVERRIDE, "PUT");
InputStreamEntity entity =
new InputStreamEntity(mMediaInputStream, -1 /* read until EOF */);
entity.setContentType(mContentType);
post.setEntity(entity);
return post;
}