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


Java InputStreamEntity.setContentType方法代码示例

本文整理汇总了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;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:24,代码来源:OkApacheClient.java

示例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;
}
 
开发者ID:lizhangqu,项目名称:PriorityOkHttp,代码行数:24,代码来源:OkApacheClient.java

示例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;
}
 
开发者ID:codeWatching,项目名称:codePay,代码行数:32,代码来源:HttpClientUtil.java

示例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();
    }
}
 
开发者ID:Nyceane,项目名称:HackathonPADLS,代码行数:21,代码来源:TriggerActivity.java

示例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.");
}
 
开发者ID:hpe-idol,项目名称:java-aci-api-ng,代码行数:18,代码来源:BinaryResponseProcessorTest.java

示例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.");
}
 
开发者ID:hpe-idol,项目名称:java-aci-api-ng,代码行数:18,代码来源:BinaryResponseProcessorTest.java

示例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;
	}
}
 
开发者ID:jayxue,项目名称:ImageS3Android,代码行数:19,代码来源:ImageS3Service.java

示例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;
}
 
开发者ID:NannanZ,项目名称:spdymcsclient,代码行数:24,代码来源:UTILS.java

示例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;
}
 
开发者ID:NannanZ,项目名称:spdymcsclient,代码行数:24,代码来源:OkApacheClient.java

示例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);
    }

}
 
开发者ID:mixi-inc,项目名称:mixi-API-SDK-for-Android,代码行数:31,代码来源:MixiContainerImpl.java

示例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);
    }
}
 
开发者ID:iterate-ch,项目名称:java-openstack-swift,代码行数:32,代码来源:Client.java

示例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;
}
 
开发者ID:zucchi,项目名称:ZucchiSpeech,代码行数:24,代码来源:DictationHTTPClient.java

示例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;
}
 
开发者ID:equella,项目名称:Equella,代码行数:12,代码来源:AbstractRestApiTest.java

示例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");
}
 
开发者ID:equella,项目名称:Equella,代码行数:12,代码来源:AbstractItemApiTest.java

示例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;
}
 
开发者ID:Plonk42,项目名称:mytracks,代码行数:10,代码来源:AndroidGDataClient.java


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