⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 exactutf8inputstreamreader.java

📁 非常棒的java数据库
💻 JAVA
字号:
/*
 * Copyright 2004-2008 H2 Group. Licensed under the H2 License, Version 1.0
 * (http://h2database.com/html/license.html).
 * Initial Developer: H2 Group
 */
package org.h2.util;

import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;

/**
 * The regular InputStreamReader may read some more bytes than required.
 * If this is a problem, use this class.
 */
public class ExactUTF8InputStreamReader extends Reader {
    
    private InputStream in;
    
    public ExactUTF8InputStreamReader(InputStream in) {
        this.in = in;
    }

    public void close() throws IOException {
    }

    public int read(char[] chars, int off, int len) throws IOException {
        for (int i = 0; i < len; i++, off++) {
            int x = in.read();
            if (x < 0) {
                return i == 0 ? -1 : i;
            }
            x = x & 0xff;
            if (x < 0x80) {
                chars[off] = (char) x;
            } else if (x >= 0xe0) {
                chars[off] = (char) (((x & 0xf) << 12) + ((in.read() & 0x3f) << 6) + (in.read() & 0x3f));
            } else {
                chars[off] = (char) (((x & 0x1f) << 6) + (in.read() & 0x3f));
            }
        }
        return len;
    }

}

⌨️ 快捷键说明

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