This commit is contained in:
@@ -11,6 +11,7 @@ import java.net.*;
|
|||||||
import java.nio.*;
|
import java.nio.*;
|
||||||
import java.nio.charset.*;
|
import java.nio.charset.*;
|
||||||
import java.util.concurrent.*;
|
import java.util.concurrent.*;
|
||||||
|
import java.util.function.*;
|
||||||
import java.util.logging.*;
|
import java.util.logging.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -89,6 +90,10 @@ public class Context {
|
|||||||
return bufferCapacity;
|
return bufferCapacity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Supplier<ByteBuffer> getBufferSupplier() {
|
||||||
|
return bufferPool;
|
||||||
|
}
|
||||||
|
|
||||||
public ByteBuffer pollBuffer() {
|
public ByteBuffer pollBuffer() {
|
||||||
return bufferPool.get();
|
return bufferPool.get();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import java.nio.channels.*;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.*;
|
import java.util.concurrent.*;
|
||||||
import java.util.concurrent.atomic.*;
|
import java.util.concurrent.atomic.*;
|
||||||
|
import java.util.function.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 传输客户端
|
* 传输客户端
|
||||||
@@ -115,6 +116,10 @@ public final class Transport {
|
|||||||
return bufferPool.get();
|
return bufferPool.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Supplier<ByteBuffer> getBufferSupplier() {
|
||||||
|
return bufferPool;
|
||||||
|
}
|
||||||
|
|
||||||
public void offerBuffer(ByteBuffer buffer) {
|
public void offerBuffer(ByteBuffer buffer) {
|
||||||
bufferPool.offer(buffer);
|
bufferPool.offer(buffer);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,10 +60,6 @@ public final class HttpContext extends Context {
|
|||||||
return responsePool;
|
return responsePool;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ObjectPool<ByteBuffer> getBufferPool() {
|
|
||||||
return bufferPool;
|
|
||||||
}
|
|
||||||
|
|
||||||
public JsonConvert getJsonConvert() {
|
public JsonConvert getJsonConvert() {
|
||||||
return jsonFactory.getConvert();
|
return jsonFactory.getConvert();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ import java.nio.file.*;
|
|||||||
import java.text.*;
|
import java.text.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.atomic.*;
|
import java.util.concurrent.atomic.*;
|
||||||
import java.util.function.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -148,10 +147,6 @@ public class HttpResponse<R extends HttpRequest> extends Response<R> {
|
|||||||
return v == null ? defValue : v;
|
return v == null ? defValue : v;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Supplier<ByteBuffer> getByteBufferSupplier() {
|
|
||||||
return ((HttpContext) context).getBufferPool();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public HttpContext getContext() {
|
public HttpContext getContext() {
|
||||||
return (HttpContext) context;
|
return (HttpContext) context;
|
||||||
@@ -170,17 +165,17 @@ public class HttpResponse<R extends HttpRequest> extends Response<R> {
|
|||||||
|
|
||||||
public void finishJson(Object obj) {
|
public void finishJson(Object obj) {
|
||||||
this.contentType = "text/plain; charset=utf-8";
|
this.contentType = "text/plain; charset=utf-8";
|
||||||
finish(request.convert.convertTo(context.getCharset(), getByteBufferSupplier(), obj));
|
finish(request.convert.convertTo(context.getCharset(), context.getBufferSupplier(), obj));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void finishJson(Type type, Object obj) {
|
public void finishJson(Type type, Object obj) {
|
||||||
this.contentType = "text/plain; charset=utf-8";
|
this.contentType = "text/plain; charset=utf-8";
|
||||||
finish(request.convert.convertTo(context.getCharset(), getByteBufferSupplier(), type, obj));
|
finish(request.convert.convertTo(context.getCharset(), context.getBufferSupplier(), type, obj));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void finishJson(Object... objs) {
|
public void finishJson(Object... objs) {
|
||||||
this.contentType = "text/plain; charset=utf-8";
|
this.contentType = "text/plain; charset=utf-8";
|
||||||
finish(request.convert.convertTo(context.getCharset(), getByteBufferSupplier(), objs));
|
finish(request.convert.convertTo(context.getCharset(), context.getBufferSupplier(), objs));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void finish(String obj) {
|
public void finish(String obj) {
|
||||||
|
|||||||
Reference in New Issue
Block a user