Java Code Examples for javax.activation.DataHandler#getName()

The following examples show how to use javax.activation.DataHandler#getName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BookCatalog.java    From cxf with Apache License 2.0 6 votes vote down vote up
@POST
@Consumes("multipart/form-data")
public Response addBook(final MultipartBody body) throws Exception {
    for (final Attachment attachment: body.getAllAttachments()) {
        final DataHandler handler = attachment.getDataHandler();

        if (handler != null) {
            final String source = handler.getName();
            final LuceneDocumentMetadata metadata = new LuceneDocumentMetadata()
                .withSource(source)
                .withField("modified", Date.class);

            final Document document = extractor.extract(handler.getInputStream(), metadata);
            if (document != null) {
                try (IndexWriter writer = getIndexWriter()) {
                    writer.addDocument(document);
                    writer.commit();
                }
            }
        }
    }

    return Response.ok().build();
}
 
Example 2
Source File: Jaxb2Marshaller.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private String getHost(String elementNamespace, DataHandler dataHandler) {
	try {
		URI uri = new URI(elementNamespace);
		return uri.getHost();
	}
	catch (URISyntaxException ex) {
		// ignore
	}
	return dataHandler.getName();
}
 
Example 3
Source File: MailUtil.java    From mail-micro-service with Apache License 2.0 5 votes vote down vote up
/**
 * 追加附件
 * @author hf-hf
 * @date 2018/12/27 16:53
 * @param attachments
 * @param wrapPart
 * @throws MessagingException
 * @throws UnsupportedEncodingException
 */
private void addAttachments(File[] attachments, MimeMultipart wrapPart)
        throws MessagingException, UnsupportedEncodingException {
    if (null != attachments && attachments.length > 0) {
        for (int i = 0; i < attachments.length; i++) {
            MimeBodyPart attachmentBodyPart = new MimeBodyPart();
            DataHandler dataHandler = new DataHandler(new FileDataSource(attachments[i]));
            String fileName = dataHandler.getName();
            attachmentBodyPart.setDataHandler(dataHandler);
            // 显示指定文件名(防止文件名乱码)
            attachmentBodyPart.setFileName(MimeUtility.encodeText(fileName));
            wrapPart.addBodyPart(attachmentBodyPart);
        }
    }
}
 
Example 4
Source File: Jaxb2Marshaller.java    From java-technology-stack with MIT License 5 votes vote down vote up
private String getHost(String elementNamespace, DataHandler dataHandler) {
	try {
		URI uri = new URI(elementNamespace);
		return uri.getHost();
	}
	catch (URISyntaxException ex) {
		// ignore
	}
	return dataHandler.getName();
}
 
Example 5
Source File: MailUtil.java    From mail-micro-service with Apache License 2.0 5 votes vote down vote up
/**
 * 追加附件
 * @author hf-hf
 * @date 2018/12/27 16:53
 * @param attachments
 * @param wrapPart
 * @throws MessagingException
 * @throws UnsupportedEncodingException
 */
private void addAttachments(File[] attachments, MimeMultipart wrapPart)
        throws MessagingException, UnsupportedEncodingException {
    if (null != attachments && attachments.length > 0) {
        for (int i = 0; i < attachments.length; i++) {
            MimeBodyPart attachmentBodyPart = new MimeBodyPart();
            DataHandler dataHandler = new DataHandler(new FileDataSource(attachments[i]));
            String fileName = dataHandler.getName();
            attachmentBodyPart.setDataHandler(dataHandler);
            // 显示指定文件名(防止文件名乱码)
            attachmentBodyPart.setFileName(MimeUtility.encodeText(fileName));
            wrapPart.addBodyPart(attachmentBodyPart);
        }
    }
}
 
Example 6
Source File: Jaxb2Marshaller.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
private String getHost(String elementNamespace, DataHandler dataHandler) {
	try {
		URI uri = new URI(elementNamespace);
		return uri.getHost();
	}
	catch (URISyntaxException e) {
		// ignore
	}
	return dataHandler.getName();
}
 
Example 7
Source File: Jaxb2Marshaller.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
public String addSwaRefAttachment(DataHandler dataHandler) {
	String contentId = UUID.randomUUID() + "@" + dataHandler.getName();
	this.mimeContainer.addAttachment(contentId, dataHandler);
	return contentId;
}
 
Example 8
Source File: Jaxb2Marshaller.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
public String addSwaRefAttachment(DataHandler dataHandler) {
	String contentId = UUID.randomUUID() + "@" + dataHandler.getName();
	this.mimeContainer.addAttachment(contentId, dataHandler);
	return contentId;
}
 
Example 9
Source File: Jaxb2Marshaller.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
public String addSwaRefAttachment(DataHandler dataHandler) {
	String contentId = UUID.randomUUID() + "@" + dataHandler.getName();
	this.mimeContainer.addAttachment(contentId, dataHandler);
	return contentId;
}