本文整理汇总了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);
}
示例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);
}
示例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");
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
}