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


Java MultipartEntityBuilder类代码示例

本文整理汇总了Java中org.apache.http.entity.mime.MultipartEntityBuilder的典型用法代码示例。如果您正苦于以下问题:Java MultipartEntityBuilder类的具体用法?Java MultipartEntityBuilder怎么用?Java MultipartEntityBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


MultipartEntityBuilder类属于org.apache.http.entity.mime包,在下文中一共展示了MultipartEntityBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: installBundle

import org.apache.http.entity.mime.MultipartEntityBuilder; //导入依赖的package包/类
/**
 * Install a bundle using the Felix webconsole HTTP interface, with a specific start level
 * @param f bundle file
 * @param startBundle whether to start or just install the bundle
 * @param startLevel start level
 * @return the sling response
 * @throws ClientException if the request failed
 */
public SlingHttpResponse installBundle(File f, boolean startBundle, int startLevel) throws ClientException {
    // Setup request for Felix Webconsole bundle install
    MultipartEntityBuilder builder = MultipartEntityBuilder.create()
            .addTextBody("action", "install")
            .addBinaryBody("bundlefile", f);
    if (startBundle) {
        builder.addTextBody("bundlestart", "true");
    }
    if (startLevel > 0) {
        builder.addTextBody("bundlestartlevel", String.valueOf(startLevel));
        LOG.info("Installing bundle {} at start level {}", f.getName(), startLevel);
    } else {
        LOG.info("Installing bundle {} at default start level", f.getName());
    }

    return this.doPost(URL_BUNDLES, builder.build(), 302);

}
 
开发者ID:apache,项目名称:sling-org-apache-sling-testing-clients,代码行数:27,代码来源:OsgiConsoleClient.java

示例2: upload

import org.apache.http.entity.mime.MultipartEntityBuilder; //导入依赖的package包/类
@Override
public String upload(String url, Map<String, String> requestHeaders, Map<String, String> parameters,
                     Map<String, File> files, String charset) {
    if (validator.isEmpty(files))
        return post(url, requestHeaders, parameters, charset);

    MultipartEntityBuilder entity = MultipartEntityBuilder.create();
    ContentType contentType = ContentType.create("text/plain", context.getCharset(charset));
    if (!validator.isEmpty(parameters))
        parameters.forEach((key, value) -> entity.addTextBody(key, value, contentType));
    files.forEach(entity::addBinaryBody);
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    postByEntity(url, requestHeaders, entity.build(), null, outputStream);

    return outputStream.toString();
}
 
开发者ID:heisedebaise,项目名称:tephra,代码行数:17,代码来源:HttpImpl.java

示例3: addBody

import org.apache.http.entity.mime.MultipartEntityBuilder; //导入依赖的package包/类
@SneakyThrows
protected void addBody(MultipartEntityBuilder request, VxmlRequestTask task) {

	super.addBody(request, task);

	String id = task.getKey();
	if (task.getUtterances().isEmpty()) {
		task.addUtterance(String.format("%s/%s-2-%s-1.wav", id, id, parameters.getPrintName()));
	}
	File utterance = task.getUtterances().get(0);

	byte[] byteArray = IOUtils.toByteArray(new FileInputStream(utterance));
	request.addBinaryBody(REQ_UTTERANCE, byteArray);

	if (task.isFeatureVector()) {
		request.addTextBody(REQ_FEATURE_VECTOR, "true");
	}

	if (parameters.isTextPrompted()) {
		request.addTextBody(REQ_VOCAB, parameters.getVocab());
		String fileName = FilenameUtils.removeExtension(utterance.getPath());
		request.addTextBody(REQ_PHRASE, FileUtils.readFileToString(new File(String.format("%s.txt", fileName)), "UTF-8").trim());
	}

	summary.getByteCount().add(byteArray.length);
}
 
开发者ID:Auraya,项目名称:armorvox-client,代码行数:27,代码来源:VxmlClientVerify.java

示例4: getHttpEntity

import org.apache.http.entity.mime.MultipartEntityBuilder; //导入依赖的package包/类
@Override
public HttpEntity getHttpEntity() {
  MultipartEntityBuilder builder = MultipartEntityBuilder.create();

  if (url != null)
    builder.addTextBody(URL_FIELD, url);

  if (certificate != null)
    builder.addBinaryBody(CERTIFICATE_FIELD, new File(certificate));

  if (maxConnections != null)
    builder.addTextBody(MAX_CONNECTIONS_FIELD, maxConnections.toString());

  if (allowedUpdates != null) {
    if (allowedUpdates.length == 0) {
      builder.addTextBody(ALLOWED_UPDATES_FIELD, "[]");
    } else {
      for (String allowedUpdate : allowedUpdates) {
        builder.addTextBody(ALLOWED_UPDATES_FIELD + "[]", allowedUpdate);
      }
    }
  }

  return builder.build();
}
 
开发者ID:AgeOfWar,项目名称:Telejam,代码行数:26,代码来源:SetWebhook.java

示例5: setupMultipartEntity

import org.apache.http.entity.mime.MultipartEntityBuilder; //导入依赖的package包/类
private void setupMultipartEntity(HttpPost httpPost){
    if(isDebug){
        log("Request upload file:"+mFile.getName() +"  exists:"+ mFile.exists());
    }
    MultipartEntityBuilder entity = MultipartEntityBuilder.create()
            .seContentType(ContentType.MULTIPART_FORM_DATA)
            .setMode(HttpMultipartMode.BROWSER_COMPATIBLE)
            .addBinaryBody(mName,mFile,ContentType.DEFAULT_BINARY,mFileName) //uploadFile对应服务端类的同名属性<File类型>
            .setCharset(DEFAULT_CHARSET);

    for (String key:mFileParames.keySet()) {
        String value = mFileParames.get(key);
        entity.addTextBody(key,value);
    }
    httpPost.setEntity(entity.build());
}
 
开发者ID:fcibook,项目名称:QuickHttp,代码行数:17,代码来源:QuickHttpController.java

示例6: addBody

import org.apache.http.entity.mime.MultipartEntityBuilder; //导入依赖的package包/类
@SneakyThrows
protected void addBody(MultipartEntityBuilder request, VxmlRequestTask task) {

	super.addBody(request, task);

	long bytes = 0L;
	int idx = 0;

	for (File utterance : task.getUtterances()) {
		byte[] byteArray = IOUtils.toByteArray(new FileInputStream(utterance));
		request.addBinaryBody(REQ_UTTERANCE + (++idx), byteArray);
		bytes += byteArray.length;
	}
	if (task.isFeatureVector()) {
		request.addTextBody(REQ_FEATURE_VECTOR, "true");
	}
	summary.getByteCount().add(bytes);
}
 
开发者ID:Auraya,项目名称:armorvox-client,代码行数:19,代码来源:VxmlClientDetectGender.java

示例7: addBody

import org.apache.http.entity.mime.MultipartEntityBuilder; //导入依赖的package包/类
@SneakyThrows
@Override
protected void addBody(MultipartEntityBuilder request, VxmlRequestTask task) {

	super.addBody(request, task);

	request.addTextBody(REQ_PRINT_NAME, parameters.getPrintName());
	request.addTextBody(REQ_CHANNEL, parameters.getChannel());
	request.addTextBody(REQ_MODE, parameters.getMode());

	String fileName = FilenameUtils.removeExtension(task.getKey());
	if (parameters.isTextPrompted()) {
		request.addTextBody(REQ_PHRASE, FileUtils.readFileToString(new File(String.format("%s.txt", fileName)), "UTF-8").trim());
		request.addTextBody(REQ_VOCAB, parameters.getVocab());
	}
}
 
开发者ID:Auraya,项目名称:armorvox-client,代码行数:17,代码来源:VxmlClientCheckQuality.java

示例8: addTpl

import org.apache.http.entity.mime.MultipartEntityBuilder; //导入依赖的package包/类
/**
 * 
 * @param param
 *            apikey sign
 * @param layout
 *            {@code VideoLayout}
 * @param material
 *            视频资料zip文件
 * 
 * @return
 */
public Result<Template> addTpl(Map<String, String> param, String layout, byte[] material) {
    Result<Template> r = new Result<>();
    if (layout == null || material == null) return r.setCode(Code.ARGUMENT_MISSING);
    List<NameValuePair> list = param2pair(param, r, APIKEY, SIGN);
    if (r.getCode() != Code.OK) return r;

    Charset ch = Charset.forName(charset());
    MultipartEntityBuilder builder = MultipartEntityBuilder.create().setCharset(ch).setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
    for (NameValuePair pair : list) {
        builder.addTextBody(pair.getName(), pair.getValue(), ContentType.create("text/plain", ch));
    }
    builder.addTextBody(LAYOUT, layout, ContentType.APPLICATION_JSON);
    builder.addBinaryBody(MATERIAL, material, ContentType.create("application/octet-stream", ch), null);

    StdResultHandler<Template> h = new StdResultHandler<>();
    try {
        return path("add_tpl.json").post(new HttpEntityWrapper(builder.build()), h, r);
    } catch (Exception e) {
        return h.catchExceptoin(e, r);
    }
}
 
开发者ID:yunpian,项目名称:yunpian-java-sdk,代码行数:33,代码来源:VideoSmsApi.java

示例9: PostData

import org.apache.http.entity.mime.MultipartEntityBuilder; //导入依赖的package包/类
static void PostData() throws Exception {
	final String url = "https://upload.gyazo.com/api/upload";
	final HttpClient httpclient = new Downloader().client;

	// create the post request.
	final HttpPost httppost = new HttpPost(url);
	final MultipartEntityBuilder builder = MultipartEntityBuilder.create();

	final File f = new File("./src/main/resources/assets/signpic/textures/logo.png");
	builder.addBinaryBody("imagedata", f, ContentType.DEFAULT_BINARY, f.getName());
	builder.addTextBody("access_token", "4d080e95be741beba0b74653a872668326a79526784d2daed9190dc584bffad7");
	httppost.setEntity(builder.build());

	// execute request
	final HttpResponse response = httpclient.execute(httppost);
	final HttpEntity resEntity = response.getEntity();
	final InputStream stream = resEntity.getContent();

	System.out.println(response.getStatusLine());
	System.out.println(convertStreamToString(stream));

}
 
开发者ID:Team-Fruit,项目名称:SignPicture,代码行数:23,代码来源:Debug.java

示例10: execute

import org.apache.http.entity.mime.MultipartEntityBuilder; //导入依赖的package包/类
@Override
public WxMediaUploadResult execute(String uri, File file) throws WxErrorException, IOException {
  HttpPost httpPost = new HttpPost(uri);
  if (requestHttp.getRequestHttpProxy() != null) {
    RequestConfig config = RequestConfig.custom().setProxy(requestHttp.getRequestHttpProxy()).build();
    httpPost.setConfig(config);
  }
  if (file != null) {
    HttpEntity entity = MultipartEntityBuilder
      .create()
      .addBinaryBody("media", file)
      .setMode(HttpMultipartMode.RFC6532)
      .build();
    httpPost.setEntity(entity);
  }
  try (CloseableHttpResponse response = requestHttp.getRequestHttpClient().execute(httpPost)) {
    String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response);
    WxError error = WxError.fromJson(responseContent);
    if (error.getErrorCode() != 0) {
      throw new WxErrorException(error);
    }
    return WxMediaUploadResult.fromJson(responseContent);
  } finally {
    httpPost.releaseConnection();
  }
}
 
开发者ID:binarywang,项目名称:weixin-java-tools,代码行数:27,代码来源:ApacheMediaUploadRequestExecutor.java

示例11: post

import org.apache.http.entity.mime.MultipartEntityBuilder; //导入依赖的package包/类
public Response post(String url, String auth, JsonJavaObject postData, File fileUpload) throws JsonException, IOException, URISyntaxException {
	URI normUri = new URI(url).normalize();
	Request postRequest = Request.Post(normUri);
	
	//Add all headers
	if(StringUtil.isNotEmpty(auth)) {
		postRequest.addHeader("Authorization", auth);
	}
	
	MultipartEntityBuilder builder = MultipartEntityBuilder.create();
	builder.addBinaryBody("images_file", fileUpload, ContentType.APPLICATION_OCTET_STREAM, fileUpload.getName());
	
	if(postData != null) {
		String postDataString = JsonGenerator.toJson(JsonJavaFactory.instanceEx, postData);
		builder.addTextBody("classifier_ids", postDataString, ContentType.MULTIPART_FORM_DATA);
	}
	
	HttpEntity multipart = builder.build();
	postRequest.body(multipart);
	
	Response response = executor.execute(postRequest);
	return response;
}
 
开发者ID:OpenNTF,项目名称:XPages-Fusion-Application,代码行数:24,代码来源:RestUtil.java

示例12: setMultipartFileData

import org.apache.http.entity.mime.MultipartEntityBuilder; //导入依赖的package包/类
/**
 * This will take a list of files, and attach them to the 
 * MultipartEntityBuilder instance
 * @param files Files to add
 * @param builder builder 
 */
private void setMultipartFileData( final Map<String,PostFile> files, 
  final MultipartEntityBuilder builder )
{
  //..Check for input files
  if ( files == null || builder == null )
    return;    
  
  for ( final String name : files.keySet())
  {
    //..Ensure the file exists
    final PostFile pf = files.get( name );

    if ( !pf.getFile().exists())
    {
      throw new IllegalArgumentException( 
        pf.getFile() + " (" + pf.getFilename() 
          + ") does not exist; cannot upload non-existent file." );
    }

    APILog.trace( LOG, "Added file", pf.getFile(), "(", pf.getFilename(), ")" );

    builder.addBinaryBody( name, pf.getFile(), pf.getContentType(), pf.getFilename());
  }
}
 
开发者ID:SixArmDonkey,项目名称:aerodrome-for-jet,代码行数:31,代码来源:API.java

示例13: addStreamToEntity

import org.apache.http.entity.mime.MultipartEntityBuilder; //导入依赖的package包/类
/**
 * Adds a stream to an HTTP entity
 *
 * @param someStream Input stream to be added to an HTTP entity
 * @param fieldName A description of the entity content
 * @param fileName Name of the file attached as an entity
 * @return HTTP entity
 * @throws IOException Signals a failure while reading the input stream
 */
HttpEntity addStreamToEntity(InputStream someStream, String fieldName, String fileName) throws IOException {
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    int bytesRead;
    byte[] bytes = new byte[1024];
    while ((bytesRead = someStream.read(bytes)) > 0) {
        byteArrayOutputStream.write(bytes, 0, bytesRead);
    }
    byte[] data = byteArrayOutputStream.toByteArray();

    MultipartEntityBuilder builder = MultipartEntityBuilder.create();
    builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
    builder.setStrictMode();
    builder.addBinaryBody(fieldName, data, ContentType.MULTIPART_FORM_DATA, fileName);
    return builder.build();
}
 
开发者ID:Microsoft,项目名称:Cognitive-SpeakerRecognition-Android,代码行数:25,代码来源:SpeakerRestClientHelper.java

示例14: postForm

import org.apache.http.entity.mime.MultipartEntityBuilder; //导入依赖的package包/类
private HttpPost postForm(String url, Map<String, String> params, Map<String, File> files, String charset) {
    if (StringUtils.isBlank(charset)) {
        charset = "UTF-8";
    }

    HttpPost httpPost = new HttpPost(url);
    MultipartEntityBuilder builder = MultipartEntityBuilder.create();
    if (null != params) {
        Set<String> keySet = params.keySet();
        for (String key : keySet) {
            builder.addTextBody(key, params.get(key), ContentType.create("text/plain", Charset.forName(charset)));
        }
    }
    if (CollectionUtils.isBlank(files)) {
        for (String filename : files.keySet()) {
            builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
            builder.addBinaryBody(filename, files.get(filename), ContentType.DEFAULT_BINARY, filename);
        }
    }
    httpPost.setEntity(builder.build());

    return httpPost;
}
 
开发者ID:storezhang,项目名称:utils,代码行数:24,代码来源:HttpClient.java

示例15: upload

import org.apache.http.entity.mime.MultipartEntityBuilder; //导入依赖的package包/类
/**
 * Upload a binary file (using a post request).
 * 
 * @param path
 * @param params
 * @param filePath
 * @return
 */
public JSONObject upload(String path, String params, String filePath){
	String uri = this.endpoint + path;
	if(params != null || params != ""){
		uri += "?" + params;
	}
	HttpPost request = new HttpPost(uri);
	
	HttpEntity entity = (HttpEntity) MultipartEntityBuilder
			.create()
			.addBinaryBody("result", new File(filePath), 
					ContentType.create("application/octet-stream"), 
					"filename"
			)
			.build();
	
	request.setEntity(entity);	
	return processRequest(request);
}
 
开发者ID:aroog,项目名称:code,代码行数:27,代码来源:Request.java


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