當前位置: 首頁>>代碼示例>>Java>>正文


Java InputStreamBody類代碼示例

本文整理匯總了Java中org.apache.http.entity.mime.content.InputStreamBody的典型用法代碼示例。如果您正苦於以下問題:Java InputStreamBody類的具體用法?Java InputStreamBody怎麽用?Java InputStreamBody使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


InputStreamBody類屬於org.apache.http.entity.mime.content包,在下文中一共展示了InputStreamBody類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testInputStreamBody

import org.apache.http.entity.mime.content.InputStreamBody; //導入依賴的package包/類
@Test
public void testInputStreamBody() throws Exception {
    final byte[] stuff = "Stuff".getBytes(Consts.ASCII);
    final InputStreamBody b1 = new InputStreamBody(new ByteArrayInputStream(stuff), "stuff");
    Assert.assertEquals(-1, b1.getContentLength());

    Assert.assertNull(b1.getCharset());
    Assert.assertEquals("stuff", b1.getFilename());
    Assert.assertEquals("application/octet-stream", b1.getMimeType());
    Assert.assertEquals("application", b1.getMediaType());
    Assert.assertEquals("octet-stream", b1.getSubType());

    Assert.assertEquals(MIME.ENC_BINARY, b1.getTransferEncoding());

    final InputStreamBody b2 = new InputStreamBody(
            new ByteArrayInputStream(stuff), ContentType.create("some/stuff"), "stuff");
    Assert.assertEquals(-1, b2.getContentLength());
    Assert.assertNull(b2.getCharset());
    Assert.assertEquals("stuff", b2.getFilename());
    Assert.assertEquals("some/stuff", b2.getMimeType());
    Assert.assertEquals("some", b2.getMediaType());
    Assert.assertEquals("stuff", b2.getSubType());

    Assert.assertEquals(MIME.ENC_BINARY, b2.getTransferEncoding());
}
 
開發者ID:MyPureCloud,項目名稱:purecloud-iot,代碼行數:26,代碼來源:TestMultipartContentBody.java

示例2: materialAdd_material

import org.apache.http.entity.mime.content.InputStreamBody; //導入依賴的package包/類
/**
 * 新增其他類型永久素材
 * @param access_token
 * @param mediaType
 * @param inputStream  	多媒體文件有格式和大小限製,如下:
					圖片(image): 128K,支持JPG格式
					語音(voice):256K,播放長度不超過60s,支持AMR\MP3格式
					視頻(video):1MB,支持MP4格式
					縮略圖(thumb):64KB,支持JPG格式
 * @param description 視頻文件類型額外字段,其它類型不用添加
 * @return
 */
public static Media materialAdd_material(String access_token,MediaType mediaType,InputStream inputStream,Description description){
	HttpPost httpPost = new HttpPost(MEDIA_URI+"/cgi-bin/material/add_material");
       @SuppressWarnings("deprecation")
	InputStreamBody inputStreamBody = new InputStreamBody(inputStream, mediaType.mimeType(),"temp."+mediaType.fileSuffix());
       MultipartEntityBuilder multipartEntityBuilder = MultipartEntityBuilder.create()
 			.addPart("media", inputStreamBody);
	if(description != null){
		multipartEntityBuilder.addTextBody("description", JsonUtil.toJSONString(description));
	}
	HttpEntity reqEntity = multipartEntityBuilder.addTextBody("access_token", access_token)
	                 .addTextBody("type",mediaType.uploadType())
	                 .build();
       httpPost.setEntity(reqEntity);
	return LocalHttpClient.executeJsonResult(httpPost,Media.class);
}
 
開發者ID:qiangstrong,項目名稱:Weixin,代碼行數:28,代碼來源:MaterialAPI.java

示例3: testOTAWrongToken

import org.apache.http.entity.mime.content.InputStreamBody; //導入依賴的package包/類
@Test
public void testOTAWrongToken() throws Exception {
    HttpPost post = new HttpPost(httpsAdminServerUrl + "/ota/start?token=" + 123);
    post.setHeader(HttpHeaderNames.AUTHORIZATION.toString(), "Basic " + Base64.getEncoder().encodeToString(auth));

    String fileName = "test.bin";

    InputStream binFile = OTATest.class.getResourceAsStream("/static/ota/" + fileName);
    ContentBody fileBody = new InputStreamBody(binFile, ContentType.APPLICATION_OCTET_STREAM, fileName);

    MultipartEntityBuilder builder = MultipartEntityBuilder.create();
    builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
    builder.addPart("upfile", fileBody);
    HttpEntity entity = builder.build();

    post.setEntity(entity);

    try (CloseableHttpResponse response = httpclient.execute(post)) {
        assertEquals(400, response.getStatusLine().getStatusCode());
        String error = consumeText(response);

        assertNotNull(error);
        assertEquals("Invalid token.", error);
    }
}
 
開發者ID:blynkkk,項目名稱:blynk-server,代碼行數:26,代碼來源:OTATest.java

示例4: testAuthorizationFailed

import org.apache.http.entity.mime.content.InputStreamBody; //導入依賴的package包/類
@Test
public void testAuthorizationFailed() throws Exception {
    HttpPost post = new HttpPost(httpsAdminServerUrl + "/ota/start?token=" + 123);
    post.setHeader(HttpHeaderNames.AUTHORIZATION.toString(), "Basic " + Base64.getEncoder().encodeToString("123:123".getBytes()));

    String fileName = "test.bin";

    InputStream binFile = OTATest.class.getResourceAsStream("/static/ota/" + fileName);
    ContentBody fileBody = new InputStreamBody(binFile, ContentType.APPLICATION_OCTET_STREAM, fileName);

    MultipartEntityBuilder builder = MultipartEntityBuilder.create();
    builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
    builder.addPart("upfile", fileBody);
    HttpEntity entity = builder.build();

    post.setEntity(entity);

    try (CloseableHttpResponse response = httpclient.execute(post)) {
        assertEquals(403, response.getStatusLine().getStatusCode());
        String error = consumeText(response);

        assertNotNull(error);
        assertEquals("Authentication failed.", error);
    }
}
 
開發者ID:blynkkk,項目名稱:blynk-server,代碼行數:26,代碼來源:OTATest.java

示例5: basicOTAForNonExistingSingleUser

import org.apache.http.entity.mime.content.InputStreamBody; //導入依賴的package包/類
@Test
public void basicOTAForNonExistingSingleUser() throws Exception {
    HttpPost post = new HttpPost(httpsAdminServerUrl + "/ota/[email protected]");
    post.setHeader(HttpHeaderNames.AUTHORIZATION.toString(), "Basic " + Base64.getEncoder().encodeToString(auth));

    String fileName = "test.bin";

    InputStream binFile = OTATest.class.getResourceAsStream("/static/ota/" + fileName);
    ContentBody fileBody = new InputStreamBody(binFile, ContentType.APPLICATION_OCTET_STREAM, fileName);

    MultipartEntityBuilder builder = MultipartEntityBuilder.create();
    builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
    builder.addPart("upfile", fileBody);
    HttpEntity entity = builder.build();

    post.setEntity(entity);

    try (CloseableHttpResponse response = httpclient.execute(post)) {
        assertEquals(400, response.getStatusLine().getStatusCode());
        String er = consumeText(response);
        assertNotNull(er);
        assertEquals("Requested user not found.", er);
    }
}
 
開發者ID:blynkkk,項目名稱:blynk-server,代碼行數:25,代碼來源:OTATest.java

示例6: makePost

import org.apache.http.entity.mime.content.InputStreamBody; //導入依賴的package包/類
/** Utility method:
 * Formulate an HTTP POST request to upload the batch query file
 * @param queryBody
 * @return
 * @throws UnsupportedEncodingException
 */
private HttpPost makePost(String queryBody) throws UnsupportedEncodingException {
    HttpPost post = new HttpPost(ClueWebSearcher.BATCH_CATB_BASEURL);
    InputStreamBody qparams = 
        new InputStreamBody(
                new ReaderInputStream(new StringReader(queryBody)),
                "text/plain",
        "query.txt");

    MultipartEntity entity = new MultipartEntity();
    entity.addPart("viewstatus", new StringBody("1")); 
    entity.addPart("indextype",  new StringBody("catbparams"));
    entity.addPart("countmax",   new StringBody("100"));
    entity.addPart("formattype", new StringBody(format));
    entity.addPart("infile",     qparams);

    post.setEntity(entity);
    return post;
}
 
開發者ID:TeamCohen,項目名稱:SEAL,代碼行數:25,代碼來源:ClueWebSearcher.java

示例7: request

import org.apache.http.entity.mime.content.InputStreamBody; //導入依賴的package包/類
private JSON request(HttpEntityEnclosingRequestBase req, Issue.NewAttachment... attachments)
    throws RestException, IOException {
    if (attachments != null) {
        req.setHeader("X-Atlassian-Token", "nocheck");
        MultipartEntity ent = new MultipartEntity();
        for(Issue.NewAttachment attachment : attachments) {
            String filename = attachment.getFilename();
            Object content = attachment.getContent();
            if (content instanceof byte[]) {
                ent.addPart("file", new ByteArrayBody((byte[]) content, filename));
            } else if (content instanceof InputStream) {
                ent.addPart("file", new InputStreamBody((InputStream) content, filename));
            } else if (content instanceof File) {
                ent.addPart("file", new FileBody((File) content, filename));
            } else if (content == null) {
                throw new IllegalArgumentException("Missing content for the file " + filename);
            } else {
                throw new IllegalArgumentException(
                    "Expected file type byte[], java.io.InputStream or java.io.File but provided " +
                        content.getClass().getName() + " for the file " + filename);
            }
        }
        req.setEntity(ent);
    }
    return request(req);
}
 
開發者ID:rcarz,項目名稱:jira-client,代碼行數:27,代碼來源:RestClient.java

示例8: postUpload

import org.apache.http.entity.mime.content.InputStreamBody; //導入依賴的package包/類
@Override
public <V> V postUpload(String uri, Map<String, String> stringParts, InputStream in, String mimeType, String fileName,
		final long fileSize, Class<V> type) throws IOException {
	HttpPost request = new HttpPost(createURI(uri));
	configureRequest(request);

	MultipartEntity entity = new MultipartEntity();
	for(Map.Entry<String, String> entry : stringParts.entrySet())
		entity.addPart(entry.getKey(), StringBody.create(entry.getValue(), "text/plain", UTF_8));

	entity.addPart("file", new InputStreamBody(in, mimeType, fileName) {
		@Override
		public long getContentLength() {
			return fileSize;
		}
	});
	request.setEntity(entity);
	return executeRequest(request, type, null);
}
 
開發者ID:puppetlabs,項目名稱:puppetdb-javaclient,代碼行數:20,代碼來源:HttpComponentsConnector.java

示例9: addBitmap

import org.apache.http.entity.mime.content.InputStreamBody; //導入依賴的package包/類
public static void addBitmap(MultipartEntity multipartEntity, Bitmap image,
        String imageId) {
    int measureId = PerformanceMeasure.startMeasure();
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    image.compress(CompressFormat.JPEG, BitmapUtils.JPEG_COMPRESSION_LEVEL,
            bos);
    ByteArrayInputStream bs = new ByteArrayInputStream(bos.toByteArray());

    InputStreamBody body = new InputStreamBody(bs, "image/jpeg", imageId);
    multipartEntity.addPart(imageId, body);
    PerformanceMeasure.endMeasure(measureId, "Jpeg compression time");

    Log.d(TAG,
            "Multipart entry after bitmap addition: "
                    + multipartEntity.toString());
}
 
開發者ID:cuipengpeng,項目名稱:p1-android,代碼行數:17,代碼來源:BatchUtil.java

示例10: createRequest

import org.apache.http.entity.mime.content.InputStreamBody; //導入依賴的package包/類
@Override
protected HttpUriRequest createRequest() throws IOException {
    MultipartEntity entity = new MultipartEntity();          
    List<NameValuePair> dataList = getData();
    for (NameValuePair d : dataList) {
        entity.addPart(new FormBodyPart(d.getName(), new StringBody(d.getValue(), Charset.forName("utf-8"))));
    }
    for (Map.Entry<String, InputStreamBody> entry : files.entrySet()) {
        entity.addPart(new FormBodyPart(entry.getKey(), entry.getValue()));
    }
    
    
    final HttpPost request = new HttpPost(url);

    if(this.sendProgressListener != null) {
        CountingRequestEntity countingEntity = new CountingRequestEntity(entity, this.sendProgressListener);
        request.setEntity(countingEntity);
    } else {
        request.setEntity(entity);
    }
    return request;
}
 
開發者ID:yuvipanda,項目名稱:java-http-fluent,代碼行數:23,代碼來源:Http.java

示例11: getNewFileMultipartEntity

import org.apache.http.entity.mime.content.InputStreamBody; //導入依賴的package包/類
private static MultipartEntityWithProgressListener getNewFileMultipartEntity(final String parentId, final InputStream inputStream, final String fileName)
    throws BoxRestException, UnsupportedEncodingException {
    MultipartEntityWithProgressListener me = new MultipartEntityWithProgressListener(HttpMultipartMode.BROWSER_COMPATIBLE);
    me.addPart(Constants.FOLDER_ID, new StringBody(parentId));
    String date = ISO8601DateParser.toString(new Date());
    if (me.getPart(KEY_CONTENT_CREATED_AT) == null) {
        me.addPart(KEY_CONTENT_CREATED_AT, new StringBody(date));
    }
    if (me.getPart(KEY_CONTENT_MODIFIED_AT) == null) {
        me.addPart(KEY_CONTENT_MODIFIED_AT, new StringBody(date));
    }

    me.addPart(fileName, new InputStreamBody(inputStream, fileName));

    return me;
}
 
開發者ID:mobilesystems,項目名稱:box-java-sdk-v2,代碼行數:17,代碼來源:BoxFileUploadRequestObject.java

示例12: newContentBody

import org.apache.http.entity.mime.content.InputStreamBody; //導入依賴的package包/類
private ContentBody newContentBody(Part part) {
  ContentType contentType = ContentType.create(part.getMediaType());
  if (part instanceof TextPart) {
    TextPart textPart = (TextPart)part;
    return new StringBody(textPart.getText(), contentType);
  }
  BinaryPart binaryPart = (BinaryPart)part;
  return new InputStreamBody(binaryPart.getData(), contentType, binaryPart.getDownloadName());
}
 
開發者ID:Enterprise-Content-Management,項目名稱:infoarchive-sip-sdk,代碼行數:10,代碼來源:ApacheHttpClient.java

示例13: testNonRepeatable

import org.apache.http.entity.mime.content.InputStreamBody; //導入依賴的package包/類
@Test
public void testNonRepeatable() throws Exception {
    final HttpEntity entity = MultipartEntityBuilder.create()
        .addPart("p1", new InputStreamBody(
            new ByteArrayInputStream("blah blah".getBytes()), ContentType.DEFAULT_BINARY))
        .addPart("p2", new InputStreamBody(
            new ByteArrayInputStream("yada yada".getBytes()), ContentType.DEFAULT_BINARY))
        .build();
    Assert.assertFalse(entity.isRepeatable());
    Assert.assertTrue(entity.isChunked());
    Assert.assertTrue(entity.isStreaming());

    Assert.assertTrue(entity.getContentLength() == -1);
}
 
開發者ID:MyPureCloud,項目名稱:purecloud-iot,代碼行數:15,代碼來源:TestMultipartFormHttpEntity.java

示例14: sendPostUploadFile

import org.apache.http.entity.mime.content.InputStreamBody; //導入依賴的package包/類
public Observable<String> sendPostUploadFile(InputStream inputStream,
                                             String filename, String pid,
                                             Map<String, String> parameters) {
  return Observable.create(o -> {
    try {
      postConfigureStart(pid, parameters);
      
      // загрузка файла
      InputStreamBody bin = new InputStreamBody(inputStream,
          filename);

      MultipartEntity reqEntity = new MultipartEntity();
      reqEntity.addPart("bundlefile", bin);
      reqEntity.addPart("action", new StringBody("install"));
      reqEntity.addPart("bundlestart", new StringBody("start"));
      reqEntity.addPart("bundlestartlevel", new StringBody("1"));
      postHttpClientQuery(URL_BUNDLES, reqEntity, Collections
          .list(new BasicHeader("Accept", "application/json")));

      o.onNext("");
    } catch (Exception e) {
      throw Exceptions.propagate(e);
    }
    o.onCompleted();
  }).subscribeOn(Schedulers.from(mes)).cast(String.class);

}
 
開發者ID:semiotproject,項目名稱:semiot-platform,代碼行數:28,代碼來源:OSGiApiService.java

示例15: mediaUpload

import org.apache.http.entity.mime.content.InputStreamBody; //導入依賴的package包/類
/**
 * 上傳媒體文件
 * 媒體文件在後台保存時間為3天,即3天後media_id失效。
 * @param access_token
 * @param mediaType
 * @param inputStream  	多媒體文件有格式和大小限製,如下:
					圖片(image): 128K,支持JPG格式
					語音(voice):256K,播放長度不超過60s,支持AMR\MP3格式
					視頻(video):1MB,支持MP4格式
					縮略圖(thumb):64KB,支持JPG格式
 * @return
 */
public static Media mediaUpload(String access_token,MediaType mediaType,InputStream inputStream){
	HttpPost httpPost = new HttpPost(MEDIA_URI+"/cgi-bin/media/upload");
       @SuppressWarnings("deprecation")
	InputStreamBody inputStreamBody = new InputStreamBody(inputStream, mediaType.mimeType(),"temp."+mediaType.fileSuffix());
	HttpEntity reqEntity = MultipartEntityBuilder.create()
       		 .addPart("media",inputStreamBody)
                .addTextBody("access_token", access_token)
                .addTextBody("type",mediaType.uploadType())
                .build();
       httpPost.setEntity(reqEntity);
	return LocalHttpClient.executeJsonResult(httpPost,Media.class);
}
 
開發者ID:qiangstrong,項目名稱:Weixin,代碼行數:25,代碼來源:MediaAPI.java


注:本文中的org.apache.http.entity.mime.content.InputStreamBody類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。