001 /** 002 * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved. 003 * 004 * This library is free software; you can redistribute it and/or modify it under 005 * the terms of the GNU Lesser General Public License as published by the Free 006 * Software Foundation; either version 2.1 of the License, or (at your option) 007 * any later version. 008 * 009 * This library is distributed in the hope that it will be useful, but WITHOUT 010 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 011 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 012 * details. 013 */ 014 015 package com.liferay.portal.kernel.util; 016 017 import java.io.File; 018 import java.io.InputStream; 019 020 /** 021 * @author Jorge Ferrer 022 * @author Brian Wing Shun Chan 023 * @author Alexander Chow 024 */ 025 public class MimeTypesUtil { 026 027 public static String getContentType(File file) { 028 return getMimeTypes().getContentType(file); 029 } 030 031 /** 032 * Determine the content type from an input stream and file name. 033 * 034 * @param fileName full name or extension of file (e.g., "Test.doc", 035 * ".doc") 036 * @return content type if it is a supported format or an empty string if it 037 * is an unsupported format 038 */ 039 public static String getContentType( 040 InputStream inputStream, String fileName) { 041 042 return getMimeTypes().getContentType(inputStream, fileName); 043 } 044 045 /** 046 * Determine the content type from a file name. 047 * 048 * @param fileName full name or extension of file (e.g., "Test.doc", 049 * ".doc") 050 * @return content type if it is a supported format or an empty string if it 051 * is an unsupported format 052 */ 053 public static String getContentType(String fileName) { 054 return getMimeTypes().getContentType(fileName); 055 } 056 057 public static MimeTypes getMimeTypes() { 058 return _mimeTypes; 059 } 060 061 public void setMimeTypes(MimeTypes mimeTypes) { 062 _mimeTypes = mimeTypes; 063 } 064 065 private static MimeTypes _mimeTypes; 066 067 }