当前位置: 首页>>代码示例>>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;未经允许,请勿转载。