當前位置: 首頁>>代碼示例>>Java>>正文


Java FormDataMultiPart.getFields方法代碼示例

本文整理匯總了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);
		}
	}
}
 
開發者ID:Bibliome,項目名稱:alvisnlp,代碼行數:26,代碼來源:RunLauncher.java

示例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);
    });
}
 
開發者ID:alancnet,項目名稱:artifactory,代碼行數:24,代碼來源:MultiPartUtils.java

示例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());
            }
        });
    });
}
 
開發者ID:alancnet,項目名稱:artifactory,代碼行數:37,代碼來源:MultiPartUtils.java

示例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();
}
 
開發者ID:psnc-dl,項目名稱:darceo,代碼行數:11,代碼來源:RegistryFormParser.java


注:本文中的com.sun.jersey.multipart.FormDataMultiPart.getFields方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。