Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/**
 * Appcelerator Titanium Mobile
 * Copyright (c) 2009-2010 by Appcelerator, Inc. All Rights Reserved.
 * Licensed under the terms of the Apache Public License
 * Please see the LICENSE included with this distribution for details.
 */

import java.util.HashMap;
import android.webkit.MimeTypeMap;

public class Main {
    public static final HashMap<String, String> EXTRA_MIMETYPES = new HashMap<String, String>();

    public static String getFileExtensionFromMimeType(String mimeType, String defaultExtension) {
        String result = defaultExtension;
        String extension = MimeTypeMap.getSingleton().getExtensionFromMimeType(mimeType);
        if (extension != null) {
            result = extension;
        } else {
            for (String ext : EXTRA_MIMETYPES.keySet()) {
                if (EXTRA_MIMETYPES.get(ext).equalsIgnoreCase(mimeType)) {
                    return ext;
                }
            }
        }

        return result;
    }
}