blob: 6222d7576a6e780f0e7cf93ba6d147036483ee12 [file] [log] [blame]
Rahul Ravikumar05336002019-10-14 15:04:32 -07001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package java.net;
18
19import java.util.Locale;
20import libcore.net.MimeUtils;
21
22/**
23 * Implements {@link FileNameMap} in terms of {@link libcore.net.MimeUtils}.
24 */
25class DefaultFileNameMap implements FileNameMap {
26 public String getContentTypeFor(String filename) {
27 if (filename.endsWith("/")) {
28 // a directory, return html
29 return MimeUtils.guessMimeTypeFromExtension("html");
30 }
31 int lastCharInExtension = filename.lastIndexOf('#');
32 if (lastCharInExtension < 0) {
33 lastCharInExtension = filename.length();
34 }
35 int firstCharInExtension = filename.lastIndexOf('.') + 1;
36 String ext = "";
37 if (firstCharInExtension > filename.lastIndexOf('/')) {
38 ext = filename.substring(firstCharInExtension, lastCharInExtension);
39 }
40 return MimeUtils.guessMimeTypeFromExtension(ext);
41 }
42}