本文整理匯總了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();
}