0%

PROBLEM

While migrating a portion of my Java code to Groovy code, I got bitten by the Groovy operator loading feature that I should have known better… and my pride hurts, but hey, I admit I write shitty code.

Consider this simple POGO with custom equals() and hashCode(), both implemented using Google Guava libraries:-

@Canonical
class Person {
    String firstName
    String lastName
    String email

    @Override
    boolean equals(Object o) {
        if (this == o) {
            return true
        }
        if (o == null || getClass() != o.getClass()) {
            return false
        }

        final Person other = (Person) o

        return Objects.equal(email, other.email)
    }

    @Override
    int hashCode() {
        return Objects.hashCode(email)
    }
}

What is wrong with the above code? Well, if you are mostly a Java developer like me, this look pretty much correct. However, when I perform an equality check, I get java.lang.StackOverflowError exception. I tend to see this exception when I write my too-smart-for-production recursion API that couldn’t seem find its way to end the recursion, causing the JVM stack to blow up.

SOLUTION

The reason we are getting java.lang.StackOverflowError exception is because Groovy overloads == with equals(). So, if (this == o) { ... } becomes if (this.equals(o)) { ... }. When we perform an equality check, it will call itself again and again until it chokes itself and dies.

To fix this, we have to use if (this.is(o)) { ... } to perform an identity check:-

@Canonical
class Person {
    String firstName
    String lastName
    String email

    @Override
    boolean equals(Object o) {
        if (this.is(o)) {
            return true
        }
        if (o == null || getClass() != o.getClass()) {
            return false
        }

        final Person other = (Person) o

        return Objects.equal(email, other.email)
    }

    @Override
    int hashCode() {
        return Objects.hashCode(email)
    }
}

原文地址:https://zhuanlan.zhihu.com/p/384752564

作者:chrootliu,腾讯 QQ 音乐前端开发工程师

本文将会从:安装 -> 全局配置 -> 常用的各种配置 来书写,其中常用配置写的炒鸡详细,需要的童鞋可以直接滑倒相应的位置查看。

安装 nginx

下载 nginx 的压缩包文件到根目录,官网下载地址:https://nginx.org/download/

yum update #更新系统软件
cd /
wget nginx.org/download/nginx-1.17.2.tar.gz

解压 tar.gz 压缩包文件,进去 nginx-1.17.2

tar -xzvf nginx-1.17.2.tar.gz
cd nginx-1.17.2

进入文件夹后进行配置检查

./configure

通过安装前的配置检查,发现有报错。检查中发现一些依赖库没有找到,这时候需要先安装 nginx 的一些依赖库

yum -y install pcre* #安装使nginx支持rewrite
yum -y install gcc-c++
yum -y install zlib*
yum -y install openssl openssl-devel

再次进行检查操作 ./configure 没发现报错显示,接下来进行编译并安装的操作

# 检查模块支持
./configure  --prefix=/usr/local/nginx  --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_auth_request_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_slice_module --with-http_stub_status_module --with-mail --with-mail_ssl_module --with-stream --with-stream_ssl_module --with-stream_realip_module --with-stream_ssl_preread_module --with-threads --user=www --group=www

这里得特别注意下,你以后需要用到的功能模块是否存在,不然以后添加新的包会比较麻烦。

查看默认安装的模块支持

命令 ls nginx-1.17.2 查看 nginx 的文件列表,可以发现里面有一个 auto 的目录。

在这个 auto 目录中有一个 options 文件,这个文件里面保存的就是 nginx 编译过程中的所有选项配置。

通过命令:cat nginx-1.17.2/auto/options | grep YES就可以查看

nginx 编译安装时,怎么查看安装模块

编译并安装

make && make install

这里需要注意,模块的支持跟后续的 nginx 配置有关,比如 SSL,gzip 压缩等等,编译安装前最好检查需要配置的模块存不存在。

查看 nginx 安装后在的目录,可以看到已经安装到 /usr/local/nginx 目录了

whereis nginx
$nginx: /usr/local/nginx

启动 nginx 服务

cd /usr/local/nginx/sbin/
./nginx

服务启动的时候报错了:nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) ,通过命令查看本机网络地址和端口等一些信息,找到被占用的 80 端口 netstat -ntpl 的 tcp 连接,并杀死进程 (kill 进程 pid)

netstat -ntpl
kill 进程PID

继续启动 nginx 服务,启动成功

./nginx

在浏览器直接访问 ip 地址,页面出现 Welcome to Nginx! 则安装成功。

阅读全文 »

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.stereotype.Service;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.DefaultTransactionDefinition;
import org.springframework.transaction.support.TransactionSynchronizationAdapter;
import org.springframework.transaction.support.TransactionSynchronizationManager;

import java.util.concurrent.Callable;

@Service
public class TransactionUtil {

    private static Logger log = LoggerFactory.getLogger(TransactionUtil.class);

    @Autowired
    private DataSourceTransactionManager dataSourceTransactionManager;

    public <T> T doTransaction(Callable<T> job, Runnable rollback) {
        DefaultTransactionDefinition def = new DefaultTransactionDefinition();
        def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
        TransactionStatus status = dataSourceTransactionManager.getTransaction(def);
        try {
            T t = job.call();
            dataSourceTransactionManager.commit(status);
            return t;
        } catch (Exception e) {
            dataSourceTransactionManager.rollback(status);
            if (rollback != null) {
                rollback.run();
            }
            log.error(e.getMessage(), e);
            throw new RuntimeException(e);
        }
    }

    public <T> T doTransaction(Callable<T> job) {
        return doTransaction(job, null);
    }

    /**
    * 开启事务(PROPAGATION_REQUIRED)
    */
    public TransactionStatus begin() {
        return getTransactionStatus(TransactionDefinition.PROPAGATION_REQUIRED);
    }

    /**
    * 开启事务(PROPAGATION_REQUIRES_NEW)
    */
    public TransactionStatus beginNew() {
        return getTransactionStatus(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
    }

    /**
    * 事务提交
    */
    public void commit(TransactionStatus status) {
        dataSourceTransactionManager.commit(status);
    }

    /**
    * 事务回滚
    */
    public void rollback(TransactionStatus status) {
        dataSourceTransactionManager.rollback(status);
    }

    private TransactionStatus getTransactionStatus(int propagationRequiresNew) {
        DefaultTransactionDefinition def = new DefaultTransactionDefinition();
        def.setPropagationBehavior(propagationRequiresNew);
        TransactionStatus status = dataSourceTransactionManager.getTransaction(def);
        return status;
    }

    /**
    * 判断当前线程是否处于事物中,是就等事物提交后再执行,否则直接执行
    * @param runnable 线程任务
    */
    public static void executeAfterCommit(Runnable runnable) {
        if (TransactionSynchronizationManager.isActualTransactionActive()) {
            TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() {
                @Override
                public void afterCommit() {
                    runnable.run();
                }
            });
        }else{
            runnable.run();
        }
    }

}

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 简易的 HTTP 请求类
 */
public class HttpUtil {

    private static final Logger log = LoggerFactory.getLogger(HttpUtil.class);

    private static final int API_TIMEOUT = 180000;

    private static final String POST = "POST";

    private static final String GET = "GET";

    private static String defaultEncoding = "utf-8";

    /**
     * http post 请求.请求参数自由组织
     *
     * @param url 地址
     * @param data 请求参数,请求参数可以是 name1=value1&name2=value2 的形式,也可以是xml、json等其他格式
     * @param charset 字符编码
     * @return
     */
    public static String post(String url, String data, String charset) {
        return httpAccessJDK(url, data, charset, POST);
    }

    /**
     * http post 请求
     *
     * @param url 地址
     * @param params 请求参数键值对
     * @param charset 编码
     * @return 以字符串形式返回
     */
    public static String post(String url, Map<String, String> params, String charset) {
        String paramStr = getHttpRequestParams(url, params, charset);
        return httpAccessJDK(url, paramStr, charset, POST);
    }

    /**
     * http post 请求.默认编码(utf-8)
     *
     * @param url 地址
     * @param params 请求参数键值对
     * @return 以字符串形式返回
     */
    public static String post(String url, Map<String, String> params) {
        String paramStr = getHttpRequestParams(url, params, defaultEncoding);
        return httpAccessJDK(url, paramStr, defaultEncoding, POST);
    }

    /**
     * http post 请求
     *
     * @param url 地址
     * @param charset 编码
     * @return 以字符串形式返回
     */
    public static String post(String url, String charset) {
        return httpAccessJDK(url, null, charset, POST);
    }

    /**
     * http post 请求.默认编码(utf-8)
     *
     * @param url 地址
     * @return 以字符串形式返回
     */
    public static String post(String url) {
        return httpAccessJDK(url, null, defaultEncoding, POST);
    }

    /**
     * http get 请求
     *
     * @param url 地址(可带参数)
     * @param params 请求参数键值对
     * @param charset 编码
     * @return 以字符串形式返回
     */
    public static String get(String url, Map<String, String> params, String charset) {
        String paramStr = getHttpRequestParams(url, params, charset);
        return httpAccessJDK(url, paramStr, charset, GET);
    }

    /**
     * http get 请求.默认编码(utf-8)
     *
     * @param url 地址(可带参数)
     * @param params 请求参数键值对
     * @return 以字符串形式返回
     */
    public static String get(String url, Map<String, String> params) {
        String paramStr = getHttpRequestParams(url, params, defaultEncoding);
        return httpAccessJDK(url, paramStr, defaultEncoding, GET);
    }

    /**
     * http get 请求
     *
     * @param url 地址
     * @param charset 编码
     * @return 以字符串形式返回
     */
    public static String get(String url, String charset) {
        return httpAccessJDK(url, null, charset, GET);
    }

    /**
     * http get 请求.默认编码(utf-8)
     *
     * @param url 地址
     * @return 以字符串形式返回
     */
    public static String get(String url) {
        return httpAccessJDK(url, null, defaultEncoding, GET);
    }

    /**
     * 生成参数
     *
     * @param url
     * @param params
     * @param charset
     * @return
     */
    public static String getHttpRequestParams(String url, Map<String, String> params, String charset) {
        if (params == null || params.size() == 0) {
            return null;
        }
        StringBuilder paramSb = new StringBuilder();
        if (charset == null) {
            charset = defaultEncoding;
        }
        try {
            int i = 0, len = params != null ? params.size() : 0;
            for (Map.Entry<String, String> entry : params.entrySet()) {
                if (entry.getKey() == null || entry.getValue() == null) {
                    i++;
                    continue;
                }
                paramSb.append(URLEncoder.encode(entry.getKey(), charset)).append("=").append(URLEncoder.encode(entry.getValue(), charset));
                if (i != len - 1) {
                    paramSb.append("&");
                }
                i++;
            }
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }
        return paramSb.toString();
    }

    /**
     * 请求
     *
     * @param url 地址
     * @param data 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。
     * @param charset 字符编码
     * @param method
     * @return
     */
    private static String httpAccessJDK(String url, String data, String charset, String method) {
        if (method == null) {
            method = GET;
        }
        if (charset == null) {
            charset = defaultEncoding;
        }

        StringBuilder content = new StringBuilder();
        int sequence = -1;

        try {
            if (data != null && method.equals(GET)) {
                if (url.indexOf("?") == -1) {
                    url = new StringBuilder(url).append("?").append(data).toString();
                }
                else {
                    url = new StringBuilder(url).append("&").append(data).toString();
                }
            }

            if (log.isInfoEnabled()) {
                sequence = (int) (Math.random() * 500000);
                log.info("[http](" + sequence + ") " + method.toLowerCase() + ": " + url);
                if (data != null) {
                    log.info("[http](" + sequence + ") param: " + (data.length() > 100 ? data.substring(0, 100) + "..." : data));
                }
                else {
                    log.info("[http](" + sequence + ") param: " + data);
                }

            }

            HttpURLConnection conn = null;

            URL getUrl = new URL(url);
            conn = (HttpURLConnection) getUrl.openConnection();
            conn.setConnectTimeout(API_TIMEOUT);
            conn.setReadTimeout(API_TIMEOUT);

            conn.setDoOutput(true);
            conn.setDoInput(true);
            conn.setRequestMethod(method);
            conn.setUseCaches(false);
            conn.setInstanceFollowRedirects(true);

            conn.connect();
            if (data != null && method.equals(POST)) {
                byte[] bdata = data.getBytes(charset);
                DataOutputStream out = new DataOutputStream(conn.getOutputStream());
                out.write(bdata);
                out.flush();
                out.close();
            }

            BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream(), charset));
            String inputLine;

            while ((inputLine = reader.readLine()) != null) {
                content.append(inputLine);
            }
            reader.close();
            conn.disconnect();
        } catch (Exception e) {
            // log.error(e.getMessage(), e);
            throw new RuntimeException(e);
        }

        String result = content.toString();
        if (log.isInfoEnabled()) {
            log.info("[http](" + sequence + ") response: " + result);
        }

        return result;
    }

}

import java.security.SecureRandom;
import java.util.UUID;

/**
 * 长度为16的 UUID 字符串生成器, 仿 java.util.UUID 实现,修改内容如下: 将16位byte数组缩短为10位,将16进制字符转换改为32进制转换
 */
public class UUIDShort {

    private static char[] digits = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' };

    private static String toUnsignedString(long i, int shift) {
        char[] buf = new char[64];
        int charPos = 64;
        int radix = 1 << shift;
        long mask = radix - 1;
        do {
            buf[--charPos] = digits[(int) (i & mask)];
            i >>>= shift;
        } while (i != 0);
        return new String(buf, charPos, (64 - charPos));
    }

    private static SecureRandom ng = new SecureRandom();

    /**
     * 生成一个长度为16的随机字符串
     *
     * @return
     */
    public static String random16() {
        byte[] data = new byte[10];
        ng.nextBytes(data);
        long msb = 0;
        long lsb = 0;
        for (int i = 0; i < 5; i++) {
            msb = (msb << 8) | (data[i] & 0xff);
        }
        for (int i = 5; i < 10; i++) {
            lsb = (lsb << 8) | (data[i] & 0xff);
        }
        String random = toUnsignedString(msb, 5) + toUnsignedString(lsb, 5);
        if (random.length() < 16) {
            for (int i = 0; i < 16 - random.length(); i++) {
                random = digits[ng.nextInt(36)] + random;
            }
        }
        return random;
    }

    public static String random32() {
        return UUID.randomUUID().toString();
    }

}

import java.math.BigDecimal;

/**
 * 数字转换为汉语中人民币的大写
 */
public class NumberToCn {

    /**
     * 汉语中数字大写
     */
    private static final String[] CN_UPPER_NUMBER = { "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖" };

    /**
     * 汉语中货币单位大写,这样的设计类似于占位符
     */
    private static final String[] CN_UPPER_MONETRAY_UNIT = { "分", "角", "元", "拾", "佰", "仟", "万", "拾", "佰", "仟", "亿", "拾", "佰", "仟", "兆", "拾", "佰", "仟" };

    /**
     * 特殊字符:整
     */
    private static final String CN_FULL = "整";

    /**
     * 特殊字符:负
     */
    private static final String CN_NEGATIVE = "负";

    /**
     * 金额的精度,默认值为2
     */
    private static final int MONEY_PRECISION = 2;

    /**
     * 特殊字符:零元整
     */
    private static final String CN_ZEOR_FULL = "零元" + CN_FULL;

    /**
     * 把输入的金额转换为汉语中人民币的大写
     *
     * @param numberOfMoney 输入的金额
     * @return 对应的汉语大写
     */
    public static String number2CNMontrayUnit(BigDecimal numberOfMoney) {
        StringBuffer sb = new StringBuffer();
        // -1, 0, or 1 as the value of this BigDecimal is negative, zero, or positive.
        int signum = numberOfMoney.signum();
        // 零元整的情况
        if (signum == 0) {
            return CN_ZEOR_FULL;
        }
        // 这里会进行金额的四舍五入
        long number = numberOfMoney.movePointRight(MONEY_PRECISION).setScale(0, 4).abs().longValue();
        // 得到小数点后两位值
        long scale = number % 100;
        int numUnit = 0;
        int numIndex = 0;
        boolean getZero = false;
        // 判断最后两位数,一共有四中情况:00 = 0, 01 = 1, 10, 11
        if (!(scale > 0)) {
            numIndex = 2;
            number = number / 100;
            getZero = true;
        }
        if ((scale > 0) && (!(scale % 10 > 0))) {
            numIndex = 1;
            number = number / 10;
            getZero = true;
        }
        int zeroSize = 0;
        while (true) {
            if (number <= 0) {
                break;
            }
            // 每次获取到最后一个数
            numUnit = (int) (number % 10);
            if (numUnit > 0) {
                if ((numIndex == 9) && (zeroSize >= 3)) {
                    sb.insert(0, CN_UPPER_MONETRAY_UNIT[6]);
                }
                if ((numIndex == 13) && (zeroSize >= 3)) {
                    sb.insert(0, CN_UPPER_MONETRAY_UNIT[10]);
                }
                sb.insert(0, CN_UPPER_MONETRAY_UNIT[numIndex]);
                sb.insert(0, CN_UPPER_NUMBER[numUnit]);
                getZero = false;
                zeroSize = 0;
            } else {
                ++zeroSize;
                if (!(getZero)) {
                    sb.insert(0, CN_UPPER_NUMBER[numUnit]);
                }
                if (numIndex == 2) {
                    if (number > 0) {
                        sb.insert(0, CN_UPPER_MONETRAY_UNIT[numIndex]);
                    }
                } else if (((numIndex - 2) % 4 == 0) && (number % 1000 > 0)) {
                    sb.insert(0, CN_UPPER_MONETRAY_UNIT[numIndex]);
                }
                getZero = true;
            }
            // 让number每次都去掉最后一个数
            number = number / 10;
            ++numIndex;
        }
        // 如果signum == -1,则说明输入的数字为负数,就在最前面追加特殊字符:负
        if (signum == -1) {
            sb.insert(0, CN_NEGATIVE);
        }
        // 输入的数字小数点后两位为"00"的情况,则要在最后追加特殊字符:整
        if (!(scale > 0)) {
            sb.append(CN_FULL);
        }
        return sb.toString();
    }

}

import java.util.HashMap;

public class MimeTypes {

   static HashMap<String, String> type = new HashMap<String, String>();

   static {
      type.put("ez", "application/andrew-inset");
      type.put("aw", "application/applixware");
      type.put("atom", "application/atom+xml");
      type.put("atomcat", "application/atomcat+xml");
      type.put("atomsvc", "application/atomsvc+xml");
      type.put("ccxml", "application/ccxml+xml");
      type.put("cdmia", "application/cdmi-capability");
      type.put("cdmic", "application/cdmi-container");
      type.put("cdmid", "application/cdmi-domain");
      type.put("cdmio", "application/cdmi-object");
      type.put("cdmiq", "application/cdmi-queue");
      type.put("cu", "application/cu-seeme");
      type.put("mdp", "application/dash+xml");
      type.put("davmount", "application/davmount+xml");
      type.put("dbk", "application/docbook+xml");
      type.put("dssc", "application/dssc+der");
      type.put("xdssc", "application/dssc+xml");
      type.put("ecma", "application/ecmascript");
      type.put("emma", "application/emma+xml");
      type.put("epub", "application/epub+zip");
      type.put("exi", "application/exi");
      type.put("pfr", "application/font-tdpfr");
      type.put("woff", "application/font-woff");
      type.put("woff2", "application/font-woff2");
      type.put("gml", "application/gml+xml");
      type.put("gpx", "application/gpx+xml");
      type.put("gxf", "application/gxf");
      type.put("stk", "application/hyperstudio");
      type.put("ink", "application/inkml+xml");
      type.put("inkml", "application/inkml+xml");
      type.put("ipfix", "application/ipfix");
      type.put("jar", "application/java-archive");
      type.put("ser", "application/java-serialized-object");
      type.put("class", "application/java-vm");
      type.put("js", "application/javascript");
      type.put("json", "application/json");
      type.put("map", "application/json");
      type.put("json5", "application/json5");
      type.put("jsonml", "application/jsonml+json");
      type.put("lostxml", "application/lost+xml");
      type.put("hqx", "application/mac-binhex40");
      type.put("cpt", "application/mac-compactpro");
      type.put("mads", "application/mads+xml");
      type.put("mrc", "application/marc");
      type.put("mrcx", "application/marcxml+xml");
      type.put("ma", "application/mathematica");
      type.put("nb", "application/mathematica");
      type.put("mb", "application/mathematica");
      type.put("mathml", "application/mathml+xml");
      type.put("mbox", "application/mbox");
      type.put("mscml", "application/mediaservercontrol+xml");
      type.put("metalink", "application/metalink+xml");
      type.put("meta4", "application/metalink4+xml");
      type.put("mets", "application/mets+xml");
      type.put("mods", "application/mods+xml");
      type.put("m21", "application/mp21");
      type.put("mp21", "application/mp21");
      type.put("mp4s", "application/mp4");
      type.put("m4p", "application/mp4");
      type.put("doc", "application/msword");
      type.put("dot", "application/msword");
      type.put("mxf", "application/mxf");
      type.put("bin", "application/octet-stream");
      type.put("dms", "application/octet-stream");
      type.put("lrf", "application/octet-stream");
      type.put("mar", "application/octet-stream");
      type.put("so", "application/octet-stream");
      type.put("dist", "application/octet-stream");
      type.put("distz", "application/octet-stream");
      type.put("pkg", "application/octet-stream");
      type.put("bpk", "application/octet-stream");
      type.put("dump", "application/octet-stream");
      type.put("elc", "application/octet-stream");
      type.put("deploy", "application/octet-stream");
      type.put("buffer", "application/octet-stream");
      type.put("oda", "application/oda");
      type.put("opf", "application/oebps-package+xml");
      type.put("ogx", "application/ogg");
      type.put("omdoc", "application/omdoc+xml");
      type.put("onetoc", "application/onenote");
      type.put("onetoc2", "application/onenote");
      type.put("onetmp", "application/onenote");
      type.put("onepkg", "application/onenote");
      type.put("oxps", "application/oxps");
      type.put("xer", "application/patch-ops-error+xml");
      type.put("pdf", "application/pdf");
      type.put("pgp", "application/pgp-encrypted");
      type.put("asc", "application/pgp-signature");
      type.put("sig", "application/pgp-signature");
      type.put("prf", "application/pics-rules");
      type.put("p10", "application/pkcs10");
      type.put("p7m", "application/pkcs7-mime");
      type.put("p7c", "application/pkcs7-mime");
      type.put("p7s", "application/pkcs7-signature");
      type.put("p8", "application/pkcs8");
      type.put("ac", "application/pkix-attr-cert");
      type.put("cer", "application/pkix-cert");
      type.put("crl", "application/pkix-crl");
      type.put("pkipath", "application/pkix-pkipath");
      type.put("pki", "application/pkixcmp");
      type.put("pls", "application/pls+xml");
      type.put("ai", "application/postscript");
      type.put("eps", "application/postscript");
      type.put("ps", "application/postscript");
      type.put("cww", "application/prs.cww");
      type.put("pskcxml", "application/pskc+xml");
      type.put("rdf", "application/rdf+xml");
      type.put("rif", "application/reginfo+xml");
      type.put("rnc", "application/relax-ng-compact-syntax");
      type.put("rl", "application/resource-lists+xml");
      type.put("rld", "application/resource-lists-diff+xml");
      type.put("rs", "application/rls-services+xml");
      type.put("gbr", "application/rpki-ghostbusters");
      type.put("mft", "application/rpki-manifest");
      type.put("roa", "application/rpki-roa");
      type.put("rsd", "application/rsd+xml");
      type.put("rss", "application/rss+xml");
      type.put("rtf", "application/rtf");
      type.put("sbml", "application/sbml+xml");
      type.put("scq", "application/scvp-cv-request");
      type.put("scs", "application/scvp-cv-response");
      type.put("spq", "application/scvp-vp-request");
      type.put("spp", "application/scvp-vp-response");
      type.put("sdp", "application/sdp");
      type.put("setpay", "application/set-payment-initiation");
      type.put("setreg", "application/set-registration-initiation");
      type.put("shf", "application/shf+xml");
      type.put("smi", "application/smil+xml");
      type.put("smil", "application/smil+xml");
      type.put("rq", "application/sparql-query");
      type.put("srx", "application/sparql-results+xml");
      type.put("gram", "application/srgs");
      type.put("grxml", "application/srgs+xml");
      type.put("sru", "application/sru+xml");
      type.put("ssdl", "application/ssdl+xml");
      type.put("ssml", "application/ssml+xml");
      type.put("tei", "application/tei+xml");
      type.put("teicorpus", "application/tei+xml");
      type.put("tfi", "application/thraud+xml");
      type.put("tsd", "application/timestamped-data");
      type.put("plb", "application/vnd.3gpp.pic-bw-large");
      type.put("psb", "application/vnd.3gpp.pic-bw-small");
      type.put("pvb", "application/vnd.3gpp.pic-bw-var");
      type.put("tcap", "application/vnd.3gpp2.tcap");
      type.put("pwn", "application/vnd.3m.post-it-notes");
      type.put("aso", "application/vnd.accpac.simply.aso");
      type.put("imp", "application/vnd.accpac.simply.imp");
      type.put("acu", "application/vnd.acucobol");
      type.put("atc", "application/vnd.acucorp");
      type.put("acutc", "application/vnd.acucorp");
      type.put("air", "application/vnd.adobe.air-application-installer-package+zip");
      type.put("fcdt", "application/vnd.adobe.formscentral.fcdt");
      type.put("fxp", "application/vnd.adobe.fxp");
      type.put("fxpl", "application/vnd.adobe.fxp");
      type.put("xdp", "application/vnd.adobe.xdp+xml");
      type.put("xfdf", "application/vnd.adobe.xfdf");
      type.put("ahead", "application/vnd.ahead.space");
      type.put("azf", "application/vnd.airzip.filesecure.azf");
      type.put("azs", "application/vnd.airzip.filesecure.azs");
      type.put("azw", "application/vnd.amazon.ebook");
      type.put("acc", "application/vnd.americandynamics.acc");
      type.put("ami", "application/vnd.amiga.ami");
      type.put("apk", "application/vnd.android.package-archive");
      type.put("cii", "application/vnd.anser-web-certificate-issue-initiation");
      type.put("fti", "application/vnd.anser-web-funds-transfer-initiation");
      type.put("atx", "application/vnd.antix.game-component");
      type.put("mpkg", "application/vnd.apple.installer+xml");
      type.put("m3u8", "application/vnd.apple.mpegurl");
      type.put("swi", "application/vnd.aristanetworks.swi");
      type.put("iota", "application/vnd.astraea-software.iota");
      type.put("aep", "application/vnd.audiograph");
      type.put("mpm", "application/vnd.blueice.multipass");
      type.put("bmi", "application/vnd.bmi");
      type.put("rep", "application/vnd.businessobjects");
      type.put("cdxml", "application/vnd.chemdraw+xml");
      type.put("mmd", "application/vnd.chipnuts.karaoke-mmd");
      type.put("cdy", "application/vnd.cinderella");
      type.put("cla", "application/vnd.claymore");
      type.put("rp9", "application/vnd.cloanto.rp9");
      type.put("c4g", "application/vnd.clonk.c4group");
      type.put("c4d", "application/vnd.clonk.c4group");
      type.put("c4f", "application/vnd.clonk.c4group");
      type.put("c4p", "application/vnd.clonk.c4group");
      type.put("c4u", "application/vnd.clonk.c4group");
      type.put("c11amc", "application/vnd.cluetrust.cartomobile-config");
      type.put("c11amz", "application/vnd.cluetrust.cartomobile-config-pkg");
      type.put("csp", "application/vnd.commonspace");
      type.put("cdbcmsg", "application/vnd.contact.cmsg");
      type.put("cmc", "application/vnd.cosmocaller");
      type.put("clkx", "application/vnd.crick.clicker");
      type.put("clkk", "application/vnd.crick.clicker.keyboard");
      type.put("clkp", "application/vnd.crick.clicker.palette");
      type.put("clkt", "application/vnd.crick.clicker.template");
      type.put("clkw", "application/vnd.crick.clicker.wordbank");
      type.put("wbs", "application/vnd.criticaltools.wbs+xml");
      type.put("pml", "application/vnd.ctc-posml");
      type.put("ppd", "application/vnd.cups-ppd");
      type.put("car", "application/vnd.curl.car");
      type.put("pcurl", "application/vnd.curl.pcurl");
      type.put("dart", "application/vnd.dart");
      type.put("rdz", "application/vnd.data-vision.rdz");
      type.put("uvf", "application/vnd.dece.data");
      type.put("uvvf", "application/vnd.dece.data");
      type.put("uvd", "application/vnd.dece.data");
      type.put("uvvd", "application/vnd.dece.data");
      type.put("uvt", "application/vnd.dece.ttml+xml");
      type.put("uvvt", "application/vnd.dece.ttml+xml");
      type.put("uvx", "application/vnd.dece.unspecified");
      type.put("uvvx", "application/vnd.dece.unspecified");
      type.put("uvz", "application/vnd.dece.zip");
      type.put("uvvz", "application/vnd.dece.zip");
      type.put("fe_launch", "application/vnd.denovo.fcselayout-link");
      type.put("dna", "application/vnd.dna");
      type.put("mlp", "application/vnd.dolby.mlp");
      type.put("dpg", "application/vnd.dpgraph");
      type.put("dfac", "application/vnd.dreamfactory");
      type.put("kpxx", "application/vnd.ds-keypoint");
      type.put("ait", "application/vnd.dvb.ait");
      type.put("svc", "application/vnd.dvb.service");
      type.put("geo", "application/vnd.dynageo");
      type.put("mag", "application/vnd.ecowin.chart");
      type.put("nml", "application/vnd.enliven");
      type.put("esf", "application/vnd.epson.esf");
      type.put("msf", "application/vnd.epson.msf");
      type.put("qam", "application/vnd.epson.quickanime");
      type.put("slt", "application/vnd.epson.salt");
      type.put("ssf", "application/vnd.epson.ssf");
      type.put("es3", "application/vnd.eszigno3+xml");
      type.put("et3", "application/vnd.eszigno3+xml");
      type.put("ez2", "application/vnd.ezpix-album");
      type.put("ez3", "application/vnd.ezpix-package");
      type.put("fdf", "application/vnd.fdf");
      type.put("mseed", "application/vnd.fdsn.mseed");
      type.put("seed", "application/vnd.fdsn.seed");
      type.put("dataless", "application/vnd.fdsn.seed");
      type.put("gph", "application/vnd.flographit");
      type.put("ftc", "application/vnd.fluxtime.clip");
      type.put("fm", "application/vnd.framemaker");
      type.put("frame", "application/vnd.framemaker");
      type.put("maker", "application/vnd.framemaker");
      type.put("book", "application/vnd.framemaker");
      type.put("fnc", "application/vnd.frogans.fnc");
      type.put("ltf", "application/vnd.frogans.ltf");
      type.put("fsc", "application/vnd.fsc.weblaunch");
      type.put("oas", "application/vnd.fujitsu.oasys");
      type.put("oa2", "application/vnd.fujitsu.oasys2");
      type.put("oa3", "application/vnd.fujitsu.oasys3");
      type.put("fg5", "application/vnd.fujitsu.oasysgp");
      type.put("bh2", "application/vnd.fujitsu.oasysprs");
      type.put("ddd", "application/vnd.fujixerox.ddd");
      type.put("xdw", "application/vnd.fujixerox.docuworks");
      type.put("xbd", "application/vnd.fujixerox.docuworks.binder");
      type.put("fzs", "application/vnd.fuzzysheet");
      type.put("txd", "application/vnd.genomatix.tuxedo");
      type.put("ggb", "application/vnd.geogebra.file");
      type.put("ggt", "application/vnd.geogebra.tool");
      type.put("gex", "application/vnd.geometry-explorer");
      type.put("gre", "application/vnd.geometry-explorer");
      type.put("gxt", "application/vnd.geonext");
      type.put("g2w", "application/vnd.geoplan");
      type.put("g3w", "application/vnd.geospace");
      type.put("gmx", "application/vnd.gmx");
      type.put("kml", "application/vnd.google-earth.kml+xml");
      type.put("kmz", "application/vnd.google-earth.kmz");
      type.put("gqf", "application/vnd.grafeq");
      type.put("gqs", "application/vnd.grafeq");
      type.put("gac", "application/vnd.groove-account");
      type.put("ghf", "application/vnd.groove-help");
      type.put("gim", "application/vnd.groove-identity-message");
      type.put("grv", "application/vnd.groove-injector");
      type.put("gtm", "application/vnd.groove-tool-message");
      type.put("tpl", "application/vnd.groove-tool-template");
      type.put("vcg", "application/vnd.groove-vcard");
      type.put("hal", "application/vnd.hal+xml");
      type.put("zmm", "application/vnd.handheld-entertainment+xml");
      type.put("hbci", "application/vnd.hbci");
      type.put("les", "application/vnd.hhe.lesson-player");
      type.put("hpgl", "application/vnd.hp-hpgl");
      type.put("hpid", "application/vnd.hp-hpid");
      type.put("hps", "application/vnd.hp-hps");
      type.put("jlt", "application/vnd.hp-jlyt");
      type.put("pcl", "application/vnd.hp-pcl");
      type.put("pclxl", "application/vnd.hp-pclxl");
      type.put("mpy", "application/vnd.ibm.minipay");
      type.put("afp", "application/vnd.ibm.modcap");
      type.put("listafp", "application/vnd.ibm.modcap");
      type.put("list3820", "application/vnd.ibm.modcap");
      type.put("irm", "application/vnd.ibm.rights-management");
      type.put("sc", "application/vnd.ibm.secure-container");
      type.put("icc", "application/vnd.iccprofile");
      type.put("icm", "application/vnd.iccprofile");
      type.put("igl", "application/vnd.igloader");
      type.put("ivp", "application/vnd.immervision-ivp");
      type.put("ivu", "application/vnd.immervision-ivu");
      type.put("igm", "application/vnd.insors.igm");
      type.put("xpw", "application/vnd.intercon.formnet");
      type.put("xpx", "application/vnd.intercon.formnet");
      type.put("i2g", "application/vnd.intergeo");
      type.put("qbo", "application/vnd.intu.qbo");
      type.put("qfx", "application/vnd.intu.qfx");
      type.put("rcprofile", "application/vnd.ipunplugged.rcprofile");
      type.put("irp", "application/vnd.irepository.package+xml");
      type.put("xpr", "application/vnd.is-xpr");
      type.put("fcs", "application/vnd.isac.fcs");
      type.put("jam", "application/vnd.jam");
      type.put("rms", "application/vnd.jcp.javame.midlet-rms");
      type.put("jisp", "application/vnd.jisp");
      type.put("joda", "application/vnd.joost.joda-archive");
      type.put("ktz", "application/vnd.kahootz");
      type.put("ktr", "application/vnd.kahootz");
      type.put("karbon", "application/vnd.kde.karbon");
      type.put("chrt", "application/vnd.kde.kchart");
      type.put("kfo", "application/vnd.kde.kformula");
      type.put("flw", "application/vnd.kde.kivio");
      type.put("kon", "application/vnd.kde.kontour");
      type.put("kpr", "application/vnd.kde.kpresenter");
      type.put("kpt", "application/vnd.kde.kpresenter");
      type.put("ksp", "application/vnd.kde.kspread");
      type.put("kwd", "application/vnd.kde.kword");
      type.put("kwt", "application/vnd.kde.kword");
      type.put("htke", "application/vnd.kenameaapp");
      type.put("kia", "application/vnd.kidspiration");
      type.put("kne", "application/vnd.kinar");
      type.put("knp", "application/vnd.kinar");
      type.put("skp", "application/vnd.koan");
      type.put("skd", "application/vnd.koan");
      type.put("skt", "application/vnd.koan");
      type.put("skm", "application/vnd.koan");
      type.put("sse", "application/vnd.kodak-descriptor");
      type.put("lasxml", "application/vnd.las.las+xml");
      type.put("lbd", "application/vnd.llamagraphics.life-balance.desktop");
      type.put("lbe", "application/vnd.llamagraphics.life-balance.exchange+xml");
      type.put("123", "application/vnd.lotus-1-2-3");
      type.put("apr", "application/vnd.lotus-approach");
      type.put("pre", "application/vnd.lotus-freelance");
      type.put("nsf", "application/vnd.lotus-notes");
      type.put("org", "application/vnd.lotus-organizer");
      type.put("scm", "application/vnd.lotus-screencam");
      type.put("lwp", "application/vnd.lotus-wordpro");
      type.put("portpkg", "application/vnd.macports.portpkg");
      type.put("mcd", "application/vnd.mcd");
      type.put("mc1", "application/vnd.medcalcdata");
      type.put("cdkey", "application/vnd.mediastation.cdkey");
      type.put("mwf", "application/vnd.mfer");
      type.put("mfm", "application/vnd.mfmp");
      type.put("flo", "application/vnd.micrografx.flo");
      type.put("igx", "application/vnd.micrografx.igx");
      type.put("mif", "application/vnd.mif");
      type.put("daf", "application/vnd.mobius.daf");
      type.put("dis", "application/vnd.mobius.dis");
      type.put("mbk", "application/vnd.mobius.mbk");
      type.put("mqy", "application/vnd.mobius.mqy");
      type.put("msl", "application/vnd.mobius.msl");
      type.put("plc", "application/vnd.mobius.plc");
      type.put("txf", "application/vnd.mobius.txf");
      type.put("mpn", "application/vnd.mophun.application");
      type.put("mpc", "application/vnd.mophun.certificate");
      type.put("xul", "application/vnd.mozilla.xul+xml");
      type.put("cil", "application/vnd.ms-artgalry");
      type.put("cab", "application/vnd.ms-cab-compressed");
      type.put("xls", "application/vnd.ms-excel");
      type.put("xlm", "application/vnd.ms-excel");
      type.put("xla", "application/vnd.ms-excel");
      type.put("xlc", "application/vnd.ms-excel");
      type.put("xlt", "application/vnd.ms-excel");
      type.put("xlw", "application/vnd.ms-excel");
      type.put("xlam", "application/vnd.ms-excel.addin.macroenabled.12");
      type.put("xlsb", "application/vnd.ms-excel.sheet.binary.macroenabled.12");
      type.put("xlsm", "application/vnd.ms-excel.sheet.macroenabled.12");
      type.put("xltm", "application/vnd.ms-excel.template.macroenabled.12");
      type.put("eot", "application/vnd.ms-fontobject");
      type.put("chm", "application/vnd.ms-htmlhelp");
      type.put("ims", "application/vnd.ms-ims");
      type.put("lrm", "application/vnd.ms-lrm");
      type.put("thmx", "application/vnd.ms-officetheme");
      type.put("cat", "application/vnd.ms-pki.seccat");
      type.put("stl", "application/vnd.ms-pki.stl");
      type.put("ppt", "application/vnd.ms-powerpoint");
      type.put("pps", "application/vnd.ms-powerpoint");
      type.put("pot", "application/vnd.ms-powerpoint");
      type.put("ppam", "application/vnd.ms-powerpoint.addin.macroenabled.12");
      type.put("pptm", "application/vnd.ms-powerpoint.presentation.macroenabled.12");
      type.put("sldm", "application/vnd.ms-powerpoint.slide.macroenabled.12");
      type.put("ppsm", "application/vnd.ms-powerpoint.slideshow.macroenabled.12");
      type.put("potm", "application/vnd.ms-powerpoint.template.macroenabled.12");
      type.put("mpp", "application/vnd.ms-project");
      type.put("mpt", "application/vnd.ms-project");
      type.put("docm", "application/vnd.ms-word.document.macroenabled.12");
      type.put("dotm", "application/vnd.ms-word.template.macroenabled.12");
      type.put("wps", "application/vnd.ms-works");
      type.put("wks", "application/vnd.ms-works");
      type.put("wcm", "application/vnd.ms-works");
      type.put("wdb", "application/vnd.ms-works");
      type.put("wpl", "application/vnd.ms-wpl");
      type.put("xps", "application/vnd.ms-xpsdocument");
      type.put("mseq", "application/vnd.mseq");
      type.put("mus", "application/vnd.musician");
      type.put("msty", "application/vnd.muvee.style");
      type.put("taglet", "application/vnd.mynfc");
      type.put("nlu", "application/vnd.neurolanguage.nlu");
      type.put("ntf", "application/vnd.nitf");
      type.put("nitf", "application/vnd.nitf");
      type.put("nnd", "application/vnd.noblenet-directory");
      type.put("nns", "application/vnd.noblenet-sealer");
      type.put("nnw", "application/vnd.noblenet-web");
      type.put("ngdat", "application/vnd.nokia.n-gage.data");
      type.put("rpst", "application/vnd.nokia.radio-preset");
      type.put("rpss", "application/vnd.nokia.radio-presets");
      type.put("edm", "application/vnd.novadigm.edm");
      type.put("edx", "application/vnd.novadigm.edx");
      type.put("ext", "application/vnd.novadigm.ext");
      type.put("odc", "application/vnd.oasis.opendocument.chart");
      type.put("otc", "application/vnd.oasis.opendocument.chart-template");
      type.put("odb", "application/vnd.oasis.opendocument.database");
      type.put("odf", "application/vnd.oasis.opendocument.formula");
      type.put("odft", "application/vnd.oasis.opendocument.formula-template");
      type.put("odg", "application/vnd.oasis.opendocument.graphics");
      type.put("otg", "application/vnd.oasis.opendocument.graphics-template");
      type.put("odi", "application/vnd.oasis.opendocument.image");
      type.put("oti", "application/vnd.oasis.opendocument.image-template");
      type.put("odp", "application/vnd.oasis.opendocument.presentation");
      type.put("otp", "application/vnd.oasis.opendocument.presentation-template");
      type.put("ods", "application/vnd.oasis.opendocument.spreadsheet");
      type.put("ots", "application/vnd.oasis.opendocument.spreadsheet-template");
      type.put("odt", "application/vnd.oasis.opendocument.text");
      type.put("odm", "application/vnd.oasis.opendocument.text-master");
      type.put("ott", "application/vnd.oasis.opendocument.text-template");
      type.put("oth", "application/vnd.oasis.opendocument.text-web");
      type.put("xo", "application/vnd.olpc-sugar");
      type.put("dd2", "application/vnd.oma.dd2+xml");
      type.put("oxt", "application/vnd.openofficeorg.extension");
      type.put("pptx", "application/vnd.openxmlformats-officedocument.presentationml.presentation");
      type.put("sldx", "application/vnd.openxmlformats-officedocument.presentationml.slide");
      type.put("ppsx", "application/vnd.openxmlformats-officedocument.presentationml.slideshow");
      type.put("potx", "application/vnd.openxmlformats-officedocument.presentationml.template");
      type.put("xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
      type.put("xltx", "application/vnd.openxmlformats-officedocument.spreadsheetml.template");
      type.put("docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document");
      type.put("dotx", "application/vnd.openxmlformats-officedocument.wordprocessingml.template");
      type.put("mgp", "application/vnd.osgeo.mapguide.package");
      type.put("dp", "application/vnd.osgi.dp");
      type.put("esa", "application/vnd.osgi.subsystem");
      type.put("pdb", "application/vnd.palm");
      type.put("pqa", "application/vnd.palm");
      type.put("oprc", "application/vnd.palm");
      type.put("paw", "application/vnd.pawaafile");
      type.put("str", "application/vnd.pg.format");
      type.put("ei6", "application/vnd.pg.osasli");
      type.put("efif", "application/vnd.picsel");
      type.put("wg", "application/vnd.pmi.widget");
      type.put("plf", "application/vnd.pocketlearn");
      type.put("pbd", "application/vnd.powerbuilder6");
      type.put("box", "application/vnd.previewsystems.box");
      type.put("mgz", "application/vnd.proteus.magazine");
      type.put("qps", "application/vnd.publishare-delta-tree");
      type.put("ptid", "application/vnd.pvi.ptid1");
      type.put("qxd", "application/vnd.quark.quarkxpress");
      type.put("qxt", "application/vnd.quark.quarkxpress");
      type.put("qwd", "application/vnd.quark.quarkxpress");
      type.put("qwt", "application/vnd.quark.quarkxpress");
      type.put("qxl", "application/vnd.quark.quarkxpress");
      type.put("qxb", "application/vnd.quark.quarkxpress");
      type.put("bed", "application/vnd.realvnc.bed");
      type.put("mxl", "application/vnd.recordare.musicxml");
      type.put("musicxml", "application/vnd.recordare.musicxml+xml");
      type.put("cryptonote", "application/vnd.rig.cryptonote");
      type.put("cod", "application/vnd.rim.cod");
      type.put("rm", "application/vnd.rn-realmedia");
      type.put("rmvb", "application/vnd.rn-realmedia-vbr");
      type.put("link66", "application/vnd.route66.link66+xml");
      type.put("st", "application/vnd.sailingtracker.track");
      type.put("see", "application/vnd.seemail");
      type.put("sema", "application/vnd.sema");
      type.put("semd", "application/vnd.semd");
      type.put("semf", "application/vnd.semf");
      type.put("ifm", "application/vnd.shana.informed.formdata");
      type.put("itp", "application/vnd.shana.informed.formtemplate");
      type.put("iif", "application/vnd.shana.informed.interchange");
      type.put("ipk", "application/vnd.shana.informed.package");
      type.put("twd", "application/vnd.simtech-mindmapper");
      type.put("twds", "application/vnd.simtech-mindmapper");
      type.put("mmf", "application/vnd.smaf");
      type.put("teacher", "application/vnd.smart.teacher");
      type.put("sdkm", "application/vnd.solent.sdkm+xml");
      type.put("sdkd", "application/vnd.solent.sdkm+xml");
      type.put("dxp", "application/vnd.spotfire.dxp");
      type.put("sfs", "application/vnd.spotfire.sfs");
      type.put("sdc", "application/vnd.stardivision.calc");
      type.put("sda", "application/vnd.stardivision.draw");
      type.put("sdd", "application/vnd.stardivision.impress");
      type.put("smf", "application/vnd.stardivision.math");
      type.put("sdw", "application/vnd.stardivision.writer");
      type.put("vor", "application/vnd.stardivision.writer");
      type.put("sgl", "application/vnd.stardivision.writer-global");
      type.put("smzip", "application/vnd.stepmania.package");
      type.put("sm", "application/vnd.stepmania.stepchart");
      type.put("sxc", "application/vnd.sun.xml.calc");
      type.put("stc", "application/vnd.sun.xml.calc.template");
      type.put("sxd", "application/vnd.sun.xml.draw");
      type.put("std", "application/vnd.sun.xml.draw.template");
      type.put("sxi", "application/vnd.sun.xml.impress");
      type.put("sti", "application/vnd.sun.xml.impress.template");
      type.put("sxm", "application/vnd.sun.xml.math");
      type.put("sxw", "application/vnd.sun.xml.writer");
      type.put("sxg", "application/vnd.sun.xml.writer.global");
      type.put("stw", "application/vnd.sun.xml.writer.template");
      type.put("sus", "application/vnd.sus-calendar");
      type.put("susp", "application/vnd.sus-calendar");
      type.put("svd", "application/vnd.svd");
      type.put("sis", "application/vnd.symbian.install");
      type.put("sisx", "application/vnd.symbian.install");
      type.put("xsm", "application/vnd.syncml+xml");
      type.put("bdm", "application/vnd.syncml.dm+wbxml");
      type.put("xdm", "application/vnd.syncml.dm+xml");
      type.put("tao", "application/vnd.tao.intent-module-archive");
      type.put("pcap", "application/vnd.tcpdump.pcap");
      type.put("cap", "application/vnd.tcpdump.pcap");
      type.put("dmp", "application/vnd.tcpdump.pcap");
      type.put("tmo", "application/vnd.tmobile-livetv");
      type.put("tpt", "application/vnd.trid.tpt");
      type.put("mxs", "application/vnd.triscape.mxs");
      type.put("tra", "application/vnd.trueapp");
      type.put("ufd", "application/vnd.ufdl");
      type.put("ufdl", "application/vnd.ufdl");
      type.put("utz", "application/vnd.uiq.theme");
      type.put("umj", "application/vnd.umajin");
      type.put("unityweb", "application/vnd.unity");
      type.put("uoml", "application/vnd.uoml+xml");
      type.put("vcx", "application/vnd.vcx");
      type.put("vsd", "application/vnd.visio");
      type.put("vst", "application/vnd.visio");
      type.put("vss", "application/vnd.visio");
      type.put("vsw", "application/vnd.visio");
      type.put("vis", "application/vnd.visionary");
      type.put("vsf", "application/vnd.vsf");
      type.put("wbxml", "application/vnd.wap.wbxml");
      type.put("wmlc", "application/vnd.wap.wmlc");
      type.put("wmlsc", "application/vnd.wap.wmlscriptc");
      type.put("wtb", "application/vnd.webturbo");
      type.put("nbp", "application/vnd.wolfram.player");
      type.put("wpd", "application/vnd.wordperfect");
      type.put("wqd", "application/vnd.wqd");
      type.put("stf", "application/vnd.wt.stf");
      type.put("xar", "application/vnd.xara");
      type.put("xfdl", "application/vnd.xfdl");
      type.put("hvd", "application/vnd.yamaha.hv-dic");
      type.put("hvs", "application/vnd.yamaha.hv-script");
      type.put("hvp", "application/vnd.yamaha.hv-voice");
      type.put("osf", "application/vnd.yamaha.openscoreformat");
      type.put("osfpvg", "application/vnd.yamaha.openscoreformat.osfpvg+xml");
      type.put("saf", "application/vnd.yamaha.smaf-audio");
      type.put("spf", "application/vnd.yamaha.smaf-phrase");
      type.put("cmp", "application/vnd.yellowriver-custom-menu");
      type.put("zir", "application/vnd.zul");
      type.put("zirz", "application/vnd.zul");
      type.put("zaz", "application/vnd.zzazz.deck+xml");
      type.put("vxml", "application/voicexml+xml");
      type.put("wgt", "application/widget");
      type.put("hlp", "application/winhlp");
      type.put("wsdl", "application/wsdl+xml");
      type.put("wspolicy", "application/wspolicy+xml");
      type.put("7z", "application/x-7z-compressed");
      type.put("abw", "application/x-abiword");
      type.put("ace", "application/x-ace-compressed");
      type.put("dmg", "application/x-apple-diskimage");
      type.put("aab", "application/x-authorware-bin");
      type.put("x32", "application/x-authorware-bin");
      type.put("u32", "application/x-authorware-bin");
      type.put("vox", "application/x-authorware-bin");
      type.put("aam", "application/x-authorware-map");
      type.put("aas", "application/x-authorware-seg");
      type.put("bcpio", "application/x-bcpio");
      type.put("torrent", "application/x-bittorrent");
      type.put("blb", "application/x-blorb");
      type.put("blorb", "application/x-blorb");
      type.put("bz", "application/x-bzip");
      type.put("bz2", "application/x-bzip2");
      type.put("boz", "application/x-bzip2");
      type.put("cbr", "application/x-cbr");
      type.put("cba", "application/x-cbr");
      type.put("cbt", "application/x-cbr");
      type.put("cbz", "application/x-cbr");
      type.put("cb7", "application/x-cbr");
      type.put("vcd", "application/x-cdlink");
      type.put("cfs", "application/x-cfs-compressed");
      type.put("chat", "application/x-chat");
      type.put("pgn", "application/x-chess-pgn");
      type.put("crx", "application/x-chrome-extension");
      type.put("nsc", "application/x-conference");
      type.put("cpio", "application/x-cpio");
      type.put("csh", "application/x-csh");
      type.put("deb", "application/x-debian-package");
      type.put("udeb", "application/x-debian-package");
      type.put("dgc", "application/x-dgc-compressed");
      type.put("dir", "application/x-director");
      type.put("dcr", "application/x-director");
      type.put("dxr", "application/x-director");
      type.put("cst", "application/x-director");
      type.put("cct", "application/x-director");
      type.put("cxt", "application/x-director");
      type.put("w3d", "application/x-director");
      type.put("fgd", "application/x-director");
      type.put("swa", "application/x-director");
      type.put("wad", "application/x-doom");
      type.put("ncx", "application/x-dtbncx+xml");
      type.put("dtb", "application/x-dtbook+xml");
      type.put("res", "application/x-dtbresource+xml");
      type.put("dvi", "application/x-dvi");
      type.put("evy", "application/x-envoy");
      type.put("eva", "application/x-eva");
      type.put("bdf", "application/x-font-bdf");
      type.put("gsf", "application/x-font-ghostscript");
      type.put("psf", "application/x-font-linux-psf");
      type.put("otf", "application/x-font-otf");
      type.put("pcf", "application/x-font-pcf");
      type.put("snf", "application/x-font-snf");
      type.put("ttf", "application/x-font-ttf");
      type.put("ttc", "application/x-font-ttf");
      type.put("pfa", "application/x-font-type1");
      type.put("pfb", "application/x-font-type1");
      type.put("pfm", "application/x-font-type1");
      type.put("afm", "application/x-font-type1");
      type.put("arc", "application/x-freearc");
      type.put("spl", "application/x-futuresplash");
      type.put("gca", "application/x-gca-compressed");
      type.put("ulx", "application/x-glulx");
      type.put("gnumeric", "application/x-gnumeric");
      type.put("gramps", "application/x-gramps-xml");
      type.put("gtar", "application/x-gtar");
      type.put("hdf", "application/x-hdf");
      type.put("install", "application/x-install-instructions");
      type.put("iso", "application/x-iso9660-image");
      type.put("jnlp", "application/x-java-jnlp-file");
      type.put("latex", "application/x-latex");
      type.put("luac", "application/x-lua-bytecode");
      type.put("lzh", "application/x-lzh-compressed");
      type.put("lha", "application/x-lzh-compressed");
      type.put("mie", "application/x-mie");
      type.put("prc", "application/x-mobipocket-ebook");
      type.put("mobi", "application/x-mobipocket-ebook");
      type.put("application", "application/x-ms-application");
      type.put("lnk", "application/x-ms-shortcut");
      type.put("wmd", "application/x-ms-wmd");
      type.put("wmz", "application/x-ms-wmz");
      type.put("xbap", "application/x-ms-xbap");
      type.put("mdb", "application/x-msaccess");
      type.put("obd", "application/x-msbinder");
      type.put("crd", "application/x-mscardfile");
      type.put("clp", "application/x-msclip");
      type.put("exe", "application/x-msdownload");
      type.put("dll", "application/x-msdownload");
      type.put("com", "application/x-msdownload");
      type.put("bat", "application/x-msdownload");
      type.put("msi", "application/x-msdownload");
      type.put("mvb", "application/x-msmediaview");
      type.put("m13", "application/x-msmediaview");
      type.put("m14", "application/x-msmediaview");
      type.put("wmf", "application/x-msmetafile");
      type.put("wmz", "application/x-msmetafile");
      type.put("emf", "application/x-msmetafile");
      type.put("emz", "application/x-msmetafile");
      type.put("mny", "application/x-msmoney");
      type.put("pub", "application/x-mspublisher");
      type.put("scd", "application/x-msschedule");
      type.put("trm", "application/x-msterminal");
      type.put("wri", "application/x-mswrite");
      type.put("nc", "application/x-netcdf");
      type.put("cdf", "application/x-netcdf");
      type.put("nzb", "application/x-nzb");
      type.put("p12", "application/x-pkcs12");
      type.put("pfx", "application/x-pkcs12");
      type.put("p7b", "application/x-pkcs7-certificates");
      type.put("spc", "application/x-pkcs7-certificates");
      type.put("p7r", "application/x-pkcs7-certreqresp");
      type.put("rar", "application/x-rar-compressed");
      type.put("ris", "application/x-research-info-systems");
      type.put("sh", "application/x-sh");
      type.put("shar", "application/x-shar");
      type.put("swf", "application/x-shockwave-flash");
      type.put("xap", "application/x-silverlight-app");
      type.put("sql", "application/x-sql");
      type.put("sit", "application/x-stuffit");
      type.put("sitx", "application/x-stuffitx");
      type.put("srt", "application/x-subrip");
      type.put("sv4cpio", "application/x-sv4cpio");
      type.put("sv4crc", "application/x-sv4crc");
      type.put("t3", "application/x-t3vm-image");
      type.put("gam", "application/x-tads");
      type.put("tar", "application/x-tar");
      type.put("tcl", "application/x-tcl");
      type.put("tex", "application/x-tex");
      type.put("tfm", "application/x-tex-tfm");
      type.put("texinfo", "application/x-texinfo");
      type.put("texi", "application/x-texinfo");
      type.put("obj", "application/x-tgif");
      type.put("ustar", "application/x-ustar");
      type.put("src", "application/x-wais-source");
      type.put("webapp", "application/x-web-app-manifest+json");
      type.put("der", "application/x-x509-ca-cert");
      type.put("crt", "application/x-x509-ca-cert");
      type.put("fig", "application/x-xfig");
      type.put("xlf", "application/x-xliff+xml");
      type.put("xpi", "application/x-xpinstall");
      type.put("xz", "application/x-xz");
      type.put("z1", "application/x-zmachine");
      type.put("z2", "application/x-zmachine");
      type.put("z3", "application/x-zmachine");
      type.put("z4", "application/x-zmachine");
      type.put("z5", "application/x-zmachine");
      type.put("z6", "application/x-zmachine");
      type.put("z7", "application/x-zmachine");
      type.put("z8", "application/x-zmachine");
      type.put("xaml", "application/xaml+xml");
      type.put("xdf", "application/xcap-diff+xml");
      type.put("xenc", "application/xenc+xml");
      type.put("xhtml", "application/xhtml+xml");
      type.put("xht", "application/xhtml+xml");
      type.put("xml", "application/xml");
      type.put("xsl", "application/xml");
      type.put("xsd", "application/xml");
      type.put("dtd", "application/xml-dtd");
      type.put("xop", "application/xop+xml");
      type.put("xpl", "application/xproc+xml");
      type.put("xslt", "application/xslt+xml");
      type.put("xspf", "application/xspf+xml");
      type.put("mxml", "application/xv+xml");
      type.put("xhvml", "application/xv+xml");
      type.put("xvml", "application/xv+xml");
      type.put("xvm", "application/xv+xml");
      type.put("yang", "application/yang");
      type.put("yin", "application/yin+xml");
      type.put("zip", "application/zip");
      type.put("adp", "audio/adpcm");
      type.put("au", "audio/basic");
      type.put("snd", "audio/basic");
      type.put("mid", "audio/midi");
      type.put("midi", "audio/midi");
      type.put("kar", "audio/midi");
      type.put("rmi", "audio/midi");
      type.put("mp4a", "audio/mp4");
      type.put("m4a", "audio/mp4");
      type.put("mpga", "audio/mpeg");
      type.put("mp2", "audio/mpeg");
      type.put("mp2a", "audio/mpeg");
      type.put("mp3", "audio/mpeg");
      type.put("m2a", "audio/mpeg");
      type.put("m3a", "audio/mpeg");
      type.put("oga", "audio/ogg");
      type.put("ogg", "audio/ogg");
      type.put("spx", "audio/ogg");
      type.put("s3m", "audio/s3m");
      type.put("sil", "audio/silk");
      type.put("uva", "audio/vnd.dece.audio");
      type.put("uvva", "audio/vnd.dece.audio");
      type.put("eol", "audio/vnd.digital-winds");
      type.put("dra", "audio/vnd.dra");
      type.put("dts", "audio/vnd.dts");
      type.put("dtshd", "audio/vnd.dts.hd");
      type.put("lvp", "audio/vnd.lucent.voice");
      type.put("pya", "audio/vnd.ms-playready.media.pya");
      type.put("ecelp4800", "audio/vnd.nuera.ecelp4800");
      type.put("ecelp7470", "audio/vnd.nuera.ecelp7470");
      type.put("ecelp9600", "audio/vnd.nuera.ecelp9600");
      type.put("rip", "audio/vnd.rip");
      type.put("weba", "audio/webm");
      type.put("aac", "audio/x-aac");
      type.put("aif", "audio/x-aiff");
      type.put("aiff", "audio/x-aiff");
      type.put("aifc", "audio/x-aiff");
      type.put("caf", "audio/x-caf");
      type.put("flac", "audio/x-flac");
      type.put("mka", "audio/x-matroska");
      type.put("m3u", "audio/x-mpegurl");
      type.put("wax", "audio/x-ms-wax");
      type.put("wma", "audio/x-ms-wma");
      type.put("ram", "audio/x-pn-realaudio");
      type.put("ra", "audio/x-pn-realaudio");
      type.put("rmp", "audio/x-pn-realaudio-plugin");
      type.put("wav", "audio/x-wav");
      type.put("xm", "audio/xm");
      type.put("cdx", "chemical/x-cdx");
      type.put("cif", "chemical/x-cif");
      type.put("cmdf", "chemical/x-cmdf");
      type.put("cml", "chemical/x-cml");
      type.put("csml", "chemical/x-csml");
      type.put("xyz", "chemical/x-xyz");
      type.put("otf", "font/opentype");
      type.put("bmp", "image/bmp");
      type.put("cgm", "image/cgm");
      type.put("g3", "image/g3fax");
      type.put("gif", "image/gif");
      type.put("ief", "image/ief");
      type.put("jpeg", "image/jpeg");
      type.put("jpg", "image/jpeg");
      type.put("jpe", "image/jpeg");
      type.put("ktx", "image/ktx");
      type.put("png", "image/png");
      type.put("btif", "image/prs.btif");
      type.put("sgi", "image/sgi");
      type.put("svg", "image/svg+xml");
      type.put("svgz", "image/svg+xml");
      type.put("tiff", "image/tiff");
      type.put("tif", "image/tiff");
      type.put("psd", "image/vnd.adobe.photoshop");
      type.put("uvi", "image/vnd.dece.graphic");
      type.put("uvvi", "image/vnd.dece.graphic");
      type.put("uvg", "image/vnd.dece.graphic");
      type.put("uvvg", "image/vnd.dece.graphic");
      type.put("djvu", "image/vnd.djvu");
      type.put("djv", "image/vnd.djvu");
      type.put("sub", "image/vnd.dvb.subtitle");
      type.put("dwg", "image/vnd.dwg");
      type.put("dxf", "image/vnd.dxf");
      type.put("fbs", "image/vnd.fastbidsheet");
      type.put("fpx", "image/vnd.fpx");
      type.put("fst", "image/vnd.fst");
      type.put("mmr", "image/vnd.fujixerox.edmics-mmr");
      type.put("rlc", "image/vnd.fujixerox.edmics-rlc");
      type.put("mdi", "image/vnd.ms-modi");
      type.put("wdp", "image/vnd.ms-photo");
      type.put("npx", "image/vnd.net-fpx");
      type.put("wbmp", "image/vnd.wap.wbmp");
      type.put("xif", "image/vnd.xiff");
      type.put("webp", "image/webp");
      type.put("3ds", "image/x-3ds");
      type.put("ras", "image/x-cmu-raster");
      type.put("cmx", "image/x-cmx");
      type.put("fh", "image/x-freehand");
      type.put("fhc", "image/x-freehand");
      type.put("fh4", "image/x-freehand");
      type.put("fh5", "image/x-freehand");
      type.put("fh7", "image/x-freehand");
      type.put("ico", "image/x-icon");
      type.put("sid", "image/x-mrsid-image");
      type.put("pcx", "image/x-pcx");
      type.put("pic", "image/x-pict");
      type.put("pct", "image/x-pict");
      type.put("pnm", "image/x-portable-anymap");
      type.put("pbm", "image/x-portable-bitmap");
      type.put("pgm", "image/x-portable-graymap");
      type.put("ppm", "image/x-portable-pixmap");
      type.put("rgb", "image/x-rgb");
      type.put("tga", "image/x-tga");
      type.put("xbm", "image/x-xbitmap");
      type.put("xpm", "image/x-xpixmap");
      type.put("xwd", "image/x-xwindowdump");
      type.put("eml", "message/rfc822");
      type.put("mime", "message/rfc822");
      type.put("igs", "model/iges");
      type.put("iges", "model/iges");
      type.put("msh", "model/mesh");
      type.put("mesh", "model/mesh");
      type.put("silo", "model/mesh");
      type.put("dae", "model/vnd.collada+xml");
      type.put("dwf", "model/vnd.dwf");
      type.put("gdl", "model/vnd.gdl");
      type.put("gtw", "model/vnd.gtw");
      type.put("mts", "model/vnd.mts");
      type.put("vtu", "model/vnd.vtu");
      type.put("wrl", "model/vrml");
      type.put("vrml", "model/vrml");
      type.put("x3db", "model/x3d+binary");
      type.put("x3dbz", "model/x3d+binary");
      type.put("x3dv", "model/x3d+vrml");
      type.put("x3dvz", "model/x3d+vrml");
      type.put("x3d", "model/x3d+xml");
      type.put("x3dz", "model/x3d+xml");
      type.put("appcache", "text/cache-manifest");
      type.put("manifest", "text/cache-manifest");
      type.put("ics", "text/calendar");
      type.put("ifb", "text/calendar");
      type.put("coffee", "text/coffeescript");
      type.put("css", "text/css");
      type.put("csv", "text/csv");
      type.put("hjson", "text/hjson");
      type.put("html", "text/html");
      type.put("htm", "text/html");
      type.put("jade", "text/jade");
      type.put("jsx", "text/jsx");
      type.put("less", "text/less");
      type.put("n3", "text/n3");
      type.put("txt", "text/plain");
      type.put("text", "text/plain");
      type.put("conf", "text/plain");
      type.put("def", "text/plain");
      type.put("list", "text/plain");
      type.put("log", "text/plain");
      type.put("in", "text/plain");
      type.put("ini", "text/plain");
      type.put("dsc", "text/prs.lines.tag");
      type.put("rtx", "text/richtext");
      type.put("sgml", "text/sgml");
      type.put("sgm", "text/sgml");
      type.put("stylus", "text/stylus");
      type.put("styl", "text/stylus");
      type.put("tsv", "text/tab-separated-values");
      type.put("t", "text/troff");
      type.put("tr", "text/troff");
      type.put("roff", "text/troff");
      type.put("man", "text/troff");
      type.put("me", "text/troff");
      type.put("ms", "text/troff");
      type.put("ttl", "text/turtle");
      type.put("uri", "text/uri-list");
      type.put("uris", "text/uri-list");
      type.put("urls", "text/uri-list");
      type.put("vcard", "text/vcard");
      type.put("curl", "text/vnd.curl");
      type.put("dcurl", "text/vnd.curl.dcurl");
      type.put("mcurl", "text/vnd.curl.mcurl");
      type.put("scurl", "text/vnd.curl.scurl");
      type.put("sub", "text/vnd.dvb.subtitle");
      type.put("fly", "text/vnd.fly");
      type.put("flx", "text/vnd.fmi.flexstor");
      type.put("gv", "text/vnd.graphviz");
      type.put("3dml", "text/vnd.in3d.3dml");
      type.put("spot", "text/vnd.in3d.spot");
      type.put("jad", "text/vnd.sun.j2me.app-descriptor");
      type.put("wml", "text/vnd.wap.wml");
      type.put("wmls", "text/vnd.wap.wmlscript");
      type.put("vtt", "text/vtt");
      type.put("s", "text/x-asm");
      type.put("asm", "text/x-asm");
      type.put("c", "text/x-c");
      type.put("cc", "text/x-c");
      type.put("cxx", "text/x-c");
      type.put("cpp", "text/x-c");
      type.put("h", "text/x-c");
      type.put("hh", "text/x-c");
      type.put("dic", "text/x-c");
      type.put("htc", "text/x-component");
      type.put("f", "text/x-fortran");
      type.put("for", "text/x-fortran");
      type.put("f77", "text/x-fortran");
      type.put("f90", "text/x-fortran");
      type.put("hbs", "text/x-handlebars-template");
      type.put("java", "text/x-java-source");
      type.put("lua", "text/x-lua");
      type.put("markdown", "text/x-markdown");
      type.put("md", "text/x-markdown");
      type.put("mkd", "text/x-markdown");
      type.put("nfo", "text/x-nfo");
      type.put("opml", "text/x-opml");
      type.put("p", "text/x-pascal");
      type.put("pas", "text/x-pascal");
      type.put("sass", "text/x-sass");
      type.put("scss", "text/x-scss");
      type.put("etx", "text/x-setext");
      type.put("sfv", "text/x-sfv");
      type.put("uu", "text/x-uuencode");
      type.put("vcs", "text/x-vcalendar");
      type.put("vcf", "text/x-vcard");
      type.put("yaml", "text/yaml");
      type.put("yml", "text/yaml");
      type.put("3gp", "video/3gpp");
      type.put("3g2", "video/3gpp2");
      type.put("h261", "video/h261");
      type.put("h263", "video/h263");
      type.put("h264", "video/h264");
      type.put("jpgv", "video/jpeg");
      type.put("jpm", "video/jpm");
      type.put("jpgm", "video/jpm");
      type.put("mj2", "video/mj2");
      type.put("mjp2", "video/mj2");
      type.put("ts", "video/mp2t");
      type.put("mp4", "video/mp4");
      type.put("mp4v", "video/mp4");
      type.put("mpg4", "video/mp4");
      type.put("mpeg", "video/mpeg");
      type.put("mpg", "video/mpeg");
      type.put("mpe", "video/mpeg");
      type.put("m1v", "video/mpeg");
      type.put("m2v", "video/mpeg");
      type.put("ogv", "video/ogg");
      type.put("qt", "video/quicktime");
      type.put("mov", "video/quicktime");
      type.put("uvh", "video/vnd.dece.hd");
      type.put("uvvh", "video/vnd.dece.hd");
      type.put("uvm", "video/vnd.dece.mobile");
      type.put("uvvm", "video/vnd.dece.mobile");
      type.put("uvp", "video/vnd.dece.pd");
      type.put("uvvp", "video/vnd.dece.pd");
      type.put("uvs", "video/vnd.dece.sd");
      type.put("uvvs", "video/vnd.dece.sd");
      type.put("uvv", "video/vnd.dece.video");
      type.put("uvvv", "video/vnd.dece.video");
      type.put("dvb", "video/vnd.dvb.file");
      type.put("fvt", "video/vnd.fvt");
      type.put("mxu", "video/vnd.mpegurl");
      type.put("m4u", "video/vnd.mpegurl");
      type.put("pyv", "video/vnd.ms-playready.media.pyv");
      type.put("uvu", "video/vnd.uvvu.mp4");
      type.put("uvvu", "video/vnd.uvvu.mp4");
      type.put("viv", "video/vnd.vivo");
      type.put("webm", "video/webm");
      type.put("f4v", "video/x-f4v");
      type.put("fli", "video/x-fli");
      type.put("flv", "video/x-flv");
      type.put("m4v", "video/x-m4v");
      type.put("mkv", "video/x-matroska");
      type.put("mk3d", "video/x-matroska");
      type.put("mks", "video/x-matroska");
      type.put("mng", "video/x-mng");
      type.put("asf", "video/x-ms-asf");
      type.put("asx", "video/x-ms-asf");
      type.put("vob", "video/x-ms-vob");
      type.put("wm", "video/x-ms-wm");
      type.put("wmv", "video/x-ms-wmv");
      type.put("wmx", "video/x-ms-wmx");
      type.put("wvx", "video/x-ms-wvx");
      type.put("avi", "video/x-msvideo");
      type.put("movie", "video/x-sgi-movie");
      type.put("smv", "video/x-smv");
      type.put("ice", "x-conference/x-cooltalk");
   }

   public static String getMimeType(String fileExt) {
      return type.get(fileExt);
   }
}

DPI/pt/px 单位的含义 DPI(Dots Per Inch) 每英寸像素数。

DPI/pt/px 单位的含义

DPI(Dots Per Inch)

每英寸像素数。Windows 系统默认是 96dpi,Apple 系统默认是 72dpi。

pt (point,磅)

是一个物理长度单位,指的是 72 分之一英寸。

px (pixel,像素)

一个虚拟长度单位,是计算机系统的数字化图像长度单位,如果 px 要换算成物理长度,需要指定精度 DPI,在扫描打印时一般都有 DPI 可选。常见浏览器的默认字体大小都是 16px。

由于屏幕大小的差异性,相同大小的字体在不同屏幕下显示的效果差异比较大。那么动态的放大 / 缩小字体就变得比较重要。显然针对每一处的字体设置都去做兼容是复杂的,于是就有了后面的 em 和 rem。

em (相对长度)

相对于当前对象内文本的字体尺寸。如当前对行内文本的字体尺寸未被人为设置,则相对于浏览器的默认字体尺寸。

由于浏览器的默认字体大小是 16px,所以未经调整默认字体大小的浏览器都符合: 1em = 16px。

em 会继承父级元素的字体大小。由此,只需要改变父元素的字体大小,就可以同步放大或缩小子元素的字体。

但是也因此需要注意几点:

1、body 选择器中声明 Font-size=62.5% (10 ÷ 16 × 100% = 62.5%);

2、将你的原来的 px 数值除以 10,然后换上 em 作为单位;

3、重新计算那些被放大的字体的 em 数值。避免字体大小的重复声明。

rem (font size of the root element)

由于 em 存在对父元素继承的问题,当改变字体大小时涉及的继承关系就变得复杂起来。

rem 是相对于根元素 字体尺寸的大小。如 文本大小设为 font-size: 10px,则 1rem = 10px。使用 rem 设置字体则简单了很多。

px 与 pt 的换算

px = pt * DPI / 72

像素与毫米的转换

象素数 / DPI = 英寸数
英寸数 * 25.4 = 毫米数

一英寸等于 25.4mm。那么毫米换算成像素的公式为:

水平方向的换算: x * px /25.4
垂直方向的换算: y * py /25.4
像素换算为毫米: x * 25.4 / px

pt/px/em/percent 换算参考

以 Windows 下的 96dpi 作参考,则有:pt = px_72/96 = px_3/4。
再考虑浏览器的默认字体大小是 16px,我们可以得到如下的换算参考:

html {font-size: 62.5%;  /*10 ÷ 16 × 100% = 62.5%*/}
body {font-size: 1.4rem; /*1.4 × 10px = 14px */}
h1 { font-size: 2.4rem;  /*2.4 × 10px = 24px*/}

一个经典的简单示例:

html {font-size: 62.5%;  /*10 ÷ 16 × 100% = 62.5%*/}
body {font-size: 1.4rem; /*1.4 × 10px = 14px */}
h1 { font-size: 2.4rem;  /*2.4 × 10px = 24px*/}

原文:https://lzw.me/a/pt-px-em-rem.html

原文地址 https://www.jianshu.com/p/86a7f506d1d2

ZooKeeper 默认开启在 2181 端口,在未进行任何访问控制情况下,攻击者可通过执行 envi 命令获得系统大量的敏感信息,包括系统名称、Java 环境。

0x00 ZooKeeper 安装:

Zookeeper 的默认开放端口是 2181

wget https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/zookeeper-3.4.10/zookeeper-3.4.10.tar.gz

tar -zxvf zookeepre-3.4.10.tar.gz
cd zookeeper-3.4.10/
cd conf/
vi zoo.cfg
### 配置单机模式
tickTime=2000
dataDir=/tmp/zookeeper/data
dataLogDir=/tmp/zookeeper/logs
clientPort=2181

bin/zkServer.sh start   //启动
### 启动client连接server
bin/zkCli.sh -server localhost:2181

0x01 漏洞验证:

执行以下命令即可远程获取该服务器的环境:
echo envi|nc 192.168.15.74 2181

直接连接:
./zkCli.sh -server ip:port

其他攻击获取信息

stat:列出关于性能和连接的客户端的统计信息。
echo stat |ncat 127.0.0.1 2181

ruok:测试服务器是否运行在非错误状态。
echo ruok |ncat 127.0.0.1 2181

reqs:列出未完成的请求。
echo reqs |ncat 127.0.0.1 2181

envi:打印有关服务环境的详细信息。
echo envi |ncat 127.0.0.1 2181

dump:列出未完成的会话和临时节点。
echo dump |ncat 127.0.0.1 2181

0x02 漏洞修复

禁止把 Zookeeper 直接暴露在公网
添加访问控制,根据情况选择对应方式(认证用户,用户名密码)

zookeeper 有三个端口(可以修改),默认端口作用:

1、2181:对 cline 端提供服务
2、3888:选举 leader 使用
3、2888:集群内机器通讯使用(Leader 监听此端口)

修复办法 1 绑定指定 IP 访问 (推荐):

1、登陆 zookeeper

./zkCli.sh -server <IP>:<port>

2、查看当前权限:

getAcl /

3、添加可访问 IP

setAcl / ip:192.168.1.xx:cdrwa,ip:192.168.1.xx:cdrwa

4、查看是否正常添加

getAcl /

未授权也可以连接,但是查看节点时会报错 "KeeperErrorCode = NoAuth for /",localhost 都不行,必须填可访问 IP,才能访问。

[zk: localhost:2181(CONNECTED) 0] ls /
KeeperErrorCode = NoAuth for /
[zk: localhost:2181(CONNECTED) 1]

回退办法:
使用之前设置的 IP 进行访问:

./zkCli.sh -server <IP>:<port>

设置为所有人可访问:

setAcl / world:anyone:cdrwa

修复办法 2 添加防火墙访问控制:

配置防火墙策略,只允许指定 IP 访问 2181 端口。
Linux 6:

iptables -I INPUT -p tcp --dport 2181 -j DROP
iptables -I INPUT -s 172.16.65.xx -p tcp --dport 2181 -j ACCEPT
iptables -I INPUT -s 172.16.65.xx -p tcp --dport 2181 -j ACCEPT
iptables -I INPUT -s 172.16.65.xx -p tcp --dport 2181 -j ACCEPT
service iptables save
service iptables restart
iptables -L

Linux 7:

firewall-cmd --zone=public --remove-port=2181/tcp --permanent
firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.0.2.181" port protocol="tcp" port="2181" accept"
firewall-cmd --reload
firewall-cmd --list-all

修复办法 3 设置身份验证(需要改程序):

为 ZooKeeper 配置相应的访问权限。

1)增加一个认证用户
addauth digest 用户名: 密码明文

addauth digest user1:password1

2)设置权限
setAcl /path auth: 用户名: 密码明文: 权限
setAcl /path digest: 用户名: 密码密文: 权限

setAcl /test auth:user1:password1:cdrwa

3)查看 Acl 设置

getAcl /path

0x03 参考链接:

ZooKeeper 未授权访问漏洞
Linux 系统安全加固 - ZooKeeper 未授权访问漏洞处理
ZooKeeper 未授权访问

原文地址 https://www.cnblogs.com/idea360/p/12391416.html

概述

接上一篇 Docker 实战之 MySQL 主从复制, 这里是 Docker 实战系列的第二篇,主要进行 Redis-Cluster 集群环境的快速搭建。Redis 作为基于键值对的 NoSQL 数据库,具有高性能、丰富的数据结构、持久化、高可用、分布式等特性,同时 Redis 本身非常稳定,已经得到业界的广泛认可和使用。

在 Redis 中,集群的解决方案有三种

  1. 主从复制
  2. 哨兵机制
  3. Cluster

Redis Cluster 是 Redis 的分布式解决方案,在 3.0 版本正式推出。

阅读全文 »