This commit is contained in:
Redkale
2018-08-27 12:36:35 +08:00
parent 921f96c975
commit 4525cfe594
8 changed files with 11 additions and 24 deletions

View File

@@ -35,12 +35,8 @@ public class BsonByteBufferWriter extends BsonWriter {
this.supplier = supplier;
}
public ByteBuffer[] toBuffers() {
return toBuffers(supplier);
}
@Override
public ByteBuffer[] toBuffers(Supplier<ByteBuffer> supplier) {
public ByteBuffer[] toBuffers() {
if (buffers == null) return new ByteBuffer[0];
for (int i = index; i < this.buffers.length; i++) {
ByteBuffer buf = this.buffers[i];

View File

@@ -6,7 +6,6 @@
package org.redkale.convert.bson;
import java.nio.ByteBuffer;
import java.util.function.Supplier;
import org.redkale.convert.*;
import org.redkale.util.*;
@@ -38,9 +37,8 @@ public class BsonWriter extends Writer {
return newdata;
}
public ByteBuffer[] toBuffers(final Supplier<ByteBuffer> supplier) {
if (supplier == null) return new ByteBuffer[]{ByteBuffer.wrap(content, 0, count)};
return ByteBufferWriter.create(supplier).put(content, 0, count).toBuffers();
public ByteBuffer[] toBuffers() {
return new ByteBuffer[]{ByteBuffer.wrap(content, 0, count)};
}
protected BsonWriter(byte[] bs) {

View File

@@ -55,12 +55,8 @@ public class JsonByteBufferWriter extends JsonWriter {
return false;
}
public ByteBuffer[] toBuffers() {
return toBuffers(supplier);
}
@Override
public ByteBuffer[] toBuffers(Supplier<ByteBuffer> supplier) {
public ByteBuffer[] toBuffers() {
if (buffers == null) return new ByteBuffer[0];
for (int i = index; i < this.buffers.length; i++) {
ByteBuffer buf = this.buffers[i];

View File

@@ -6,7 +6,6 @@
package org.redkale.convert.json;
import java.nio.ByteBuffer;
import java.util.function.Supplier;
import org.redkale.convert.*;
import org.redkale.util.*;
@@ -107,9 +106,8 @@ public class JsonWriter extends Writer {
return true;
}
public ByteBuffer[] toBuffers(Supplier<ByteBuffer> supplier) {
if (supplier == null) return new ByteBuffer[]{ByteBuffer.wrap(Utility.encodeUTF8(content, 0, count))};
return ByteBufferWriter.create(supplier).put(Utility.encodeUTF8(content, 0, count)).toBuffers();
public ByteBuffer[] toBuffers() {
return new ByteBuffer[]{ByteBuffer.wrap(Utility.encodeUTF8(content, 0, count))};
}
public byte[] toBytes() {

View File

@@ -10,7 +10,6 @@ import java.nio.ByteBuffer;
import java.nio.channels.CompletionHandler;
import java.util.function.*;
import java.util.logging.Level;
import org.redkale.util.ByteBufferWriter;
/**
* 协议响应对象
@@ -275,7 +274,7 @@ public abstract class Response<C extends Context, R extends Request<C>> {
buffer.flip();
this.finish(buffer);
} else {
this.finish(ByteBufferWriter.toBuffers(this.context.getBufferSupplier(), bs));
this.finish(ByteBuffer.wrap(bs));
}
}

View File

@@ -636,7 +636,7 @@ public class HttpResponse extends Response<HttpContext, HttpRequest> {
super.finish(false, headbuf);
} else {
headbuf.flip();
super.finish(false, Utility.append(new ByteBuffer[]{headbuf}, ByteBufferWriter.toBuffers(context.getBufferSupplier(), content)));
super.finish(false, new ByteBuffer[]{headbuf, ByteBuffer.wrap(content)});
}
} else {
if (this.context.getBufferCapacity() >= content.length) {
@@ -645,7 +645,7 @@ public class HttpResponse extends Response<HttpContext, HttpRequest> {
buffer.flip();
this.finish(false, buffer);
} else {
this.finish(false, ByteBufferWriter.toBuffers(context.getBufferSupplier(), content));
this.finish(false, ByteBuffer.wrap(content));
}
}

View File

@@ -367,7 +367,7 @@ public final class SncpClient {
return future;
}
final AsyncConnection conn = conn0;
final ByteBuffer[] sendBuffers = writer.toBuffers(transport.getBufferSupplier());
final ByteBuffer[] sendBuffers = writer.toBuffers();
fillHeader(sendBuffers[0], seqid, actionid, reqBodyLength);
final ByteBuffer buffer = transport.pollBuffer();

View File

@@ -65,7 +65,7 @@ public final class SncpResponse extends Response<SncpContext, SncpRequest> {
return;
}
final int respBodyLength = out.count(); //body总长度
final ByteBuffer[] buffers = out.toBuffers(context.getBufferSupplier());
final ByteBuffer[] buffers = out.toBuffers();
fillHeader(buffers[0], respBodyLength - HEADER_SIZE, retcode);
finish(buffers);
}