http优化

This commit is contained in:
redkale
2023-03-19 19:26:11 +08:00
parent 32cae92848
commit f9a65f7492
3 changed files with 40 additions and 28 deletions

View File

@@ -13,11 +13,13 @@ import org.redkale.util.*;
* HttpRender主要是给HttpResponse.finish(Object obj)提供指定数据类型的输出策略。 <br> * HttpRender主要是给HttpResponse.finish(Object obj)提供指定数据类型的输出策略。 <br>
* <pre> * <pre>
* HttpResponse.finish(Object obj)内置对如下数据类型进行了特殊处理: * HttpResponse.finish(Object obj)内置对如下数据类型进行了特殊处理:
* CompletionStage
* CharSequence/String * CharSequence/String
* byte[] * byte[]
* File * File
* RetResult * RetResult
* HttpResult * HttpResult
* HttpScope
* </pre> * </pre>
* <p> * <p>
* 如果对其他数据类型有特殊输出的需求则需要自定义HttpRender。 * 如果对其他数据类型有特殊输出的需求则需要自定义HttpRender。

View File

@@ -641,7 +641,7 @@ public class HttpRequest extends Request<HttpContext> {
} }
break; break;
} }
bytes.put(b); bytes.putWithoutCheck(b);
} }
size = bytes.length(); size = bytes.length();
byte[] content = bytes.content(); byte[] content = bytes.content();

View File

@@ -6,9 +6,9 @@
package org.redkale.util; package org.redkale.util;
import java.io.*; import java.io.*;
import java.nio.ByteBuffer; import java.nio.*;
import java.nio.charset.*; import java.nio.charset.*;
import java.util.Arrays; import java.util.*;
/** /**
* 简单的byte[]操作类。 * 简单的byte[]操作类。
@@ -292,31 +292,6 @@ public final class ByteArray implements ByteTuple {
System.arraycopy(this.content, 0, buf, 0, count); System.arraycopy(this.content, 0, buf, 0, count);
} }
/**
* 将ByteBuffer的内容读取到本对象中
*
* @param buffer ByteBuffer
*/
public void put(ByteBuffer buffer) {
if (buffer == null) {
return;
}
int remain = buffer.remaining();
if (remain == 0) {
return;
}
int l = this.content.length - count;
if (remain > l) {
byte[] ns = new byte[this.content.length + remain];
if (count > 0) {
System.arraycopy(content, 0, ns, 0, count);
}
this.content = ns;
}
buffer.get(content, count, remain);
count += remain;
}
/** /**
* 将array的内容引用给本对象 * 将array的内容引用给本对象
* *
@@ -819,6 +794,16 @@ public final class ByteArray implements ByteTuple {
return this; return this;
} }
/**
* 写入一个byte值
*
* @param value byte值
*
*/
public void putWithoutCheck(byte value) {
content[count++] = value;
}
/** /**
* 写入一个byte值 content.length 必须不能小于offset+1 * 写入一个byte值 content.length 必须不能小于offset+1
* *
@@ -917,6 +902,31 @@ public final class ByteArray implements ByteTuple {
return this; return this;
} }
/**
* 将ByteBuffer的内容读取到本对象中
*
* @param buffer ByteBuffer
*/
public void put(ByteBuffer buffer) {
if (buffer == null) {
return;
}
int remain = buffer.remaining();
if (remain == 0) {
return;
}
int l = this.content.length - count;
if (remain > l) {
byte[] ns = new byte[this.content.length + remain];
if (count > 0) {
System.arraycopy(content, 0, ns, 0, count);
}
this.content = ns;
}
buffer.get(content, count, remain);
count += remain;
}
/** /**
* 写入ByteArray中的一部分 * 写入ByteArray中的一部分
* *