com.google.gerrit.server.mime.DefaultFileExtensionRegistry Maven / Gradle / Ivy
The newest version!
// Copyright (C) 2013 The Android Open Source Project
//
// 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 com.google.gerrit.server.mime;
import com.google.common.collect.ImmutableMap;
import com.google.common.flogger.FluentLogger;
import eu.medsea.mimeutil.MimeException;
import eu.medsea.mimeutil.MimeType;
import eu.medsea.mimeutil.MimeUtil;
import eu.medsea.mimeutil.detector.MimeDetector;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.Properties;
/** Loads mime types from {@code mime-types.properties} at specificity of 2. */
public class DefaultFileExtensionRegistry extends MimeDetector {
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
private static final ImmutableMap TYPES;
static {
Properties prop = new Properties();
try (InputStream in =
DefaultFileExtensionRegistry.class.getResourceAsStream("mime-types.properties")) {
prop.load(in);
} catch (IOException e) {
logger.atWarning().withCause(e).log("Cannot load mime-types.properties");
}
ImmutableMap.Builder b = ImmutableMap.builder();
for (Map.Entry
© 2015 - 2024 Weber Informatics LLC | Privacy Policy