欢迎访问玛尊真服务平台,本站唯一网址:www.isodyi.com,未经明确书面许可,任何人不得擅自使用“玛尊真”等商标。
玛尊真ISO认证服务公司

RedisOutputStream.java的源码是什么

本篇内容介绍了“redisOutputStream.java的源码是什么”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

成都创新互联公司是一家以网站建设、网页设计、品牌设计、软件运维、seo优化排名、小程序App开发等移动开发为一体互联网公司。已累计为成都木托盘等众行业中小客户提供优质的互联网建站和软件开发服务。

package redis.clients.util;

import java.io.*;
import java.nio.charset.Charset;

/**
 * The class implements a buffered output stream without synchronization
 * There are also special operations like in-place string encoding.
 * This stream fully ignore mark/reset and should not be used outside Jedis
 */
public final class RedisOutputStream extends FilterOutputStream {
    protected final byte buf[];//缓冲区

    protected int count;//计数器
    public static final Charset CHARSET = Charset.forName("UTF-8");//编码方式

    public RedisOutputStream(OutputStream out) {//初始化
        this(out, 8192);
    }

    public RedisOutputStream(OutputStream out, int size) {//初始化
        super(out);
        if (size <= 0) {
            throw new IllegalArgumentException("Buffer size <= 0");
        }
        buf = new byte[size];
    }

    private void flushBuffer() throws IOException {//将所有字符都写出去
        if (count > 0) {
            out.write(buf, 0, count);
            count = 0;
        }
    }

    public void write(int b) throws IOException {//写到缓冲区,满时执行缓冲区清除
        buf[count++] = (byte) b;
        if (count == buf.length) {
            flushBuffer();
        }
    }

    public void write(byte b[], int off, int len) throws IOException {//写到缓冲区
        if (len >= buf.length) {
            flushBuffer();
            out.write(b, off, len);
        } else {
            if (len >= buf.length - count) {
                flushBuffer();
            }

            System.arraycopy(b, off, buf, count, len);
            count += len;
        }
    }

    public void writeAsciiCrLf(String in) throws IOException {//写到缓冲区
        final int size = in.length();

        for (int i = 0; i != size; ++i) {
            buf[count++] = (byte) in.charAt(i);
            if (count == buf.length) {
                flushBuffer();
            }
        }

        writeCrLf();
    }

    public static boolean isSurrogate(char ch) {//XXX
        return ch >= Character.MIN_SURROGATE && ch <= Character.MAX_SURROGATE;
    }

    public static int utf8Length (String str) {//utf8编码的长度
        int strLen = str.length(), utfLen = 0;
        for(int i = 0; i != strLen; ++i) {
            char c = str.charAt(i);
            if (c < 0x80) {
                utfLen++;
            } else if (c < 0x800) {
                utfLen += 2;
            } else if (isSurrogate(c)) {
                i++;
                utfLen += 4;
            } else {
                utfLen += 3;
            }
        }
        return utfLen;
    }

    public void writeCrLf() throws IOException {//写到缓冲区里
        if (2 >= buf.length - count) {
            flushBuffer();
        }

        buf[count++] = '\r';
        buf[count++] = '\n';
    }

    public void writeUtf8CrLf(String str) throws IOException {//XXX
        int strLen = str.length();

        int i;
        for (i = 0; i < strLen; i++) {
            char c = str.charAt(i);
            if (!(c < 0x80)) break;
            buf[count++] = (byte) c;
            if(count == buf.length) {
                flushBuffer();
            }
        }

        for (; i < strLen; i++) {
            char c = str.charAt(i);
            if (c < 0x80) {
                buf[count++] = (byte) c;
                if(count == buf.length) {
                    flushBuffer();
                }
            } else if (c < 0x800) {
                if(2 < buf.length - count) {
                    flushBuffer();
                }
                buf[count++] = (byte)(0xc0 | (c >> 6));
                buf[count++] = (byte)(0x80 | (c & 0x3f));
            } else if (isSurrogate(c)) {
                if(4 < buf.length - count) {
                    flushBuffer();
                }
                int uc = Character.toCodePoint(c, str.charAt(i++));
                buf[count++] = ((byte)(0xf0 | ((uc >> 18))));
                buf[count++] = ((byte)(0x80 | ((uc >> 12) & 0x3f)));
                buf[count++] = ((byte)(0x80 | ((uc >> 6) & 0x3f)));
                buf[count++] = ((byte)(0x80 | (uc & 0x3f)));
            } else {
                if(3 < buf.length - count) {
                    flushBuffer();
                }
                buf[count++] =((byte)(0xe0 | ((c >> 12))));
                buf[count++] =((byte)(0x80 | ((c >> 6) & 0x3f)));
                buf[count++] =((byte)(0x80 | (c & 0x3f)));
            }
        }

        writeCrLf();
    }

    private final static int[] sizeTable = {9, 99, 999, 9999, 99999, 999999, 9999999, 99999999, 999999999, Integer.MAX_VALUE};

    private final static byte[] DigitTens = {
            '0', '0', '0', '0', '0', '0', '0', '0', '0', '0',
            '1', '1', '1', '1', '1', '1', '1', '1', '1', '1',
            '2', '2', '2', '2', '2', '2', '2', '2', '2', '2',
            '3', '3', '3', '3', '3', '3', '3', '3', '3', '3',
            '4', '4', '4', '4', '4', '4', '4', '4', '4', '4',
            '5', '5', '5', '5', '5', '5', '5', '5', '5', '5',
            '6', '6', '6', '6', '6', '6', '6', '6', '6', '6',
            '7', '7', '7', '7', '7', '7', '7', '7', '7', '7',
            '8', '8', '8', '8', '8', '8', '8', '8', '8', '8',
            '9', '9', '9', '9', '9', '9', '9', '9', '9', '9',
    };

    private final static byte[] DigitOnes = {
            '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
            '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
            '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
            '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
            '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
            '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
            '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
            '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
            '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
            '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
    };

    private final static byte[] 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'
    };

    public void writeIntCrLf(int value) throws IOException {//写一个整数
        if (value < 0) {
            write('-');
            value = -value;
        }

        int size = 0;
        while (value > sizeTable[size])
            size++;

        size++;
        if (size >= buf.length - count) {
            flushBuffer();
        }

        int q, r;
        int charPos = count + size;

        while (value >= 65536) {
            q = value / 100;
            r = value - ((q << 6) + (q << 5) + (q << 2));
            value = q;
            buf[--charPos] = DigitOnes[r];
            buf[--charPos] = DigitTens[r];
        }

        for (; ;) {
            q = (value * 52429) >>> (16 + 3);
            r = value - ((q << 3) + (q << 1));
            buf[--charPos] = digits[r];
            value = q;
            if (value == 0) break;
        }
        count += size;

        writeCrLf();
    }

    public void flush() throws IOException {//写完缓冲区,并且对out执行flush操作。
        flushBuffer();
        out.flush();
    }
}

“RedisOutputStream.java的源码是什么”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注创新互联网站,小编将为大家输出更多高质量的实用文章!

上一篇:没有了
快速申请办理
称呼: *
电话: *

订单提交后,10分钟内,我们将安排工作人员和您联系!

热点资讯
联系我们
大悟县玛尊真商贸有限公司
电   话:0712-7218610

传   真:0712-7218610

谭经理:18980820575

王主任:135 1821 9792

邮   箱:631063699@qq.com

地   址:湖北省孝感市大悟县城关镇鄂北物流城13栋125号

微信二维码
扫一扫 关注我们
电话:

189-8208-1108

湖北省孝感市大悟县城关镇鄂北物流城13栋125号八戒云创空间-D1-430

ISO体系认证
iso认证
服务体系认证
有机产品认证
OHSAS18001
ITSS认证
信用评级
中国招标企业信用认证
资信等级
重合同守信用
企业信用认证
中国诚信供应商
质量、服务诚信认证
CMMI
CMMI1
CMMI2
CMMI3
CMMI4
CMMI5
系统集成
系统集成一级
信息系统集成二级
信息系统集成三级
信息系统集成四级
涉密信息系统集成
资质许可证
生产许可证认证
GS认证
CCC认证
中国节能认证
十环认证
知识产权

Copyright © 2002-2025

大悟县玛尊真商贸有限公司 版权所有

备案/许可证号:鄂ICP备2025140345号-7   网站建设创新互联
 
QQ在线咨询
客服咨询
咨询热线
189-8208-1108