Java Activation Mimetype Check equal(String string1, String string2)

Here you can find the source of equal(String string1, String string2)

Description

Returns true if the given MIME type strings are considered equivalent because their types and subtypes match (parameters are not considered in the comparison).

License

Open Source License

Parameter

Parameter Description
string1 The first MIME type string to be compare.
string2 The second MIME type string to be compared.

Exception

Parameter Description
MimeTypeParseException If either of the MIME type strings are malformed.

Return

True if the two MIME type strings are considered equal, otherwise false.

Declaration

public static boolean equal(String string1, String string2) throws MimeTypeParseException 

Method Source Code

//package com.java2s;
/*/*w w w . j a  va 2  s .  co m*/
 * The MIT License (MIT)
 *
 * Copyright (c) 2015 Lachlan Dowding
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

import javax.activation.MimeType;

import javax.activation.MimeTypeParseException;

public class Main {
    /**
     * Returns true if the given MIME type strings are considered equivalent because their types and subtypes match
     * (parameters are not considered in the comparison).
     *
     * @param string1 The first MIME type string to be compare.
     * @param string2 The second MIME type string to be compared.
     * @return True if the two MIME type strings are considered equal, otherwise false.
     * @throws MimeTypeParseException If either of the MIME type strings are malformed.
     */
    public static boolean equal(String string1, String string2) throws MimeTypeParseException {
        if (string1 == null && string2 == null)
            return true;
        if (string1 == null || string2 == null)
            return false;

        MimeType mimeType1 = new MimeType(string1);
        MimeType mimeType2 = new MimeType(string2);

        return mimeType1.match(mimeType2);
    }
}

Related

  1. copyMimeType(final MimeType original)
  2. createWildcard()
  3. getContentType(String filename)
  4. getContentType(String filePath)
  5. getContentTypeFromFileName(String fileName)
  6. getMimeType(final String filename)