RedisOutputStream.java的源码是什么
发表于:2025-12-02 作者:千家信息网编辑
千家信息网最后更新 2025年12月02日,本篇内容介绍了"RedisOutputStream.java的源码是什么"的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅
千家信息网最后更新 2025年12月02日RedisOutputStream.java的源码是什么
本篇内容介绍了"RedisOutputStream.java的源码是什么"的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!
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的源码是什么"的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注网站,小编将为大家输出更多高质量的实用文章!
缓冲区
缓冲
源码
内容
更多
知识
编码
实用
学有所成
接下来
困境
实际
情况
整数
文章
方式
案例
编带
网站
行业
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
查账软件数据库安装在哪
做好网络安全守护者
赣州科汇网络技术
技术先进的服务器监控工具
魔兽世界哪些是合并服务器
伊春网络技术工程师证
康展互联网科技
北京华瑞软件开发公司
嘉兴数字视频系统服务器
参考文献网站属于网上数据库吗
软件开发与云计算哪个好
实验技能数据库
衡水快报网络安全审查办法开启
武汉档存网络技术有限公司
如何登录smb服务器
贵阳金融城软件开发
json数据库性能
广西生信分析软件开发
软件开发十大免费自学网站
python 网络安全前景
土地利用规划数据库标准
同花顺等待代理服务器超时
小程序中怎么获取数据库信息
流媒体服务器实现语音广播
自己搞一个原神服务器
潍坊销售管理软件开发公司
云计算软件开发教学
上海助力智慧工厂软件开发
软件开发如何避免人员流失
自动化打胶机控制软件开发