本文整理汇总了Java中com.sun.jersey.core.header.ContentDisposition类的典型用法代码示例。如果您正苦于以下问题:Java ContentDisposition类的具体用法?Java ContentDisposition怎么用?Java ContentDisposition使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ContentDisposition类属于com.sun.jersey.core.header包,在下文中一共展示了ContentDisposition类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: addFiles
import com.sun.jersey.core.header.ContentDisposition; //导入依赖的package包/类
@POST @Path("add/files")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public void addFiles(FormDataMultiPart body) {
List<IBridge.UploadedFileInfo> files = new LinkedList<>();
for(BodyPart part : body.getBodyParts()) {
InputStream is = part.getEntityAs(InputStream.class);
ContentDisposition meta = part.getContentDisposition();
try {
File tmpFile = File.createTempFile("dlup", ".dat");
tmpFile.deleteOnExit();
FileUtils.copyInputStreamToFile(is, tmpFile);
LOGGER.info("File {} uploaded to {}", meta.getFileName(), tmpFile);
files.add(new IBridge.UploadedFileInfo(tmpFile, meta.getFileName()));
} catch (IOException e) {
LOGGER.error("Cannot create temporary file for upload", e);
}
}
downloadsService.addFiles(files, globalConfig.getDownloadPath());
}
开发者ID:jhkst,项目名称:dlface,代码行数:22,代码来源:Downloads.java
示例2: setFormParams
import com.sun.jersey.core.header.ContentDisposition; //导入依赖的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
示例3: extractInputFileSource
import com.sun.jersey.core.header.ContentDisposition; //导入依赖的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: getFileNameFromResponse
import com.sun.jersey.core.header.ContentDisposition; //导入依赖的package包/类
private String getFileNameFromResponse(final ClientResponse response) {
String value = response.getHeaders().getFirst("Content-Disposition");
String fileName = "executeTask";
try {
ContentDisposition contentDisposition = new ContentDisposition(value);
fileName = contentDisposition.getFileName();
} catch (ParseException e) {
e.printStackTrace();
}
return fileName;
}
开发者ID:poquito,项目名称:assetmanager,代码行数:12,代码来源:JerseyTaskManager.java
示例5: FileStream
import com.sun.jersey.core.header.ContentDisposition; //导入依赖的package包/类
public FileStream(String requestUri, ClientResponse response) {
this.inputStream = response.getEntityInputStream();
if(response.getType() != null){
this.contentType = response.getType().toString();
}
MultivaluedMap<String, String> headers = response.getHeaders();
try {
// http://www.ietf.org/rfc/rfc2183.txt
ContentDisposition cd = new ContentDisposition(headers.getFirst("Content-Disposition"));
fileName = cd.getFileName() == null ? getFileNameFromUrl(requestUri) : cd.getFileName();
size = cd.getSize() == 0 ? response.getLength() : cd.getSize();
} catch (ParseException e) {
}
}
开发者ID:liosha2007,项目名称:temporary-groupdocs-java-sdk,代码行数:16,代码来源:FileStream.java
示例6: download
import com.sun.jersey.core.header.ContentDisposition; //导入依赖的package包/类
@GET
@Path("/{service}/{id}/{filename}")
public Response download(
@Auth ClientPermission clientPermission,
@SuppressWarnings("TypeMayBeWeakened") @Context HttpServletRequest req,
@Metadata final BackupMetadata backup,
@PathParam("filename") final String filename) throws MetadataNotFoundException {
if (!(backup.isSuccessful() || backup.isFailed())) {
throw new IllegalStateException("Attempted to download a non-complete backup.");
}
final List<Chunk> chunks = backup.getChunks(filename);
if (chunks.isEmpty()) {
throw new WebApplicationException(Response.Status.NOT_FOUND);
}
LOG.info("SecEvent: Downloading backup {}, requested by {}", backup, req.getRemoteAddr());
long size = 0;
for (Chunk chunk : chunks) {
size += chunk.getOriginalSize();
}
final ContentDisposition disposition = ContentDisposition
.type("attachment")
.fileName(filename)
.build();
final Response.ResponseBuilder builder = Response
.status(Response.Status.OK)
.type(MediaType.APPLICATION_OCTET_STREAM)
.header(HttpHeaders.CONTENT_DISPOSITION, disposition)
.entity(new StreamingOutput() {
@Override
public void write(OutputStream output) throws IOException {
try {
backupProcessor.download(backup, filename, output);
}
finally {
output.close();
}
}
});
// Only add a content length if we have one
if (size > 0) {
builder.header(HttpHeaders.CONTENT_LENGTH, size);
}
return builder.build();
}
开发者ID:yammer,项目名称:backups,代码行数:53,代码来源:BackupResource.java
注:本文中的com.sun.jersey.core.header.ContentDisposition类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论