use of com.generallycloud.baseio.component.ByteArrayBuffer in project baseio by generallycloud.
the class ServerHTTPProtocolEncoder method encode.
@Override
public void encode(SocketChannel channel, ChannelFuture readFuture) throws IOException {
ByteBufAllocator allocator = channel.getByteBufAllocator();
ServerHttpFuture f = (ServerHttpFuture) readFuture;
if (f.isUpdateWebSocketProtocol()) {
channel.setProtocolDecoder(WebSocketProtocolFactory.WS_PROTOCOL_DECODER);
channel.setProtocolEncoder(WebSocketProtocolFactory.WS_PROTOCOL_ENCODER);
channel.setProtocolFactory(WebSocketProtocolFactory.WS_PROTOCOL_FACTORY);
channel.getSession().setAttribute(WebSocketFuture.SESSION_KEY_SERVICE_NAME, f.getFutureName());
}
f.setResponseHeader("Date", HttpHeaderDateFormat.getFormat().format(System.currentTimeMillis()));
ByteArrayBuffer os = f.getBinaryBuffer();
if (os != null) {
encode(allocator, f, os.size(), os.array());
return;
}
int writeSize = f.getWriteSize();
if (writeSize == 0) {
encode(allocator, f, 0, null);
return;
}
encode(allocator, f, writeSize, f.getWriteBuffer());
}
use of com.generallycloud.baseio.component.ByteArrayBuffer in project baseio by generallycloud.
the class CharBasedFutureImpl method read.
@Override
public boolean read(SocketChannel channel, ByteBuf buffer) throws IOException {
if (complete) {
return true;
}
ByteArrayBuffer cache = this.cache;
for (; buffer.hasRemaining(); ) {
byte b = buffer.getByte();
if (b == splitor) {
this.readText = cache.toString(context.getEncoding());
this.complete = true;
return true;
}
cache.write(b);
if (cache.size() > limit) {
throw new IOException("max length " + limit);
}
}
return false;
}
Aggregations