当前位置: 首页>>代码示例>>Java>>正文


Java FormDataBodyPart.getValueAs方法代码示例

本文整理汇总了Java中com.sun.jersey.multipart.FormDataBodyPart.getValueAs方法的典型用法代码示例。如果您正苦于以下问题:Java FormDataBodyPart.getValueAs方法的具体用法?Java FormDataBodyPart.getValueAs怎么用?Java FormDataBodyPart.getValueAs使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.sun.jersey.multipart.FormDataBodyPart的用法示例。


在下文中一共展示了FormDataBodyPart.getValueAs方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: addFile

import com.sun.jersey.multipart.FormDataBodyPart; //导入方法依赖的package包/类
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces({ MediaType.APPLICATION_JSON })
public FileOutVO addFile(@FormDataParam("json") FormDataBodyPart json,
		@FormDataParam("data") FormDataBodyPart content,
		@FormDataParam("data") FormDataContentDisposition contentDisposition,
		@FormDataParam("data") final InputStream input) throws AuthenticationException, AuthorisationException, ServiceException {
	// in.setTrialId(trialId);
	// in.setModule(FileModule.TRIAL_DOCUMENT);
	// https://stackoverflow.com/questions/27609569/file-upload-along-with-other-object-in-jersey-restful-web-service
	json.setMediaType(MediaType.APPLICATION_JSON_TYPE);
	FileInVO in = json.getValueAs(FileInVO.class);
	FileStreamInVO stream = new FileStreamInVO();
	stream.setStream(input);
	stream.setMimeType(content.getMediaType().toString()); // .getType());
	stream.setSize(contentDisposition.getSize());
	stream.setFileName(contentDisposition.getFileName());
	return WebUtil.getServiceLocator().getFileService().addFile(auth, in, stream);
}
 
开发者ID:phoenixctms,项目名称:ctsms,代码行数:20,代码来源:FileResource.java

示例2: updateFile

import com.sun.jersey.multipart.FormDataBodyPart; //导入方法依赖的package包/类
@PUT
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces({ MediaType.APPLICATION_JSON })
public FileOutVO updateFile(@FormDataParam("json") FormDataBodyPart json,
		@FormDataParam("data") FormDataBodyPart content,
		@FormDataParam("data") FormDataContentDisposition contentDisposition,
		@FormDataParam("data") final InputStream input) throws AuthenticationException, AuthorisationException, ServiceException {
	// in.setId(fileId);
	json.setMediaType(MediaType.APPLICATION_JSON_TYPE);
	FileInVO in = json.getValueAs(FileInVO.class);
	FileStreamInVO stream = new FileStreamInVO();
	stream.setStream(input);
	stream.setMimeType(content.getMediaType().toString()); // .getType());
	stream.setSize(contentDisposition.getSize());
	stream.setFileName(contentDisposition.getFileName());
	return WebUtil.getServiceLocator().getFileService().updateFile(auth, in, stream);
}
 
开发者ID:phoenixctms,项目名称:ctsms,代码行数:18,代码来源:FileResource.java

示例3: extractInputFileSource

import com.sun.jersey.multipart.FormDataBodyPart; //导入方法依赖的package包/类
/**
 * Extracts certificate from the multipart form.
 * 
 * @param part
 *            parsed multipart form body part.
 * @return extracted certificate or <code>null</code> if empty field was passed.
 * @throws UnableToParseFormException
 *             should passed value be invalid.
 */
private byte[] extractInputFileSource(FormDataBodyPart part)
        throws UnableToParseFormException {
    ContentDisposition disp = part.getContentDisposition();
    if (disp.getFileName() != null) {
        InputStream is = part.getValueAs(InputStream.class);
        try {
            byte[] certificate = IOUtils.toByteArray(is);
            return certificate.length > 0 ? certificate : null;
        } catch (IOException e) {
            // fall through, error will be thrown nonetheless from the last line.
            logger.debug("IO error while parsing certificate data from multipart form: " + e.toString());
        }
    }
    throw new UnableToParseFormException("Could not parse the certificate information");
}
 
开发者ID:psnc-dl,项目名称:darceo,代码行数:25,代码来源:RegistryFormParser.java

示例4: getFileMapFromFormDataBodyPartList

import com.sun.jersey.multipart.FormDataBodyPart; //导入方法依赖的package包/类
protected Map<String, File> getFileMapFromFormDataBodyPartList(List<FormDataBodyPart> parts) {
	Map<String, File> files = new LinkedHashMap<String, File>();
	
	if (parts != null) {
		for (FormDataBodyPart part : parts) {
			String fileName = part.getContentDisposition().getFileName();
			File file = part.getValueAs(File.class);
			
			if (StringUtils.hasText(fileName) && file != null && file.canRead()) {
				files.put(fileName, file);
			}
		}
	}
	
	return files;
}
 
开发者ID:openwide-java,项目名称:owsi-core-parent,代码行数:17,代码来源:AbstractRestServiceImpl.java

示例5: createAgreementMultipart

import com.sun.jersey.multipart.FormDataBodyPart; //导入方法依赖的package包/类
@Deprecated
@POST
@Path("agreements")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response createAgreementMultipart(@Context UriInfo uriInfo, FormDataMultiPart form,
        @QueryParam("agreementId") String agreementId) 
        throws ParserException, InternalException {
    
    FormDataBodyPart slaPart = form.getField("sla");
    String slaPayload = slaPart.getValueAs(String.class);

    String id = createAgreementImpl(agreementId, slaPayload);
    String location = buildResourceLocation(uriInfo.getAbsolutePath().toString() ,id);
    logger.debug("EndOf createAgreement");
    return buildResponsePOST(
            HttpStatus.CREATED,
            createMessage(HttpStatus.CREATED, id, 
                    "The agreement has been stored successfully in the SLA Repository Database. "
                    + "It has location " + location), location);
}
 
开发者ID:SeaCloudsEU,项目名称:SeaCloudsPlatform,代码行数:21,代码来源:SeacloudsRest.java

示例6: writeSourceFileToDisk

import com.sun.jersey.multipart.FormDataBodyPart; //导入方法依赖的package包/类
/**
 * Save uploaded file to specified location.
 * @param form
 * @return 
 * @throws IOException
 */
private String writeSourceFileToDisk(FormDataMultiPart form) throws IOException {
	FormDataBodyPart formFile = form.getField("file");
       String formName =  formFile.getContentDisposition().getFileName();
       
       String pathToTest = suggestName(formName);
	File file = new File(pathToTest);
	while (file.isFile()) {
        String lastExistingFile = pathToTest;
		pathToTest = getNewNameIfHashDiffers(formFile, pathToTest);
		if (pathToTest == null) { // file exists, same content
			return lastExistingFile;
		}
		file = new File(pathToTest);
	}
	
       InputStream readFormStream = formFile.getValueAs(InputStream.class);
	writeFile(readFormStream, file);
	
	return pathToTest;
}
 
开发者ID:AKSW,项目名称:LinkingLodPortal,代码行数:27,代码来源:UploadFileService.java

示例7: getNewNameIfHashDiffers

import com.sun.jersey.multipart.FormDataBodyPart; //导入方法依赖的package包/类
/**
 * Checks if the existing file has the same hash as the file from the form and renames if needed. If hash equals, existing name is used.
 * @param formFile
 * @param pathToTest
 * @return 
 * @throws IOException
 * @throws FileNotFoundException
 */
private String getNewNameIfHashDiffers(FormDataBodyPart formFile,
		String pathToTest) throws IOException, FileNotFoundException {
	InputStream hashFormStream = formFile.getValueAs(InputStream.class);

	String formHash = DigestUtils.md5Hex(hashFormStream);
	String diskHash = MD5Utils.computeChecksum(pathToTest);
	
	if (!formHash.equals(diskHash)) { // hash is different -> new name
		String nextTry = "";
		if (pathToTest.endsWith(".nt")) {
			nextTry = pathToTest.substring(0, pathToTest.length() - 3);
			nextTry = setNextName(nextTry);
			nextTry += ".nt";
		}
		else {
			nextTry = setNextName(nextTry);
		}
		
		return nextTry;
	}

	return null;
}
 
开发者ID:AKSW,项目名称:LinkingLodPortal,代码行数:32,代码来源:UploadFileService.java

示例8: getFileFromFormDataBodyPart

import com.sun.jersey.multipart.FormDataBodyPart; //导入方法依赖的package包/类
protected File getFileFromFormDataBodyPart(FormDataBodyPart part) {
	File file = part.getValueAs(File.class);
	if (file != null && file.canRead()) {
		return file;
	} else {
		return null;
	}
}
 
开发者ID:openwide-java,项目名称:owsi-core-parent,代码行数:9,代码来源:AbstractRestServiceImpl.java


注:本文中的com.sun.jersey.multipart.FormDataBodyPart.getValueAs方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。