MimeTypesUtil.java |
1 /** 2 * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved. 3 * 4 * The contents of this file are subject to the terms of the Liferay Enterprise 5 * Subscription License ("License"). You may not use this file except in 6 * compliance with the License. You can obtain a copy of the License by 7 * contacting Liferay, Inc. See the License for the specific language governing 8 * permissions and limitations under the License, including but not limited to 9 * distribution rights of the Software. 10 * 11 * 12 * 13 */ 14 15 package com.liferay.portal.kernel.util; 16 17 import java.io.File; 18 import java.io.InputStream; 19 20 /** 21 * <a href="MimeTypesUtil.java.html"><b><i>View Source</i></b></a> 22 * 23 * @author Jorge Ferrer 24 * @author Brian Wing Shun Chan 25 * @author Alexander Chow 26 */ 27 public class MimeTypesUtil { 28 29 public static String getContentType(File file) { 30 return getMimeTypes().getContentType(file); 31 } 32 33 /** 34 * Determine the content type from an input stream and file name. 35 * 36 * @param fileName full name or extension of file (e.g., "Test.doc", 37 * ".doc") 38 * @return content type if it is a supported format or an empty string if it 39 * is an unsupported format 40 */ 41 public static String getContentType( 42 InputStream inputStream, String fileName) { 43 44 return getMimeTypes().getContentType(inputStream, fileName); 45 } 46 47 /** 48 * Determine the content type from a file name. 49 * 50 * @param fileName full name or extension of file (e.g., "Test.doc", 51 * ".doc") 52 * @return content type if it is a supported format or an empty string if it 53 * is an unsupported format 54 */ 55 public static String getContentType(String fileName) { 56 return getMimeTypes().getContentType(fileName); 57 } 58 59 public static MimeTypes getMimeTypes() { 60 return _mimeTypes; 61 } 62 63 public void setMimeTypes(MimeTypes mimeTypes) { 64 _mimeTypes = mimeTypes; 65 } 66 67 private static MimeTypes _mimeTypes; 68 69 }