当前位置: 首页>>代码示例>>Java>>正文


Java ByteBufUtil.writeAscii方法代码示例

本文整理汇总了Java中io.netty.buffer.ByteBufUtil.writeAscii方法的典型用法代码示例。如果您正苦于以下问题:Java ByteBufUtil.writeAscii方法的具体用法?Java ByteBufUtil.writeAscii怎么用?Java ByteBufUtil.writeAscii使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.netty.buffer.ByteBufUtil的用法示例。


在下文中一共展示了ByteBufUtil.writeAscii方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: encode

import io.netty.buffer.ByteBufUtil; //导入方法依赖的package包/类
@Override
protected void encode(ChannelHandlerContext ctx, Object msg, List<Object> out) throws Exception {
  if (!(msg instanceof SmtpRequest)) {
    return;
  }

  boolean release = true;
  final ByteBuf buffer = ctx.alloc().buffer();

  try {
    final SmtpRequest req = (SmtpRequest) msg;

    ByteBufUtil.writeAscii(buffer, req.command().name());
    writeParameters(req.parameters(), buffer);
    buffer.writeBytes(CRLF);

    out.add(buffer);
    release = false;
  } finally {
    if (release) {
      buffer.release();
    }
  }
}
 
开发者ID:HubSpot,项目名称:NioSmtpClient,代码行数:25,代码来源:Utf8SmtpRequestEncoder.java

示例2: channelRead0

import io.netty.buffer.ByteBufUtil; //导入方法依赖的package包/类
@Override
public void channelRead0(ChannelHandlerContext ctx, FullHttpRequest req) throws Exception {
    if (HttpUtil.is100ContinueExpected(req)) {
        ctx.write(new DefaultFullHttpResponse(HTTP_1_1, CONTINUE));
    }
    boolean keepAlive = HttpUtil.isKeepAlive(req);

    ByteBuf content = ctx.alloc().buffer();
    content.writeBytes(HelloWorldHttp2Handler.RESPONSE_BYTES.duplicate());
    ByteBufUtil.writeAscii(content, " - via " + req.protocolVersion() + " (" + establishApproach + ")");

    FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, OK, content);
    response.headers().set(CONTENT_TYPE, "text/plain; charset=UTF-8");
    response.headers().setInt(CONTENT_LENGTH, response.content().readableBytes());

    if (!keepAlive) {
        ctx.writeAndFlush(response).addListener(ChannelFutureListener.CLOSE);
    } else {
        response.headers().set(CONNECTION, HttpHeaderValues.KEEP_ALIVE);
        ctx.writeAndFlush(response);
    }
}
 
开发者ID:cowthan,项目名称:JavaAyo,代码行数:23,代码来源:HelloWorldHttp1Handler.java

示例3: fromDataString

import io.netty.buffer.ByteBufUtil; //导入方法依赖的package包/类
/**
 * Read a DeviceConnectInformation from a Base64 encoded String, which was read from a QR Code.
 */
public static DeviceConnectInformation fromDataString(String data) throws IOException {
    final ByteBuf base64 = UnpooledByteBufAllocator.DEFAULT.heapBuffer(data.length());
    ByteBufUtil.writeAscii(base64, data);
    final ByteBuf byteBuf = decode(base64);
    if (byteBuf.readableBytes() != DATA_LENGTH) {
        throw new IOException("too many bytes encoded");
    }

    final byte[] addressData = new byte[ADDRESS_LENGTH];
    byteBuf.readBytes(addressData);
    final InetAddress address = InetAddress.getByAddress(addressData);
    final int port = byteBuf.readUnsignedShort();
    final byte[] idData = new byte[DeviceID.ID_LENGTH];
    byteBuf.readBytes(idData);
    final DeviceID id = new DeviceID(idData);
    final byte[] encodedToken = new byte[TOKEN_BASE64_LENGTH];
    byteBuf.readBytes(encodedToken);
    final byte[] token = decodeToken(new String(encodedToken));

    return new DeviceConnectInformation(address, port, id, token);
}
 
开发者ID:SecureSmartHome,项目名称:SecureSmartHome,代码行数:25,代码来源:DeviceConnectInformation.java

示例4: onPingRead

import io.netty.buffer.ByteBufUtil; //导入方法依赖的package包/类
@Override
public void onPingRead(ChannelHandlerContext ctx, ByteBuf data) throws Http2Exception {
  if (keepAliveManager != null) {
    keepAliveManager.onDataReceived();
  }
  if (!keepAliveEnforcer.pingAcceptable()) {
    ByteBuf debugData = ByteBufUtil.writeAscii(ctx.alloc(), "too_many_pings");
    goAway(ctx, connection().remote().lastStreamCreated(), Http2Error.ENHANCE_YOUR_CALM.code(),
        debugData, ctx.newPromise());
    Status status = Status.RESOURCE_EXHAUSTED.withDescription("Too many pings from client");
    try {
      forcefulClose(ctx, new ForcefulCloseCommand(status), ctx.newPromise());
    } catch (Exception ex) {
      onError(ctx, ex);
    }
  }
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:18,代码来源:NettyServerHandler.java

示例5: sendResponseString

import io.netty.buffer.ByteBufUtil; //导入方法依赖的package包/类
void sendResponseString(ChannelHandlerContext ctx, int streamId, String responseString) {
    ByteBuf content = ctx.alloc().buffer();
    ByteBufUtil.writeAscii(content, responseString);
    encoder().writeHeaders(
            ctx, streamId, createDefaultResponseHeaders(), 0, false, ctx.newPromise());
    encoder().writeData(ctx, streamId, content, 0, true, ctx.newPromise());
    ctx.flush();
}
 
开发者ID:lizhangqu,项目名称:chromium-net-for-android,代码行数:9,代码来源:Http2TestHandler.java

示例6: getBdatRequestWithData

import io.netty.buffer.ByteBufUtil; //导入方法依赖的package包/类
@SuppressFBWarnings("VA_FORMAT_STRING_USES_NEWLINE") // we shouldn't use platform-specific newlines for SMTP
private ByteBuf getBdatRequestWithData(ByteBuf data, boolean isLast) {
  String request = String.format("BDAT %d%s\r\n", data.readableBytes(), isLast ? " LAST" : "");
  ByteBuf requestBuf = channel.alloc().buffer(request.length());
  ByteBufUtil.writeAscii(requestBuf, request);

  return channel.alloc().compositeBuffer().addComponents(true, requestBuf, data);
}
 
开发者ID:HubSpot,项目名称:NioSmtpClient,代码行数:9,代码来源:SmtpSession.java

示例7: encode

import io.netty.buffer.ByteBufUtil; //导入方法依赖的package包/类
@Override
protected void encode(ChannelHandlerContext ctx, RconMessage message, ByteBuf buf) throws Exception {
    buf.writeIntLE(message.getId());
    buf.writeIntLE(message.getType());
    ByteBufUtil.writeAscii(buf, message.getBody());
    // 2 null bytes
    buf.writeByte(0);
    buf.writeByte(0);
}
 
开发者ID:voxelwind,项目名称:voxelwind,代码行数:10,代码来源:RconEncoder.java

示例8: onHeadersRead

import io.netty.buffer.ByteBufUtil; //导入方法依赖的package包/类
/**
 * If receive a frame with end-of-stream set, send a pre-canned response.
 */
public void onHeadersRead(ChannelHandlerContext ctx, Http2HeadersFrame headers)
        throws Exception {
    if (headers.isEndStream()) {
        ByteBuf content = ctx.alloc().buffer();
        content.writeBytes(RESPONSE_BYTES);
        ByteBufUtil.writeAscii(content, " - via HTTP/2");
        sendResponse(ctx, content);
    }
}
 
开发者ID:cowthan,项目名称:JavaAyo,代码行数:13,代码来源:HelloWorldHttp2Handler.java

示例9: onHeadersRead

import io.netty.buffer.ByteBufUtil; //导入方法依赖的package包/类
@Override
public void onHeadersRead(ChannelHandlerContext ctx, int streamId,
                          Http2Headers headers, int padding, boolean endOfStream) {
    if (endOfStream) {
        ByteBuf content = ctx.alloc().buffer();
        content.writeBytes(RESPONSE_BYTES.duplicate());
        ByteBufUtil.writeAscii(content, " - via HTTP/2");
        sendResponse(ctx, streamId, content);
    }
}
 
开发者ID:cowthan,项目名称:JavaAyo,代码行数:11,代码来源:HelloWorldHttp2Handler.java

示例10: escape

import io.netty.buffer.ByteBufUtil; //导入方法依赖的package包/类
public static void escape(@NotNull CharSequence value, @NotNull ByteBuf buffer) {
  int length = value.length();
  buffer.ensureWritable(length * 2);
  buffer.writeByte('"');
  int last = 0;
  for (int i = 0; i < length; i++) {
    char c = value.charAt(i);
    String replacement;
    if (c < 128) {
      replacement = REPLACEMENT_CHARS[c];
      if (replacement == null) {
        continue;
      }
    }
    else if (c == '\u2028') {
      replacement = "\\u2028";
    }
    else if (c == '\u2029') {
      replacement = "\\u2029";
    }
    else {
      continue;
    }
    if (last < i) {
      ByteBufUtilEx.writeUtf8(buffer, value, last, i);
    }
    ByteBufUtil.writeAscii(buffer, replacement);
    last = i + 1;
  }
  if (last < length) {
    ByteBufUtilEx.writeUtf8(buffer, value, last, length);
  }
  buffer.writeByte('"');
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:35,代码来源:JsonUtil.java

示例11: makeASCIIStringMessage

import io.netty.buffer.ByteBufUtil; //导入方法依赖的package包/类
public static ByteBuf makeASCIIStringMessage(short cmd, int msgId, String data) {
    int dataLength = data.length();
    ByteBuf byteBuf = DEFAULT.buffer(HEADER_LENGTH + dataLength)
            .writeByte(cmd)
            .writeShort(msgId)
            .writeShort(dataLength);

    ByteBufUtil.writeAscii(byteBuf, data);
    return byteBuf;
}
 
开发者ID:blynkkk,项目名称:blynk-server,代码行数:11,代码来源:CommonByteBufUtil.java

示例12: onHeadersRead

import io.netty.buffer.ByteBufUtil; //导入方法依赖的package包/类
/**
 * If receive a frame with end-of-stream set, send a pre-canned response.
 *
 * @param ctx channel handler context
 * @param headers headers frame
 */
public void onHeadersRead(ChannelHandlerContext ctx, Http2HeadersFrame headers) {
  if (headers.isEndStream()) {
    ByteBuf content = ctx.alloc().buffer();
    content.writeBytes(RESPONSE_BYTES);
    ByteBufUtil.writeAscii(content, " - via HTTP/2");
    sendResponse(ctx, content);
  }
}
 
开发者ID:xjdr,项目名称:xio,代码行数:15,代码来源:XioHttp2StreamHandler.java

示例13: encode

import io.netty.buffer.ByteBufUtil; //导入方法依赖的package包/类
public void encode(String str, ByteBuf target) {

        if (str == null) {
            return;
        }

        if (utf8) {
            ByteBufUtil.writeUtf8(target, str);
            return;
        }

        if (ascii) {
            ByteBufUtil.writeAscii(target, str);
            return;
        }

        CharsetEncoder encoder = CharsetUtil.encoder(charset);
        int length = (int) ((double) str.length() * encoder.maxBytesPerChar());
        target.ensureWritable(length);
        try {
            final ByteBuffer dstBuf = target.nioBuffer(0, length);
            final int pos = dstBuf.position();
            CoderResult cr = encoder.encode(CharBuffer.wrap(str), dstBuf, true);
            if (!cr.isUnderflow()) {
                cr.throwException();
            }
            cr = encoder.flush(dstBuf);
            if (!cr.isUnderflow()) {
                cr.throwException();
            }
            target.writerIndex(target.writerIndex() + dstBuf.position() - pos);
        } catch (CharacterCodingException x) {
            throw new IllegalStateException(x);
        }
    }
 
开发者ID:lettuce-io,项目名称:lettuce-core,代码行数:36,代码来源:StringCodec.java

示例14: writeIntAsAscii

import io.netty.buffer.ByteBufUtil; //导入方法依赖的package包/类
public static void writeIntAsAscii(int value, @NotNull ByteBuf buffer) {
  ByteBufUtil.writeAscii(buffer, new StringBuilder().append(value));
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:4,代码来源:ChannelBufferToString.java

示例15: writeAsciiString

import io.netty.buffer.ByteBufUtil; //导入方法依赖的package包/类
@Benchmark
public void writeAsciiString() {
    buffer.resetWriterIndex();
    ByteBufUtil.writeAscii(buffer, ascii);
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:6,代码来源:ByteBufUtilBenchmark.java


注:本文中的io.netty.buffer.ByteBufUtil.writeAscii方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。