private File getFileFromMultipart(FormDataMultiPart multiPart, File dstFile) throws IOException { // Read segment file or segment metadata file and directly use that information to update zk Map<String, List<FormDataBodyPart>> segmentMetadataMap = multiPart.getFields(); if (!validateMultiPart(segmentMetadataMap, null)) { throw new ControllerApplicationException(LOGGER, "Invalid multi-part form for segment metadata", Response.Status.BAD_REQUEST); } FormDataBodyPart segmentMetadataBodyPart = segmentMetadataMap.values().iterator().next().get(0); try (InputStream inputStream = segmentMetadataBodyPart.getValueAs(InputStream.class); OutputStream outputStream = new FileOutputStream(dstFile)) { IOUtils.copyLarge(inputStream, outputStream); } finally { multiPart.cleanup(); } return dstFile; }
private Schema getSchemaFromMultiPart(FormDataMultiPart multiPart) { try { Map<String, List<FormDataBodyPart>> map = multiPart.getFields(); if (!PinotSegmentUploadRestletResource.validateMultiPart(map, null)) { throw new ControllerApplicationException(LOGGER, "Found not exactly one file from the multi-part fields", Response.Status.BAD_REQUEST); } FormDataBodyPart bodyPart = map.values().iterator().next().get(0); try (InputStream inputStream = bodyPart.getValueAs(InputStream.class)) { return Schema.fromInputSteam(inputStream); } catch (IOException e) { throw new ControllerApplicationException(LOGGER, "Caught exception while de-serializing the schema from request body: " + e.getMessage(), Response.Status.BAD_REQUEST); } } finally { multiPart.cleanup(); } }
return null; } finally { multiPart.cleanup();