本文整理汇总了Java中com.sun.jersey.multipart.FormDataMultiPart.getFields方法的典型用法代码示例。如果您正苦于以下问题:Java FormDataMultiPart.getFields方法的具体用法?Java FormDataMultiPart.getFields怎么用?Java FormDataMultiPart.getFields使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.jersey.multipart.FormDataMultiPart
的用法示例。
在下文中一共展示了FormDataMultiPart.getFields方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setFormParams
import com.sun.jersey.multipart.FormDataMultiPart; //导入方法依赖的package包/类
private static void setFormParams(FormDataMultiPart formData, Run run, String... excluded) throws IOException {
Collection<String> ex = new HashSet<String>(Arrays.asList(excluded));
Map<String,List<FormDataBodyPart>> formFields = formData.getFields();
for (Map.Entry<String,List<FormDataBodyPart>> e : formFields.entrySet()) {
String name = e.getKey();
if (ex.contains(name)) {
continue;
}
List<FormDataBodyPart> fields = e.getValue();
if (fields.isEmpty()) {
continue;
}
FormDataBodyPart field = fields.get(fields.size() - 1);
if (name.startsWith(ParamValue.METHOD_UPLOAD + "-")) {
name = name.substring(7);
ContentDisposition cd = field.getContentDisposition();
run.addUploadParamValue(name, cd.getFileName(), field.getValueAs(InputStream.class));
}
else {
String value = field.getValue();
setParam(run, name, value);
}
}
}
示例2: saveSpecificFile
import com.sun.jersey.multipart.FormDataMultiPart; //导入方法依赖的package包/类
/**
* save file to folder on server
* @param centralConfigService - central config service
* @param formDataMultiPart - multi part - file content
* @param uploadDir - upload dir
* @param fileName - file name
*/
public static void saveSpecificFile(CentralConfigService centralConfigService,
FormDataMultiPart formDataMultiPart, String uploadDir, String fileName) {
int fileUploadMaxSizeMb = centralConfigService.getMutableDescriptor().getFileUploadMaxSizeMb();
// get uploaded file map
Map<String, List<FormDataBodyPart>> fields = formDataMultiPart.getFields();
fields.forEach((name, dataBody) -> {
List<FormDataBodyPart> formDataBodyParts = fields.get(name);
// get file name and data
byte[] fileAsBytes = formDataBodyParts.get(0).getValueAs(byte[].class);
if (FileUtils.bytesToMeg(fileAsBytes.length) > fileUploadMaxSizeMb && fileUploadMaxSizeMb > 0) {
throw new BadRequestException("Uploaded file size is bigger than :" + fileUploadMaxSizeMb);
}
String fileLocation = uploadDir + File.separator + fileName;
FileUtils.writeFile(fileLocation, fileAsBytes);
});
}
示例3: saveFileDataToTemp
import com.sun.jersey.multipart.FormDataMultiPart; //导入方法依赖的package包/类
/**
* fetch file data from request and save it to temp folder
*
* @param uploadDir - temp folder
* @param fileNames
*/
public static void saveFileDataToTemp(CentralConfigService centralConfigService,
FormDataMultiPart formDataMultiPart, String uploadDir, List<String> fileNames, boolean isUnique) {
int fileUploadMaxSizeMb = centralConfigService.getMutableDescriptor().getFileUploadMaxSizeMb();
// get uploaded file map
Map<String, List<FormDataBodyPart>> fields = formDataMultiPart.getFields();
long sizeInBytes = getContentLengthFromMultiPart(formDataMultiPart);
fields.forEach((name, dataBody) -> {
List<FormDataBodyPart> formDataBodyParts = fields.get(name);
formDataBodyParts.forEach(formDataBodyPart -> {
// get file name and data
InputStream inputStream = formDataBodyPart.getEntityAs(InputStream.class);
long sizeInMb = FileUtils.bytesToMB(sizeInBytes);
if (sizeInMb > fileUploadMaxSizeMb && fileUploadMaxSizeMb > 0) {
throw new BadRequestException("Uploaded file size is bigger than " + fileUploadMaxSizeMb + "MB");
}
String fileName = formDataBodyPart.getContentDisposition().getFileName();
try {
fileName = URLDecoder.decode(fileName, "UTF-8");
if (isUnique) {
fileName = UUID.randomUUID().toString() + "_" + fileName;
}
String fileLocation = uploadDir + File.separator + fileName;
FileUtils.copyInputStreamToFile(inputStream, new File(fileLocation));
fileNames.add(fileName);
} catch (UnsupportedEncodingException e) {
log.error(e.getMessage());
}
});
});
}
示例4: RegistryFormParser
import com.sun.jersey.multipart.FormDataMultiPart; //导入方法依赖的package包/类
/**
* Constructs new parser for adding registry.
*
* @param multipart
* multipart form fields.
*/
public RegistryFormParser(FormDataMultiPart multipart) {
this.builder = new RemoteRegistryBuilder();
this.fields = multipart.getFields();
}