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