本文整理汇总了Java中io.netty.buffer.ByteBuf.writeZero方法的典型用法代码示例。如果您正苦于以下问题:Java ByteBuf.writeZero方法的具体用法?Java ByteBuf.writeZero怎么用?Java ByteBuf.writeZero使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.netty.buffer.ByteBuf
的用法示例。
在下文中一共展示了ByteBuf.writeZero方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: writeFixLength
import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
/**
* 给 ByteBuf 写入定长字符串
* <p>
* 若字符串长度大于定长,则截取定长字节;若小于定长,则补零
*
* @param buf
* @param content
* @param length
*/
public static void writeFixLength(ByteBuf buf, String content, int length) {
byte[] bytes = content.getBytes(CharsetUtil.UTF_8);
int blen = bytes.length;
int wlen = blen > length ? length : blen;
buf.writeBytes(bytes, 0, wlen);
if (wlen < length) {
buf.writeZero(length - wlen);
}
}
示例2: getPadding
import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
private static ByteBuf getPadding(int headerSize)
{
int paddingSize = 4 - headerSize % 4;
ByteBuf padding = Unpooled.buffer(paddingSize);
padding.writeZero(paddingSize);
return padding;
}
示例3: handleUFormat
import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
private void handleUFormat ( final UnnumberedControl msg, final ByteBuf out )
{
out.ensureWritable ( 6 );
out.writeByte ( Constants.START_BYTE );
out.writeByte ( 4 );
out.writeByte ( msg.getFunction ().getNumericValue () | 0x03 /* bits 1 and 2*/);
out.writeZero ( 3 );
}
示例4: processOption
import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
private String processOption(ChannelHandlerContext ctx, ByteBuf in) throws IOException {
switch (currentOption) {
case Protocol.NBD_OPT_EXPORT_NAME:
CharSequence exportName = in.readCharSequence((int) currentOptionLen, Charset.forName("UTF-8"));
if (!exportProvider.supportsClientFlags(clientFlags)) {
LOGGER.error("client flags {} not supported", clientFlags);
ctx.channel().close();
break;
}
long exportSize = 0;
if ((exportSize = exportProvider.open(exportName)) < 0) {
// ep us unwilling to export this name
ctx.channel().close();
break;
}
/* build response */
ByteBuf resp = ctx.alloc().buffer(256);
resp.writeLong(exportSize);
short transmissionFlags =
Protocol.NBD_FLAG_HAS_FLAGS
| Protocol.NBD_FLAG_SEND_FLUSH
| Protocol.NBD_FLAG_SEND_TRIM;
resp.writeShort(transmissionFlags);
if ((clientFlags & Protocol.NBD_FLAG_NO_ZEROES) == 0) {
resp.writeZero(124);
}
ctx.writeAndFlush(resp);
//FIXME: transfer any remaining bytes into the transmission phase!
/* The NBD protocol has two phases: the handshake (HS_) and the transmission (TM_) */
// Handshake complete, switch to transmission phase
ctx.pipeline().addLast("transmission", new TransmissionPhase(config, exportProvider));
ctx.pipeline().remove(this);
return exportName.toString();
default:
sendHandshakeOptionHagglingReply(ctx, currentOption, Protocol.NBD_REP_ERR_UNSUP, null);
}
return null;
}