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


Java MediaType.MULTIPART_FORM_DATA_TYPE属性代码示例

本文整理汇总了Java中javax.ws.rs.core.MediaType.MULTIPART_FORM_DATA_TYPE属性的典型用法代码示例。如果您正苦于以下问题:Java MediaType.MULTIPART_FORM_DATA_TYPE属性的具体用法?Java MediaType.MULTIPART_FORM_DATA_TYPE怎么用?Java MediaType.MULTIPART_FORM_DATA_TYPE使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在javax.ws.rs.core.MediaType的用法示例。


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

示例1: getFormPostResponse

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,代码行数:20,代码来源:AbstractServingTest.java

示例2: uploadHomeFile

private void uploadHomeFile() throws Exception {
  final FormDataMultiPart form = new FormDataMultiPart();
  final FormDataBodyPart fileBody = new FormDataBodyPart("file", com.dremio.common.util.FileUtils.getResourceAsString("/testfiles/yelp_biz.json"), MediaType.MULTIPART_FORM_DATA_TYPE);
  form.bodyPart(fileBody);
  form.bodyPart(new FormDataBodyPart("fileName", "biz"));

  com.dremio.file.File file1 = expectSuccess(getBuilder(getAPIv2().path("home/" + HOME_NAME + "/upload_start/").queryParam("extension", "json"))
      .buildPost(Entity.entity(form, form.getMediaType())), com.dremio.file.File.class);
  file1 = expectSuccess(getBuilder(getAPIv2().path("home/" + HOME_NAME + "/upload_finish/biz"))
      .buildPost(Entity.json(file1.getFileFormat().getFileFormat())), com.dremio.file.File.class);

  FileFormat fileFormat = file1.getFileFormat().getFileFormat();
  assertEquals(physicalFileAtHome.getLeaf().getName(), fileFormat.getName());
  assertEquals(physicalFileAtHome.toPathList(), fileFormat.getFullPath());
  assertEquals(FileType.JSON, fileFormat.getFileType());

  fileBody.cleanup();
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:18,代码来源:TestAccelerationResource.java

示例3: formatChangeForUploadedHomeFile

@Test // DX-5410
public void formatChangeForUploadedHomeFile() throws Exception {
  FormDataMultiPart form = new FormDataMultiPart();
  FormDataBodyPart fileBody = new FormDataBodyPart("file", FileUtils.getResourceAsFile("/datasets/csv/pipe.csv"), MediaType.MULTIPART_FORM_DATA_TYPE);
  form.bodyPart(fileBody);
  form.bodyPart(new FormDataBodyPart("fileName", "pipe"));

  doc("uploading a text file");
  File file1 = expectSuccess(getBuilder(getAPIv2().path("home/" + HOME_NAME + "/upload_start/").queryParam("extension", "csv"))
      .buildPost(Entity.entity(form, form.getMediaType())), File.class);
  file1 = expectSuccess(getBuilder(getAPIv2().path("home/" + HOME_NAME + "/upload_finish/pipe"))
      .buildPost(Entity.json(file1.getFileFormat().getFileFormat())), File.class);
  final FileFormat defaultFileFormat = file1.getFileFormat().getFileFormat();

  assertTrue(defaultFileFormat instanceof TextFileConfig);
  assertEquals(",", ((TextFileConfig)defaultFileFormat).getFieldDelimiter());

  doc("change the format settings of uploaded file");
  final TextFileConfig newFileFormat = (TextFileConfig)defaultFileFormat;
  newFileFormat.setFieldDelimiter("|");

  final FileFormat updatedFileFormat = expectSuccess(getBuilder(getAPIv2().path("home/" + HOME_NAME + "/file_format/pipe"))
      .buildPut(Entity.json(newFileFormat)), FileFormatUI.class).getFileFormat();
  assertTrue(updatedFileFormat instanceof TextFileConfig);
  assertEquals("|", ((TextFileConfig)updatedFileFormat).getFieldDelimiter());
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:26,代码来源:TestHomeFiles.java

示例4: testUploadExcelFile

private void testUploadExcelFile(final boolean isXLS) throws Exception {
  final String extension = isXLS ? "xls" : "xlsx";
  final FileType fileType = isXLS ? FileType.XLS : FileType.EXCEL;

  FormDataMultiPart form = new FormDataMultiPart();
  FormDataBodyPart fileBody = new FormDataBodyPart("file", FileUtils.getResourceAsFile("/testfiles/excel." + extension), MediaType.MULTIPART_FORM_DATA_TYPE);
  form.bodyPart(fileBody);
  form.bodyPart(new FormDataBodyPart("fileName", "excel"));

  doc("uploading excel file");
  File file1 = expectSuccess(getBuilder(getAPIv2().path("home/" + HOME_NAME + "/upload_start/").queryParam("extension", extension)).buildPost(
    Entity.entity(form, form.getMediaType())), File.class);
  file1 = expectSuccess(getBuilder(getAPIv2().path("home/" + HOME_NAME + "/upload_finish/excel")).buildPost(
      Entity.json(file1.getFileFormat().getFileFormat())), File.class);
  FileFormat file1Format = file1.getFileFormat().getFileFormat();

  assertEquals("excel", file1Format.getName());
  assertEquals(asList(HOME_NAME, "excel"), file1Format.getFullPath());
  assertEquals(fileType, file1Format.getFileType());

  fileBody.cleanup();

  doc("getting a excel file");
  File file2 = expectSuccess(getBuilder(getAPIv2().path("home/" + HOME_NAME + "/file/excel")).buildGet(), File.class);
  FileFormat file2Format = file2.getFileFormat().getFileFormat();

  assertEquals("excel", file2Format.getName());
  assertEquals(asList(HOME_NAME, "excel"), file2Format.getFullPath());
  assertEquals(fileType, file2Format.getFileType());

  doc("querying excel file");
  final JobsService jobsService = l(JobsService.class);
  JobUI job = new JobUI(jobsService.submitJob(JobRequest.newBuilder()
      .setSqlQuery(new SqlQuery("select * from \"" + HOME_NAME + "\".\"excel\"", SampleDataPopulator.DEFAULT_USER_NAME))
      .build(), NoOpJobStatusListener.INSTANCE));
  job.getData().loadIfNecessary();
  JobDataFragment truncData = job.getData().truncate(500);
  assertEquals(6, truncData.getReturnedRowCount());
  assertEquals(5, truncData.getColumns().size());

  doc("previewing excel file");
  if (file2Format instanceof ExcelFileConfig) {
    ((ExcelFileConfig) file2Format).setExtractHeader(true);
  } else {
    ((XlsFileConfig) file2Format).setExtractHeader(true);
  }
  JobDataFragment data = expectSuccess(getBuilder(getAPIv2().path("/home/" + HOME_NAME + "/file_preview/excel")).buildPost(Entity.json(file2Format)), JobDataFragment.class);
  assertEquals(5, data.getReturnedRowCount());
  assertEquals(5, data.getColumns().size());

  doc("creating dataset from excel file");
  InitialPreviewResponse previewResponse = expectSuccess(getBuilder(getAPIv2().path(
    "/home/" + HOME_NAME + "/new_untitled_from_file/excel")).buildPost(Entity.json("")), InitialPreviewResponse.class);
  assertEquals(5, previewResponse.getData().getColumns().size());
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:55,代码来源:TestHomeFiles.java


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