本文整理汇总了Java中org.jboss.netty.buffer.ChannelBufferOutputStream.close方法的典型用法代码示例。如果您正苦于以下问题:Java ChannelBufferOutputStream.close方法的具体用法?Java ChannelBufferOutputStream.close怎么用?Java ChannelBufferOutputStream.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jboss.netty.buffer.ChannelBufferOutputStream
的用法示例。
在下文中一共展示了ChannelBufferOutputStream.close方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buffer
import org.jboss.netty.buffer.ChannelBufferOutputStream; //导入方法依赖的package包/类
/**
* create a buffer containing the encoding of this batch
*/
ChannelBuffer buffer() throws Exception {
ChannelBufferOutputStream bout = new ChannelBufferOutputStream(
ChannelBuffers.directBuffer(encoded_length));
for (Object msg : msgs)
if (msg instanceof TaskMessage)
writeTaskMessage(bout, (TaskMessage) msg);
else {
// LOG.debug("Write one non-TaskMessage {}", msg );
((ControlMessage) msg).write(bout);
}
// add a END_OF_BATCH indicator
ControlMessage.EOB_MESSAGE.write(bout);
// LOG.debug("ControlMessage.EOB_MESSAGE " );
bout.close();
return bout.buffer();
}
示例2: buffer
import org.jboss.netty.buffer.ChannelBufferOutputStream; //导入方法依赖的package包/类
/**
* create a buffer containing the encoding of this batch
*/
ChannelBuffer buffer() throws Exception {
ChannelBufferOutputStream bout = new ChannelBufferOutputStream(ChannelBuffers.directBuffer(encoded_length));
for (Object msg : msgs)
if (msg instanceof TaskMessage)
writeTaskMessage(bout, (TaskMessage) msg);
else {
// LOG.debug("Write one non-TaskMessage {}", msg );
((ControlMessage) msg).write(bout);
}
// add a END_OF_BATCH indicator
ControlMessage.EOB_MESSAGE.write(bout);
// LOG.debug("ControlMessage.EOB_MESSAGE " );
bout.close();
return bout.buffer();
}
示例3: buffer
import org.jboss.netty.buffer.ChannelBufferOutputStream; //导入方法依赖的package包/类
/**
* create a buffer containing the encoding of this batch
*/
ChannelBuffer buffer() throws Exception {
ChannelBufferOutputStream bout = new ChannelBufferOutputStream(ChannelBuffers.directBuffer(encoded_length));
for (Object msg : msgs)
if (msg instanceof TaskMessage)
writeTaskMessage(bout, (TaskMessage)msg);
else
((ControlMessage)msg).write(bout);
//add a END_OF_BATCH indicator
ControlMessage.EOB_MESSAGE.write(bout);
bout.close();
return bout.buffer();
}
示例4: buffer
import org.jboss.netty.buffer.ChannelBufferOutputStream; //导入方法依赖的package包/类
/**
* create a buffer containing the encoding of this batch
*/
@Override
public ChannelBuffer buffer() throws Exception {
ChannelBufferOutputStream bout = new ChannelBufferOutputStream(ChannelBuffers.directBuffer(encodedLength));
for (Object msg : msgs)
if (msg instanceof TaskMessage)
writeTaskMessage(bout, (TaskMessage) msg);
else {
// LOG.debug("Write one non-TaskMessage {}", msg );
((ControlMessage) msg).write(bout);
}
// add a END_OF_BATCH indicator
ControlMessage.EOB_MESSAGE.write(bout);
// LOG.debug("ControlMessage.EOB_MESSAGE " );
bout.close();
return bout.buffer();
}
示例5: buffer
import org.jboss.netty.buffer.ChannelBufferOutputStream; //导入方法依赖的package包/类
/**
* create a buffer containing the encoding of this batch
*/
@Override
public ChannelBuffer buffer() throws Exception {
int payloadLen = 0;
if (_message != null)
payloadLen = _message.length;
int totalLen = 8 + payloadLen;
ChannelBufferOutputStream bout = new ChannelBufferOutputStream(ChannelBuffers.directBuffer(totalLen));
bout.writeShort(_type);
if (_task > Short.MAX_VALUE)
throw new RuntimeException("Task ID should not exceed " + Short.MAX_VALUE);
bout.writeShort((short) _task);
bout.writeInt(payloadLen);
if (payloadLen > 0)
bout.write(_message);
bout.close();
return bout.buffer();
}
示例6: doEncode
import org.jboss.netty.buffer.ChannelBufferOutputStream; //导入方法依赖的package包/类
private Object doEncode(Request request, ChannelHandlerContext ctx, Channel channel) throws Exception {
//version from request header;
byte ver = request.getHeader().getSerializeVersion();
//overwrite if request header == 0 and version != 0, use version
if ( ver == 0 && version != 0)
ver = version;
int pLen = request.getPayload() == null ? 0 : request.getPayload().length;
byte[] header = request.getHeader().toByte();
// encoding length , and check the max value of integer, should be 2GB
int len = TOTAL + header.length + pLen + R_SIZE;
if ( len > Integer.MAX_VALUE ) {
channel.close();
throw new Exception( len+" exceeding Integer.MAX_VALUE");
}
ChannelBufferOutputStream bout = new ChannelBufferOutputStream(dynamicBuffer(
len, ctx.getChannel().getConfig().getBufferFactory()));
bout.write(SIGNATURE);
bout.write(ver);
bout.writeInt(len);
bout.writeShort((short) header.length);
bout.write(header);
// request type
bout.write((byte) request.getType().ordinal());
bout.write( request.getPayload());
bout.flush();
bout.close();
ChannelBuffer encoded = bout.buffer();
return encoded;
}
示例7: buffer
import org.jboss.netty.buffer.ChannelBufferOutputStream; //导入方法依赖的package包/类
/**
* create a buffer containing the encoding of this batch
*/
ChannelBuffer buffer() throws Exception {
ChannelBufferOutputStream bout = new ChannelBufferOutputStream(ChannelBuffers.directBuffer(encoded_length));
for (TaskMessage msg : msgs)
writeTaskMessage(bout, msg);
//add a END_OF_BATCH indicator
ControlMessage.EOB_MESSAGE.write(bout);
bout.close();
return bout.buffer();
}
示例8: encode
import org.jboss.netty.buffer.ChannelBufferOutputStream; //导入方法依赖的package包/类
@Override
protected Object encode(ChannelHandlerContext ctx,
Channel channel, Object msg) throws Exception {
if (!(msg instanceof WritableRequest)) {
throw new IllegalArgumentException(
"encode: Got a message of type " + msg.getClass());
}
// Encode the request
if (LOG.isDebugEnabled()) {
startEncodingNanoseconds = TIME.getNanoseconds();
}
WritableRequest writableRequest = (WritableRequest) msg;
int requestSize = writableRequest.getSerializedSize();
ChannelBuffer channelBuffer;
if (requestSize == WritableRequest.UNKNOWN_SIZE) {
channelBuffer = ChannelBuffers.dynamicBuffer(
bufferStartingSize,
ctx.getChannel().getConfig().getBufferFactory());
} else {
requestSize += LENGTH_PLACEHOLDER.length + 1;
channelBuffer = useDirectBuffers ?
ChannelBuffers.directBuffer(requestSize) :
ChannelBuffers.buffer(requestSize);
}
ChannelBufferOutputStream outputStream =
new ChannelBufferOutputStream(channelBuffer);
outputStream.write(LENGTH_PLACEHOLDER);
outputStream.writeByte(writableRequest.getType().ordinal());
try {
writableRequest.write(outputStream);
} catch (IndexOutOfBoundsException e) {
LOG.error("encode: Most likely the size of request was not properly " +
"specified - see getSerializedSize() in " +
writableRequest.getType().getRequestClass());
throw new IllegalStateException(e);
}
outputStream.flush();
outputStream.close();
// Set the correct size at the end
ChannelBuffer encodedBuffer = outputStream.buffer();
encodedBuffer.setInt(0, encodedBuffer.writerIndex() - 4);
if (LOG.isDebugEnabled()) {
LOG.debug("encode: Client " + writableRequest.getClientId() + ", " +
"requestId " + writableRequest.getRequestId() +
", size = " + encodedBuffer.writerIndex() + ", " +
writableRequest.getType() + " took " +
Times.getNanosSince(TIME, startEncodingNanoseconds) + " ns");
}
return encodedBuffer;
}