• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java StreamDataBodyPart类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: getFormPostResponse

import org.glassfish.jersey.media.multipart.file.StreamDataBodyPart; //导入依赖的package包/类
protected final Response getFormPostResponse(String data,
                                             String endpoint,
                                             Class<? extends OutputStream> compressingClass,
                                             String encoding) throws IOException {
  byte[] bytes;
  if (compressingClass == null) {
    bytes = data.getBytes(StandardCharsets.UTF_8);
  } else {
    bytes = compress(data, compressingClass);
  }
  MediaType type =
      encoding == null ? MediaType.TEXT_PLAIN_TYPE : new MediaType("application", encoding);
  InputStream in = new ByteArrayInputStream(bytes);
  StreamDataBodyPart filePart = new StreamDataBodyPart("data", in, "data", type);
  try (MultiPart multiPart = new MultiPart(MediaType.MULTIPART_FORM_DATA_TYPE)) {
    multiPart.getBodyParts().add(filePart);
    return target(endpoint).request().post(
        Entity.entity(multiPart, MediaType.MULTIPART_FORM_DATA_TYPE));
  }
}
 
开发者ID:oncewang,项目名称:oryx2,代码行数:21,代码来源:AbstractServingTest.java


示例2: sendFax

import org.glassfish.jersey.media.multipart.file.StreamDataBodyPart; //导入依赖的package包/类
@Override
public APIResponse sendFax(String faxNumber,
                              InputStream[] streamsToSendAsFax,
                              String[] mediaTypes,
                              Optional<SendFaxOptions> options) throws IOException, URISyntaxException {

	if (streamsToSendAsFax.length != mediaTypes.length) {
		throw new IllegalArgumentException("Stream and file name arrays do not have the same length");
	}

       MultiPart multiPart = new MultiPart();
       for (int i=0; i < streamsToSendAsFax.length; i++) {
           final String entityName = "file"+i;
           final StreamDataBodyPart streamDataBodyPart = new StreamDataBodyPart(
                                                                   entityName,
                                                                   streamsToSendAsFax[i],
                                                                   entityName,
                                                                   MediaType.valueOf(mediaTypes[i]));
           multiPart.bodyPart(streamDataBodyPart);
       }

       return sendMultiPartFax(faxNumber, multiPart, options);
}
 
开发者ID:interfax,项目名称:interfax-java,代码行数:24,代码来源:DefaultInterFAXClient.java


示例3: getEntity

import org.glassfish.jersey.media.multipart.file.StreamDataBodyPart; //导入依赖的package包/类
@Override
public Entity getEntity(List<MultiPartItem> items, String mediaType) {
    MultiPart multiPart = new MultiPart();
    for (MultiPartItem item : items) {
        if (item.getValue() == null || item.getValue().isNull()) {
            continue;
        }
        String name = item.getName();
        String filename = item.getFilename();
        ScriptValue sv = item.getValue();
        String ct = item.getContentType();                    
        if (ct == null) {
            ct = HttpUtils.getContentType(sv);
        }
        MediaType itemType = MediaType.valueOf(ct);
        if (name == null) { // most likely multipart/mixed
            BodyPart bp = new BodyPart().entity(sv.getAsString()).type(itemType);
            multiPart.bodyPart(bp);
        } else if (filename != null) {
            StreamDataBodyPart part = new StreamDataBodyPart(name, sv.getAsStream(), filename, itemType);
            multiPart.bodyPart(part);
        } else {
            multiPart.bodyPart(new FormDataBodyPart(name, sv.getAsString(), itemType));
        }
    }
    return Entity.entity(multiPart, mediaType);
}
 
开发者ID:intuit,项目名称:karate,代码行数:28,代码来源:JerseyHttpClient.java


示例4: uploadSchemaVersion

import org.glassfish.jersey.media.multipart.file.StreamDataBodyPart; //导入依赖的package包/类
public SchemaIdVersion uploadSchemaVersion(final String schemaBranchName,
                                           final String schemaName,
                                           final String description,
                                           final InputStream schemaVersionInputStream)
        throws InvalidSchemaException, IncompatibleSchemaException, SchemaNotFoundException, SchemaBranchNotFoundException {

    SchemaMetadataInfo schemaMetadataInfo = getSchemaMetadataInfo(schemaName);
    if (schemaMetadataInfo == null) {
        throw new SchemaNotFoundException("Schema with name " + schemaName + " not found");
    }

    StreamDataBodyPart streamDataBodyPart = new StreamDataBodyPart("file", schemaVersionInputStream);

    WebTarget target = currentSchemaRegistryTargets().schemasTarget.path(schemaName).path("/versions/upload").queryParam("branch",schemaBranchName);
    MultiPart multipartEntity =
            new FormDataMultiPart()
                    .field("description", description, MediaType.APPLICATION_JSON_TYPE)
                    .bodyPart(streamDataBodyPart);

    Entity<MultiPart> multiPartEntity = Entity.entity(multipartEntity, MediaType.MULTIPART_FORM_DATA);
    Response response = Subject.doAs(subject, new PrivilegedAction<Response>() {
        @Override
        public Response run() {
            return target.request().post(multiPartEntity, Response.class);
        }
    });
    return handleSchemaIdVersionResponse(schemaMetadataInfo, response);
}
 
开发者ID:hortonworks,项目名称:registry,代码行数:29,代码来源:SchemaRegistryClient.java


示例5: uploadFile

import org.glassfish.jersey.media.multipart.file.StreamDataBodyPart; //导入依赖的package包/类
@Override
public String uploadFile(InputStream inputStream) {
    MultiPart multiPart = new MultiPart();
    BodyPart filePart = new StreamDataBodyPart("file", inputStream, "file");
    multiPart.bodyPart(filePart);
    return Subject.doAs(subject, new PrivilegedAction<String>() {
        @Override
        public String run() {
            return currentSchemaRegistryTargets().filesTarget.request()
                                                             .post(Entity.entity(multiPart, MediaType.MULTIPART_FORM_DATA), String.class);
        }
    });
}
 
开发者ID:hortonworks,项目名称:registry,代码行数:14,代码来源:SchemaRegistryClient.java


示例6: importWorkflowConfig

import org.glassfish.jersey.media.multipart.file.StreamDataBodyPart; //导入依赖的package包/类
@Override
public WorkflowConfig importWorkflowConfig(
  FormDataContentDisposition contentDispositionHeader, InputStream in,
  Long projectId, String authToken) throws Exception {

  Logger.getLogger(getClass())
      .debug("Workflow Client - import workflow config");
  validateNotEmpty(projectId, "projectId");

  StreamDataBodyPart fileDataBodyPart = new StreamDataBodyPart("file", in,
      "filename.dat", MediaType.APPLICATION_OCTET_STREAM_TYPE);
  FormDataMultiPart multiPart = new FormDataMultiPart();
  multiPart.bodyPart(fileDataBodyPart);

  ClientConfig clientConfig = new ClientConfig();
  clientConfig.register(MultiPartFeature.class);
  Client client = ClientBuilder.newClient(clientConfig);

  WebTarget target = client.target(config.getProperty("base.url")
      + "/config/import" + "?projectId=" + projectId);

  Response response = target.request(MediaType.APPLICATION_XML)
      .header("Authorization", authToken)
      .post(Entity.entity(multiPart, MediaType.MULTIPART_FORM_DATA_TYPE));

  String resultString = response.readEntity(String.class);

  if (response.getStatusInfo().getFamily() == Family.SUCCESSFUL) {
    // n/a
  } else {
    throw new Exception(response.toString());
  }
  // converting to object
  return ConfigUtility.getGraphForString(resultString,
      WorkflowConfigJpa.class);
}
 
开发者ID:WestCoastInformatics,项目名称:UMLS-Terminology-Server,代码行数:37,代码来源:WorkflowClientRest.java


示例7: importChecklist

import org.glassfish.jersey.media.multipart.file.StreamDataBodyPart; //导入依赖的package包/类
@Override
public Checklist importChecklist(
  FormDataContentDisposition contentDispositionHeader, InputStream in,
  Long projectId, String checklistName, String authToken) throws Exception {

  Logger.getLogger(getClass()).debug("Workflow Client - import checklist");
  validateNotEmpty(projectId, "projectId");
  validateNotEmpty(checklistName, "checklistName");

  StreamDataBodyPart fileDataBodyPart = new StreamDataBodyPart("file", in,
      "filename.dat", MediaType.APPLICATION_OCTET_STREAM_TYPE);
  FormDataMultiPart multiPart = new FormDataMultiPart();
  multiPart.bodyPart(fileDataBodyPart);

  ClientConfig clientConfig = new ClientConfig();
  clientConfig.register(MultiPartFeature.class);
  Client client = ClientBuilder.newClient(clientConfig);

  WebTarget target = client
      .target(config.getProperty("base.url") + "/workflow/checklist/import"
          + "?projectId=" + projectId + "&name=" + checklistName);

  Response response = target.request(MediaType.APPLICATION_XML)
      .header("Authorization", authToken)
      .post(Entity.entity(multiPart, MediaType.MULTIPART_FORM_DATA_TYPE));

  String resultString = response.readEntity(String.class);

  if (response.getStatusInfo().getFamily() == Family.SUCCESSFUL) {
    // n/a
  } else {
    throw new Exception(response.toString());
  }
  // converting to object
  return ConfigUtility.getGraphForString(resultString, ChecklistJpa.class);

}
 
开发者ID:WestCoastInformatics,项目名称:UMLS-Terminology-Server,代码行数:38,代码来源:WorkflowClientRest.java


示例8: importProcessConfig

import org.glassfish.jersey.media.multipart.file.StreamDataBodyPart; //导入依赖的package包/类
@Override
public ProcessConfig importProcessConfig(
  FormDataContentDisposition contentDispositionHeader, InputStream in,
  Long projectId, String authToken) throws Exception {

  Logger.getLogger(getClass())
      .debug("Process Client - import process config");
  validateNotEmpty(projectId, "projectId");

  StreamDataBodyPart fileDataBodyPart = new StreamDataBodyPart("file", in,
      "filename.dat", MediaType.APPLICATION_OCTET_STREAM_TYPE);
  FormDataMultiPart multiPart = new FormDataMultiPart();
  multiPart.bodyPart(fileDataBodyPart);

  ClientConfig clientConfig = new ClientConfig();
  clientConfig.register(MultiPartFeature.class);
  Client client = ClientBuilder.newClient(clientConfig);

  WebTarget target = client.target(config.getProperty("base.url")
      + "/config/import" + "?projectId=" + projectId);

  Response response = target.request(MediaType.APPLICATION_XML)
      .header("Authorization", authToken)
      .post(Entity.entity(multiPart, MediaType.MULTIPART_FORM_DATA_TYPE));

  String resultString = response.readEntity(String.class);

  if (response.getStatusInfo().getFamily() == Family.SUCCESSFUL) {
    // n/a
  } else {
    throw new Exception(response.toString());
  }
  // converting to object
  return ConfigUtility.getGraphForString(resultString,
      ProcessConfigJpa.class);

}
 
开发者ID:WestCoastInformatics,项目名称:UMLS-Terminology-Server,代码行数:38,代码来源:ProcessClientRest.java


示例9: createMedia

import org.glassfish.jersey.media.multipart.file.StreamDataBodyPart; //导入依赖的package包/类
public JSONObject createMedia(final YaasAwareParameters yaasAware, final InputStream fileInputStream,
        final AccessToken token) {

    final FormDataMultiPart multiPart = new FormDataMultiPart();
    multiPart.bodyPart(new StreamDataBodyPart("file", fileInputStream));

    final JSONObject payload = new JSONObject();
    payload.put("Content-Type", MediaType.MULTIPART_FORM_DATA);

    final Response responseUrl = mediaClient // get URL
            .$public()
            .files()
            .preparePost()
            .withAuthorization(token.toAuthorizationHeaderValue())
            .withPayload(payload.toString())
            .execute();

    if (responseUrl.getStatus() == Response.Status.OK.getStatusCode()) {
        final JSONObject mediaCreate = new JSONObject(responseUrl.readEntity(String.class));
        final String uploadLink = mediaCreate.getString("uploadLink");
        final String uploadEndpointId = mediaCreate.getString("id");
        final WebTarget webTarget = ClientBuilder.newClient().target(uploadLink);
        final Response responsePut = webTarget.request() // put media
                .put(Entity.entity(fileInputStream, MediaType.MULTIPART_FORM_DATA));
        if (responsePut.getStatus() == Response.Status.OK.getStatusCode()) {
            final Response responseCommit = mediaClient.$public().files().fileId(uploadEndpointId).commit() // commit
                    .preparePost().withAuthorization(token.toAuthorizationHeaderValue()).execute(); // media
            if (responseCommit.getStatus() == Response.Status.OK.getStatusCode()) {
                final JSONObject mediaCommited = new JSONObject(responseCommit.readEntity(String.class));
                return mediaCommited;
            }
        }
    }

    throw ErrorHandler.resolveErrorResponse(responseUrl, token);
}
 
开发者ID:SAP,项目名称:yaas_java_jersey_wishlist,代码行数:37,代码来源:MediaClientService.java


示例10: upload

import org.glassfish.jersey.media.multipart.file.StreamDataBodyPart; //导入依赖的package包/类
private Response upload(String endpoint, Set<String> targets, String path, String fileName, byte[] content) throws IOException {
    try (ByteArrayInputStream inputStream = new ByteArrayInputStream(content)) {
        StreamDataBodyPart streamDataBodyPart = new StreamDataBodyPart("file", inputStream, fileName);
        MultiPart multiPart = new FormDataMultiPart().field("path", path).field("targets", String.join(",", targets)).bodyPart(streamDataBodyPart);
        MediaType contentType = MediaType.MULTIPART_FORM_DATA_TYPE;
        contentType = Boundary.addBoundary(contentType);
        String signature = PkiUtil.generateSignature(signatureKey, content);
        return saltTarget.path(endpoint).request().header(SIGN_HEADER, signature).post(Entity.entity(multiPart, contentType));
    }
}
 
开发者ID:hortonworks,项目名称:cloudbreak,代码行数:11,代码来源:SaltConnector.java


示例11: directUpload

import org.glassfish.jersey.media.multipart.file.StreamDataBodyPart; //导入依赖的package包/类
@Override
public SuccessfulUploadResponse directUpload(DirectUploadRequest directUploadRequest) {
    return directUpload(directUploadRequest, new StreamDataBodyPart(UPLOAD_PART, directUploadRequest.getImage(), UUID.randomUUID().toString()));
}
 
开发者ID:kraken-io,项目名称:kraken-java,代码行数:5,代码来源:DefaultKrakenIoClient.java


示例12: fileTooLargeShouldResultInError

import org.glassfish.jersey.media.multipart.file.StreamDataBodyPart; //导入依赖的package包/类
@Test
public void fileTooLargeShouldResultInError() throws Exception {

    this.waitForQueueDrainAndRefreshIndex();

    // set max file size down to 6mb

    Map<String, String> props = new HashMap<String, String>();
    props.put( "usergrid.binary.max-size-mb", "6" );
    pathResource( "testproperties" ).post( props );

    try {

        // upload a file larger than 6mb

        final StreamDataBodyPart part = new StreamDataBodyPart(
            "file", getClass().getResourceAsStream( "/ship-larger-than-6mb.gif" ), "ship");
        final MultiPart multipart = new FormDataMultiPart().bodyPart( part );

        ApiResponse postResponse = pathResource( getOrgAppPath( "bars" ) ).post( multipart );
        UUID assetId = postResponse.getEntities().get(0).getUuid();

        String errorMessage = null;
        logger.info( "Waiting for upload to finish..." );
        Thread.sleep( 2000 );

        // attempt to get asset entity, it should contain error

        ApiResponse getResponse = pathResource( getOrgAppPath( "bars/" +assetId ) ).get( ApiResponse.class );
        Map<String, Object> fileMetadata = (Map<String, Object>)getResponse.getEntities().get(0).get("file-metadata");
        assertTrue( fileMetadata.get( "error" ).toString().startsWith( "Asset size " ) );

    } finally {

        // set max upload size back to default 25mb

        props.put( "usergrid.binary.max-size-mb", "25" );
        pathResource( "testproperties" ).post( props );
    }
}
 
开发者ID:apache,项目名称:usergrid,代码行数:41,代码来源:AssetResourceIT.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java TOAFactory类代码示例发布时间:2022-05-22
下一篇:
Java CompileTester类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap