<commit_before>/*
 * jets3t : Java Extra-Tasty S3 Toolkit (for Amazon S3 online storage service)
 * This is a java.net project, see https://jets3t.dev.java.net/
 *
 * Copyright 2006 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.jets3t.service.utils;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.StringTokenizer;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * Utility class that maintains a listing of known Mimetypes, and determines the mimetype of files
 * based on file extensions.
 * <p>
 * This class is obtained with the {#link {@link #getInstance()} method that recognised loads mime
 * types  from the file <code>mime.types</code> if this file is available at the root of the
 * classpath. The mime.types file format, and most of the content, is taken from the Apache HTTP
 * server's mime.types file.
 * <p>
 * The format for mime type setting documents is:
 * <code>mimetype <Space | Tab>+ extension (<Space|Tab>+ extension)*</code>.
 * Any blank lines in the file are ignored, as are lines starting with <code>#</code> which are
 * considered comments. Lines that have a mimetype but no associated extensions are also ignored.
 * <p>
 * For more information about Mimetype settings please see:
 * <a href="http://jets3t.s3.amazonaws.com/toolkit/configuration.html">JetS3t Configuration</a>
 *
 * @author <NAME>
 */
public class Mimetypes {
    private static final Log log = LogFactory.getLog(Mimetypes.class);

    // Mimetypes used frequently in jets3t.
    /**
     * The default XML mimetype: application/xml
     */
    public static final String MIMETYPE_XML = "application/xml";
    /**
     * The default HTML mimetype: text/html
     */
    public static final String MIMETYPE_HTML = "text/html";
    /**
     * The default binary mimetype: application/octet-stream
     */
    public static final String MIMETYPE_OCTET_STREAM = "application/octet-stream";
    /**
     * The default gzip mimetype: application/x-gzip
     */
    public static final String MIMETYPE_GZIP = "application/x-gzip";

    // Mimetypes specific to jetS3T.
    /**
     * A JetS3t-specific mimetype used to indicate that an S3 object actually represents
     * a directory on the local file system.
     */
    public static final String MIMETYPE_JETS3T_DIRECTORY = "application/x-directory";

    private static Mimetypes mimetypes = null;

    /**
     * Map that stores file extensions as keys, and the corresponding mimetype as values.
     */
    private HashMap extensionToMimetypeMap = new HashMap();

    private Mimetypes() {
    }

    /**
     * Loads mime type settings from the file 'mime.types' in the classpath, if it's available.
     */
    public static Mimetypes getInstance() {
        if (mimetypes != null) {
            return mimetypes;
        }
        mimetypes = new Mimetypes();
        InputStream mimetypesFile = mimetypes.getClass().getResourceAsStream("/mime.types");
        if (mimetypesFile != null) {
            if (log.isDebugEnabled()) {
            	log.debug("Loading mime types from file in the classpath: mime.types");
            }
            try {
                mimetypes.loadAndReplaceMimetypes(mimetypesFile);
            } catch (IOException e) {
                if (log.isErrorEnabled()) {
                	log.error("Failed to load mime types from file in the classpath: mime.types", e);
                }
            }
        } else {
            if (log.isWarnEnabled()) {
            	log.warn("Unable to find 'mime.types' file in classpath");
            }
        }
        return mimetypes;
    }
<commit_msg>Fixes #9: synchronize access to singleton provider method #getInstance<commit_after>/*
 * jets3t : Java Extra-Tasty S3 Toolkit (for Amazon S3 online storage service)
 * This is a java.net project, see https://jets3t.dev.java.net/
 *
 * Copyright 2006 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.jets3t.service.utils;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.StringTokenizer;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * Utility class that maintains a listing of known Mimetypes, and determines the mimetype of files
 * based on file extensions.
 * <p>
 * This class is obtained with the {#link {@link #getInstance()} method that recognised loads mime
 * types  from the file <code>mime.types</code> if this file is available at the root of the
 * classpath. The mime.types file format, and most of the content, is taken from the Apache HTTP
 * server's mime.types file.
 * <p>
 * The format for mime type setting documents is:
 * <code>mimetype <Space | Tab>+ extension (<Space|Tab>+ extension)*</code>.
 * Any blank lines in the file are ignored, as are lines starting with <code>#</code> which are
 * considered comments. Lines that have a mimetype but no associated extensions are also ignored.
 * <p>
 * For more information about Mimetype settings please see:
 * <a href="http://jets3t.s3.amazonaws.com/toolkit/configuration.html">JetS3t Configuration</a>
 *
 * @author <NAME>
 */
public class Mimetypes {
    private static final Log log = LogFactory.getLog(Mimetypes.class);

    // Mimetypes used frequently in jets3t.
    /**
     * The default XML mimetype: application/xml
     */
    public static final String MIMETYPE_XML = "application/xml";
    /**
     * The default HTML mimetype: text/html
     */
    public static final String MIMETYPE_HTML = "text/html";
    /**
     * The default binary mimetype: application/octet-stream
     */
    public static final String MIMETYPE_OCTET_STREAM = "application/octet-stream";
    /**
     * The default gzip mimetype: application/x-gzip
     */
    public static final String MIMETYPE_GZIP = "application/x-gzip";

    // Mimetypes specific to jetS3T.
    /**
     * A JetS3t-specific mimetype used to indicate that an S3 object actually represents
     * a directory on the local file system.
     */
    public static final String MIMETYPE_JETS3T_DIRECTORY = "application/x-directory";

    private static Mimetypes mimetypes = null;

    /**
     * Map that stores file extensions as keys, and the corresponding mimetype as values.
     */
    private HashMap extensionToMimetypeMap = new HashMap();

    private Mimetypes() {
    }

    /**
     * Loads mime type settings from the file 'mime.types' in the classpath, if it's available.
     */
    public static synchronized Mimetypes getInstance() {
        if (mimetypes != null) {
            return mimetypes;
        }
        mimetypes = new Mimetypes();
        InputStream mimetypesFile = mimetypes.getClass().getResourceAsStream("/mime.types");
        if (mimetypesFile != null) {
            if (log.isDebugEnabled()) {
            	log.debug("Loading mime types from file in the classpath: mime.types");
            }
            try {
                mimetypes.loadAndReplaceMimetypes(mimetypesFile);
            } catch (IOException e) {
                if (log.isErrorEnabled()) {
                	log.error("Failed to load mime types from file in the classpath: mime.types", e);
                }
            }
        } else {
            if (log.isWarnEnabled()) {
            	log.warn("Unable to find 'mime.types' file in classpath");
            }
        }
        return mimetypes;
    }

{'fraction_non_alphanumeric': 0.09356928059218135, 'fraction_numerical': 0.004973398103169095, 'mean_word_length': 2.870635631154879, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 33, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2968999', 'n_tokens_mistral': 2460, 'n_tokens_neox': 2424, 'n_words': 875}