This commit is contained in:
@@ -31,7 +31,7 @@ public abstract class Response<C extends Context, R extends Request<C>> {
|
|||||||
|
|
||||||
protected Object output; //输出的结果对象
|
protected Object output; //输出的结果对象
|
||||||
|
|
||||||
protected BiConsumer<R, Response<C, R>> recycleListener;
|
protected BiConsumer<R, Response<C, R>> recycleListener;
|
||||||
|
|
||||||
private final CompletionHandler finishHandler = new CompletionHandler<Integer, ByteBuffer>() {
|
private final CompletionHandler finishHandler = new CompletionHandler<Integer, ByteBuffer>() {
|
||||||
|
|
||||||
@@ -56,29 +56,26 @@ public abstract class Response<C extends Context, R extends Request<C>> {
|
|||||||
private final CompletionHandler finishHandler2 = new CompletionHandler<Integer, ByteBuffer[]>() {
|
private final CompletionHandler finishHandler2 = new CompletionHandler<Integer, ByteBuffer[]>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void completed(Integer result, ByteBuffer[] attachments) {
|
public void completed(final Integer result, final ByteBuffer[] attachments) {
|
||||||
int index = -1;
|
int index = -1;
|
||||||
for (int i = 0; i < attachments.length; i++) {
|
for (int i = 0; i < attachments.length; i++) {
|
||||||
if (attachments[i].hasRemaining()) {
|
if (attachments[i].hasRemaining()) {
|
||||||
index = i;
|
index = i;
|
||||||
break;
|
break;
|
||||||
} else {
|
|
||||||
context.offerBuffer(attachments[i]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (index == 0) {
|
if (index >= 0) {
|
||||||
channel.write(attachments, attachments, this);
|
channel.write(attachments, index, attachments.length - index, attachments, this);
|
||||||
} else if (index > 0) {
|
|
||||||
ByteBuffer[] newattachs = new ByteBuffer[attachments.length - index];
|
|
||||||
System.arraycopy(attachments, index, newattachs, 0, newattachs.length);
|
|
||||||
channel.write(newattachs, newattachs, this);
|
|
||||||
} else {
|
} else {
|
||||||
|
for (ByteBuffer attachment : attachments) {
|
||||||
|
context.offerBuffer(attachment);
|
||||||
|
}
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void failed(Throwable exc, ByteBuffer[] attachments) {
|
public void failed(Throwable exc, final ByteBuffer[] attachments) {
|
||||||
for (ByteBuffer attachment : attachments) {
|
for (ByteBuffer attachment : attachments) {
|
||||||
context.offerBuffer(attachment);
|
context.offerBuffer(attachment);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user