http优化
This commit is contained in:
@@ -13,11 +13,13 @@ import org.redkale.util.*;
|
||||
* HttpRender主要是给HttpResponse.finish(Object obj)提供指定数据类型的输出策略。 <br>
|
||||
* <pre>
|
||||
* HttpResponse.finish(Object obj)内置对如下数据类型进行了特殊处理:
|
||||
* CompletionStage
|
||||
* CharSequence/String
|
||||
* byte[]
|
||||
* File
|
||||
* RetResult
|
||||
* HttpResult
|
||||
* HttpScope
|
||||
* </pre>
|
||||
* <p>
|
||||
* 如果对其他数据类型有特殊输出的需求,则需要自定义HttpRender。
|
||||
|
||||
@@ -641,7 +641,7 @@ public class HttpRequest extends Request<HttpContext> {
|
||||
}
|
||||
break;
|
||||
}
|
||||
bytes.put(b);
|
||||
bytes.putWithoutCheck(b);
|
||||
}
|
||||
size = bytes.length();
|
||||
byte[] content = bytes.content();
|
||||
|
||||
@@ -6,9 +6,9 @@
|
||||
package org.redkale.util;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.*;
|
||||
import java.nio.charset.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 简单的byte[]操作类。
|
||||
@@ -292,31 +292,6 @@ public final class ByteArray implements ByteTuple {
|
||||
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的内容引用给本对象
|
||||
*
|
||||
@@ -819,6 +794,16 @@ public final class ByteArray implements ByteTuple {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 写入一个byte值
|
||||
*
|
||||
* @param value byte值
|
||||
*
|
||||
*/
|
||||
public void putWithoutCheck(byte value) {
|
||||
content[count++] = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* 写入一个byte值, content.length 必须不能小于offset+1
|
||||
*
|
||||
@@ -917,6 +902,31 @@ public final class ByteArray implements ByteTuple {
|
||||
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中的一部分
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user