| MimeTypesUtil.java |
1 /**
2 * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3 *
4 * This library is free software; you can redistribute it and/or modify it under
5 * the terms of the GNU Lesser General Public License as published by the Free
6 * Software Foundation; either version 2.1 of the License, or (at your option)
7 * any later version.
8 *
9 * This library is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12 * details.
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 }