當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。