本文整理汇总了Java中javax.activation.MimetypesFileTypeMap类的典型用法代码示例。如果您正苦于以下问题:Java MimetypesFileTypeMap类的具体用法?Java MimetypesFileTypeMap怎么用?Java MimetypesFileTypeMap使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MimetypesFileTypeMap类属于javax.activation包,在下文中一共展示了MimetypesFileTypeMap类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createContent
import javax.activation.MimetypesFileTypeMap; //导入依赖的package包/类
private String createContent(
Reference ref,
String name,
String title,
String description,
byte[] data) throws RemoteException, ContentFault {
ParentReference parent = getReferenceToParent(ref);
parent.setChildName(Constants.createQNameString(
Constants.NAMESPACE_CONTENT_MODEL,
normalizeNodeName(name)));
NamedValue[] properties = new NamedValue[]{
Utils.createNamedValue(Constants.PROP_NAME, name),
Utils.createNamedValue(Constants.PROP_TITLE, title),
Utils.createNamedValue(Constants.PROP_DESCRIPTION, description)};
CMLCreate create = new CMLCreate("1", parent, null, null, null, Constants.TYPE_CONTENT, properties);
CML cml = new CML();
cml.setCreate(new CMLCreate[]{create});
UpdateResult[] result = getAlfrescoRepositoryService().update(cml);
Reference newContentNode = result[0].getDestination();
Content content = getAlfrescoContentService().write(
newContentNode,
Constants.PROP_CONTENT,
data,
new ContentFormat(new MimetypesFileTypeMap().getContentType(name), null));
return content.getNode().getUuid();
}
示例2: createContent
import javax.activation.MimetypesFileTypeMap; //导入依赖的package包/类
public String createContent(
Reference ref,
String name,
String title,
String description,
byte[] data) throws RemoteException, ContentFault {
ParentReference parent = getReferenceToParent(ref);
parent.setChildName(Constants.createQNameString(
Constants.NAMESPACE_CONTENT_MODEL,
normalizeNodeName(name)));
NamedValue[] properties = new NamedValue[]{
Utils.createNamedValue(Constants.PROP_NAME, name),
Utils.createNamedValue(Constants.PROP_TITLE, title),
Utils.createNamedValue(Constants.PROP_DESCRIPTION, description)};
CMLCreate create = new CMLCreate("1", parent, null, null, null, Constants.TYPE_CONTENT, properties);
CML cml = new CML();
cml.setCreate(new CMLCreate[]{create});
UpdateResult[] result = getAlfrescoRepositoryService().update(cml);
Reference newContentNode = result[0].getDestination();
Content content = getAlfrescoContentService().write(
newContentNode,
Constants.PROP_CONTENT,
data,
new ContentFormat(new MimetypesFileTypeMap().getContentType(name), null));
return content.getNode().getUuid();
}
示例3: render
import javax.activation.MimetypesFileTypeMap; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
public void render(
Map model,
HttpServletRequest request,
HttpServletResponse response) throws Exception {
response.setHeader(HEADER_PRAGMA, "");
response.setHeader(HEADER_EXPIRES, "");
response.setHeader(HEADER_CACHE_CONTROL, "");
byte[] data = (byte[])model.get(MODEL_ATTRIBUTE_DATA);
String fileName = (String)model.get(MODEL_ATTRIBUTE_FILENAME);
String contentType = (String)model.get(MODEL_ATTRIBUTE_CONTENTTYPE);
if (data == null)
data = new byte[0];
if (fileName == null)
fileName = "unknown";
response.setHeader("Content-Disposition","attachment; filename=\"" + fileName + "\"");
if (contentType == null)
response.setContentType(new MimetypesFileTypeMap().getContentType(fileName));
else
response.setContentType(contentType);
response.getOutputStream().write(data);
}
示例4: loadMimeTypes
import javax.activation.MimetypesFileTypeMap; //导入依赖的package包/类
/**
* Load MIME types
*/
public static void loadMimeTypes() {
try {
List<MimeType> mimeTypeList = MimeTypeDAO.findAll("mt.id");
MimeTypeConfig.mimeTypes = new MimetypesFileTypeMap();
for (MimeType mt : mimeTypeList) {
String entry = mt.getName();
for (String ext : mt.getExtensions()) {
entry += " " + ext;
}
log.debug("loadMimeTypes => Add Entry: {}", entry);
MimeTypeConfig.mimeTypes.addMimeTypes(entry);
}
} catch (DatabaseException e) {
log.error(e.getMessage(), e);
}
}
示例5: getTempFileHttpEntity
import javax.activation.MimetypesFileTypeMap; //导入依赖的package包/类
private HttpEntity<byte[]> getTempFileHttpEntity(String filePath) throws IOException {
String fullPath = uploadTempDir + filePath.replace("../", ""); //보안을 위해서 ../ 를 공백 처리한다.
File file = new File(fullPath);
String fileType = new MimetypesFileTypeMap().getContentType(file);
String[] fileTypeArr = fileType.split("/");
InputStream is = new FileInputStream(fullPath);
byte[] fileBytes = IOUtils.toByteArray(is);
HttpHeaders headers = new HttpHeaders();
headers.setContentType(new MediaType(fileTypeArr[0], fileTypeArr[1]));
headers.setContentLength(file.length());
return new HttpEntity<byte[]>(fileBytes, headers);
}
示例6: addResourcesInMessage
import javax.activation.MimetypesFileTypeMap; //导入依赖的package包/类
private String addResourcesInMessage(final MimeMessageHelper mailMessage, final String htmlText) throws Exception {
final Document document = Jsoup.parse(htmlText);
final List<String> resources = new ArrayList<>();
final Elements imageElements = document.getElementsByTag("img");
resources.addAll(imageElements.stream()
.filter(imageElement -> imageElement.hasAttr("src"))
.map(imageElement -> {
final String src = imageElement.attr("src");
imageElement.attr("src", "cid:" + src);
return src;
})
.collect(Collectors.toList()));
final String html = document.html();
mailMessage.setText(html, true);
for (final String res : resources) {
final FileSystemResource templateResource = new FileSystemResource(new File(templatesPath, res));
mailMessage.addInline(res, templateResource, MimetypesFileTypeMap.getDefaultFileTypeMap().getContentType(res));
}
return html;
}
示例7: registerMediaTypes
import javax.activation.MimetypesFileTypeMap; //导入依赖的package包/类
private void registerMediaTypes() {
// Common MIME types used for uploading attachments.
mediaTypes = new MimetypesFileTypeMap();
mediaTypes.addMimeTypes("application/msword doc");
mediaTypes.addMimeTypes("application/vnd.ms-excel xls");
mediaTypes.addMimeTypes("application/pdf pdf");
mediaTypes.addMimeTypes("text/richtext rtx");
mediaTypes.addMimeTypes("text/csv csv");
mediaTypes.addMimeTypes("text/tab-separated-values tsv tab");
mediaTypes.addMimeTypes("application/x-vnd.oasis.opendocument.spreadsheet ods");
mediaTypes.addMimeTypes("application/vnd.oasis.opendocument.text odt");
mediaTypes.addMimeTypes("application/vnd.ms-powerpoint ppt pps pot");
mediaTypes.addMimeTypes("application/vnd.openxmlformats-officedocument."
+ "wordprocessingml.document docx");
mediaTypes.addMimeTypes("application/vnd.openxmlformats-officedocument."
+ "spreadsheetml.sheet xlsx");
mediaTypes.addMimeTypes("audio/mpeg mp3 mpeg3");
mediaTypes.addMimeTypes("image/png png");
mediaTypes.addMimeTypes("application/zip zip");
mediaTypes.addMimeTypes("application/x-tar tar");
mediaTypes.addMimeTypes("video/quicktime qt mov moov");
mediaTypes.addMimeTypes("video/mpeg mpeg mpg mpe mpv vbs mpegv");
mediaTypes.addMimeTypes("video/msvideo avi");
}
示例8: download
import javax.activation.MimetypesFileTypeMap; //导入依赖的package包/类
@RequestMapping(value = "download")
public String download(HttpServletRequest request, HttpServletResponse response) throws IOException {
ServletContext servletContext = request.getSession().getServletContext();
String filename = servletContext.getRealPath("Schedule_Sample.xlsx");
File file = new File(filename);
response.setContentType(new MimetypesFileTypeMap().getContentType(file));
response.setContentLength((int) file.length());
response.setHeader("content-disposition", "attachment; filename=" + URLEncoder.encode(filename, "UTF-8"));
InputStream is = new FileInputStream(file);
FileCopyUtils.copy(is, response.getOutputStream());
return null;
}
示例9: getResult
import javax.activation.MimetypesFileTypeMap; //导入依赖的package包/类
/**
* @return A MimeMultipart object containing the zipped result files
*/
public MimeMultipart getResult() {
File file = new File(JPLAG_RESULTS_DIRECTORY + File.separator
+ submissionID + getUsername() + ".zip");
MimeMultipart mmp = new MimeMultipart();
FileDataSource fds1 = new FileDataSource(file);
MimetypesFileTypeMap mftp = new MimetypesFileTypeMap();
mftp.addMimeTypes("multipart/zip zip ZIP");
fds1.setFileTypeMap(mftp);
MimeBodyPart mbp = new MimeBodyPart();
try {
mbp.setDataHandler(new DataHandler(fds1));
mbp.setFileName(file.getName());
mmp.addBodyPart(mbp);
} catch (MessagingException me) {
me.printStackTrace();
}
return mmp;
}
示例10: setContentTypeHeader
import javax.activation.MimetypesFileTypeMap; //导入依赖的package包/类
/**
* Sets the content type header for the HTTP Response
*
* @param response
* HTTP response
* @param file
* file to extract content type
*/
private static void setContentTypeHeader(HttpResponse response, String path) {
MimetypesFileTypeMap mimeTypesMap = new MimetypesFileTypeMap();
////////////////////////////////////////
//NOTE: this does not work and behaves different between Java releases!!!!!
///////////////////////////////////////
String contentType = mimeTypesMap.getContentType(path);
//patching mistake from the above broken code.
if (path.endsWith("css")) {
contentType = "text/css";
} else if (path.endsWith("html")) {
contentType = "text/html";
} else if (path.endsWith("jpg")) {
contentType = "image/jpeg";
}
response.headers().set(HttpHeaderNames.CONTENT_TYPE, contentType);
}
示例11: isImage
import javax.activation.MimetypesFileTypeMap; //导入依赖的package包/类
/**
* Obtains a files MIME type and returns true if it is of type image
* @param fileName
* @param output
* @return true if an image; false otherwise
*/
public static boolean isImage(String fileName, boolean output) {
MimetypesFileTypeMap mimeTypesMap = new MimetypesFileTypeMap();
String mimeType = mimeTypesMap.getContentType(fileName);
if(output){
System.out.println("Validating input file...");
System.out.println("File type: "+mimeType);
}
if(mimeType.startsWith("image")){
return true;
}else{
if(output){
System.out.println("Invalid file type input. Please enter an image");
}
return false;
}
}
示例12: setContentTypeHeader
import javax.activation.MimetypesFileTypeMap; //导入依赖的package包/类
/**
* Sets the content type header for the HTTP Response
*
* @param response
* HTTP response
* @param file
* file to extract content type
*/
private static void setContentTypeHeader(HttpResponse response, String path) {
String contentType = null;
if(path.endsWith(".css")) {
contentType = "text/css";
}
else if(path.endsWith(".js")) {
contentType = "application/javascript";
}
else if(path.endsWith(".html")) {
contentType = "text/html";
}
else {
MimetypesFileTypeMap mimeTypesMap = new MimetypesFileTypeMap();
contentType = mimeTypesMap.getContentType(path);
}
response.headers().set(CONTENT_TYPE, contentType);
}
示例13: getMIMEType
import javax.activation.MimetypesFileTypeMap; //导入依赖的package包/类
/**
* Return the mimetype of the file depending of his extension and the mime.types file
*
* @param strFilename
* the file name
* @return the file mime type
*/
public static String getMIMEType( String strFilename )
{
try
{
MimetypesFileTypeMap mimeTypeMap = new MimetypesFileTypeMap( AppPathService.getWebAppPath( ) + File.separator + FILE_MIME_TYPE );
return mimeTypeMap.getContentType( strFilename.toLowerCase( ) );
}
catch( IOException e )
{
AppLogService.error( e );
return DEFAULT_MIME_TYPE;
}
}
示例14: createItem
import javax.activation.MimetypesFileTypeMap; //导入依赖的package包/类
private Item createItem(File file, Document doc){
Matcher matcher = fileNamePattern.matcher(file.getName());
if (matcher.matches()) {
String resourceName = matcher.group(1);
String version = matcher.group(2);
String suffix = FilenameUtils.getExtension(file.getName());
Item item = new Item();
item.file = file;
item.doc = doc;
item.resourceName = resourceName;
item.version = version;
item.fileSuffix = suffix;
item.size = FileUtils.sizeOf(file);
item.obsolete = false;
item.mimetype = new MimetypesFileTypeMap().getContentType(file);
return item;
} else {
return null;
}
}
示例15: downloadFile
import javax.activation.MimetypesFileTypeMap; //导入依赖的package包/类
protected void downloadFile(HttpServletResponse response, String filePath) throws ServletException, IOException {
File fileToDownload = new File(filePath);
FileInputStream fileInputStream = new FileInputStream(fileToDownload);
ServletOutputStream out = response.getOutputStream();
String mimeType = new MimetypesFileTypeMap().getContentType(filePath);
response.setContentType(mimeType);
response.setContentLength(fileInputStream.available());
response.setHeader( "Content-Disposition", "attachment; filename=\""+ fileToDownload.getName() + "\"" );
int c;
while((c=fileInputStream.read()) != -1){
out.write(c);
}
out.flush();
out.close();
fileInputStream.close();
}