httpcontenttype.java

来自「OS(OpenSymphony)的SiteMesh是一个用来在JSP中实现页面布」· Java 代码 · 共 59 行

JAVA
59
字号
package com.opensymphony.module.sitemesh.filter;/** * Extracts the type and encoding from an HTTP Content-Type header. * * @author Scott Farquhar */public class HttpContentType {    private final String type;    private final String encoding;    public HttpContentType(String fullValue) {        // this is the content type + charset. eg: text/html;charset=UTF-8        int offset = fullValue.lastIndexOf("charset=");        encoding = offset != -1 ? extractContentTypeValue(fullValue, offset + 8) : null;        type = extractContentTypeValue(fullValue, 0);    }    private String extractContentTypeValue(String type, int startIndex) {        if (startIndex < 0)            return null;        // Skip over any leading spaces        while (startIndex < type.length() && type.charAt(startIndex) == ' ') startIndex++;        if (startIndex >= type.length()) {            return null;        }        int endIndex = startIndex;        if (type.charAt(startIndex) == '"') {            startIndex++;            endIndex = type.indexOf('"', startIndex);            if (endIndex == -1)                endIndex = type.length();        } else {            // Scan through until we hit either  the end of the string or a            // special character (as defined in RFC-2045). Note that we ignore '/'            // since we want to capture it as part of the value.            char ch;            while (endIndex < type.length() && (ch = type.charAt(endIndex)) != ' ' && ch != ';'                    && ch != '(' && ch != ')' && ch != '[' && ch != ']' && ch != '<' && ch != '>'                    && ch != ':' && ch != ',' && ch != '=' && ch != '?' && ch != '@' && ch != '"'                    && ch != '\\') endIndex++;        }        return type.substring(startIndex, endIndex);    }    public String getType() {        return type;    }    public String getEncoding() {        return encoding;    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?