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


Java ByteBuf.getByte方法代码示例

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


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

示例1: parseBinaryString

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
/**
 * Parses a hex encoded binary string and write to an output buffer.
 *
 * This function does not modify  the {@code readerIndex} and {@code writerIndex}
 * of the byte buffer.
 *
 * @return Index in the byte buffer just after the last written byte.
 */
public static int parseBinaryString(ByteBuf str, int strStart, int strEnd, ByteBuf out) {
  int dstEnd = 0;
  for (int i = strStart; i < strEnd; i++) {
    byte b = str.getByte(i);
    if (b == '\\'
        && strEnd > i+3
        && (str.getByte(i+1) == 'x' || str.getByte(i+1) == 'X')) {
      // ok, take next 2 hex digits.
      byte hd1 = str.getByte(i+2);
      byte hd2 = str.getByte(i+3);
      if (isHexDigit(hd1) && isHexDigit(hd2)) { // [a-fA-F0-9]
        // turn hex ASCII digit -> number
        b = (byte) ((toBinaryFromHex(hd1) << 4) + toBinaryFromHex(hd2));
        i += 3; // skip 3
      }
    }
    out.setByte(dstEnd++, b);
  }
  return dstEnd;
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:29,代码来源:DremioStringUtils.java

示例2: parseBinaryStringNoFormat

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
public static int parseBinaryStringNoFormat(ByteBuf str, int strStart, int strEnd, ByteBuf out) {
  int dstEnd = 0;

  if(((strStart - strEnd) % 2) != 0){
    throw UserException.functionError().message("Failure parsing hex string, length was not a multiple of two.").build(logger);
  }
  for (int i = strStart; i < strEnd; i+=2) {
    byte b1 = str.getByte(i);
    byte b2 = str.getByte(i+1);
    if(isHexDigit(b1) && isHexDigit(b2)){
      byte finalByte = (byte) ((toBinaryFromHex(b1) << 4) + toBinaryFromHex(b2));
      out.setByte(dstEnd++, finalByte);
    }else{
      throw UserException.functionError().message("Failure parsing hex string, one or more bytes was not a valid hex value.").build(logger);
    }
  }
  return dstEnd;
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:19,代码来源:DremioStringUtils.java

示例3: parseBinaryString

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
/**
 * In-place parsing of a hex encoded binary string.
 *
 * This function does not modify  the {@code readerIndex} and {@code writerIndex}
 * of the byte buffer.
 *
 * @return Index in the byte buffer just after the last written byte.
 */
public static int parseBinaryString(ByteBuf str, int strStart, int strEnd) {
  int length = (strEnd - strStart);
  int dstEnd = strStart;
  for (int i = strStart; i < length ; i++) {
    byte b = str.getByte(i);
    if (b == '\\'
        && length > i+3
        && (str.getByte(i+1) == 'x' || str.getByte(i+1) == 'X')) {
      // ok, take next 2 hex digits.
      byte hd1 = str.getByte(i+2);
      byte hd2 = str.getByte(i+3);
      if (isHexDigit(hd1) && isHexDigit(hd2)) { // [a-fA-F0-9]
        // turn hex ASCII digit -> number
        b = (byte) ((toBinaryFromHex(hd1) << 4) + toBinaryFromHex(hd2));
        i += 3; // skip 3
      }
    }
    str.setByte(dstEnd++, b);
  }
  return dstEnd;
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:30,代码来源:DrillStringUtils.java

示例4: channelRead

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
  // This must be a single byte buffer - after that follow the SSL handshake
  ByteBuf byteBuf = (ByteBuf) msg;
  byte b = byteBuf.getByte(0);
  byteBuf.release();
  switch (b) {
    case SSL_YES: {
      conn.upgradeToSSL(v -> {
        ctx.pipeline().remove(this);
        upgradeFuture.complete();
      });
      break;
    }
    case SSL_NO: {
      // This case is not tested as our test db is configured for SSL
      ctx.fireExceptionCaught(new Exception("Postgres does not handle SSL"));
      break;
    }
    default:
      ctx.fireExceptionCaught(new Exception("Invalid connection data"));
      break;
  }
}
 
开发者ID:vietj,项目名称:reactive-pg-client,代码行数:25,代码来源:InitiateSslHandler.java

示例5: stringLeftMatchUTF8

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
public static int stringLeftMatchUTF8(ByteBuf str, int strStart, int strEnd,
                                  ByteBuf substr, int subStart, int subEnd, int offset) {
  for (int i = strStart + offset; i <= strEnd - (subEnd - subStart); i++) {
    int j = subStart;
    for (; j< subEnd; j++) {
      if (str.getByte(i + j - subStart) != substr.getByte(j)) {
        break;
      }
    }

    if (j == subEnd  && j!= subStart) {  // found a matched substr (non-empty) in str.
      return i;   // found a match.
    }
  }

  return -1;
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:18,代码来源:StringFunctionUtil.java

示例6: utf8CharLen

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
public static int utf8CharLen(ByteBuf buffer, int idx) {
  byte firstByte = buffer.getByte(idx);
  if (firstByte >= 0) { // 1-byte char. First byte is 0xxxxxxx.
    return 1;
  } else if ((firstByte & 0xE0) == 0xC0) { // 2-byte char. First byte is 110xxxxx
    return 2;
  } else if ((firstByte & 0xF0) == 0xE0) { // 3-byte char. First byte is 1110xxxx
    return 3;
  } else if ((firstByte & 0xF8) == 0xF0) { //4-byte char. First byte is 11110xxx
    return 4;
  }
  throw new RuntimeException("Unexpected byte 0x" + Integer.toString(firstByte & 0xff, 16)
      + " at position " + idx + " encountered while decoding UTF8 string.");
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:15,代码来源:StringFunctionUtil.java

示例7: channelRead0

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@Override
protected void channelRead0(ChannelHandlerContext ctx, ByteBuf msg) {

    int remainder = msg.readableBytes() % 13;

    if (remainder == 0 && (msg.getByte(0) & 0xF0) == 0x80 & msg.getByte(1) == 0x00) {
        processByteBuf(ctx, msg);
        return;
    }

    if (remainder != 0 && index == 0 && (msg.getByte(0) & 0xF0) == 0x80 & msg.getByte(1) == 0x00) {
        logger.warn("读取到非整数个 CAN 帧");
        processByteBuf(ctx, msg);
        cacheRemainByte(msg);
        return;
    }

    if (index != 0) {
        if (cacheRemainByte(msg)) {
            ByteBuf byteBuf = Unpooled.copiedBuffer(bytes);
            if ((byteBuf.getByte(0) & 0xF0) == 0x80 & byteBuf.getByte(1) == 0x00) {
                processByteBuf(ctx, byteBuf);
            }
        }
        remainder = msg.readableBytes() % 13;
        if (remainder == 0) {
            System.out.println("lml");
        }
        if (remainder == 0 && (msg.getByte(msg.readerIndex()) & 0xF0) == 0x80 & msg.getByte(msg.readerIndex() + 1) == 0x00) {
            processByteBuf(ctx, msg);
            return;
        }
        return;
    }
}
 
开发者ID:bitkylin,项目名称:ClusterDeviceControlPlatform,代码行数:36,代码来源:CanFrameChannelInboundHandler.java

示例8: utf8CharLen

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
public static int utf8CharLen(ByteBuf buffer, int idx) {
  byte firstByte = buffer.getByte(idx);
  if (firstByte >= 0) { // 1-byte char. First byte is 0xxxxxxx.
    return 1;
  } else if ((firstByte & 0xE0) == 0xC0) { // 2-byte char. First byte is 110xxxxx
    return 2;
  } else if ((firstByte & 0xF0) == 0xE0) { // 3-byte char. First byte is 1110xxxx
    return 3;
  } else if ((firstByte & 0xF8) == 0xF0) { //4-byte char. First byte is 11110xxx
    return 4;
  }
  throw new DrillRuntimeException("Unexpected byte 0x" + Integer.toString((int)firstByte & 0xff, 16)
      + " at position " + idx + " encountered while decoding UTF8 string.");
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:15,代码来源:StringFunctionUtil.java

示例9: byteBufRelativeAccess

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
/**
 * Listing 5.6
 */
public static void byteBufRelativeAccess(ByteBuf buffer) {
    for (int i = 0; i < buffer.capacity(); i++) {
        byte b = buffer.getByte(i);
        System.out.println((char) b);
    }

}
 
开发者ID:zy416548283,项目名称:NettyStudy,代码行数:11,代码来源:ByteBufExamples.java

示例10: isTerminatedWithCrLf

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
private boolean isTerminatedWithCrLf(ByteBuf chunk) {
  int length = chunk.readableBytes();

  return length >= 2 &&
      chunk.getByte(length - 2) == CR &&
      chunk.getByte(length - 1) == LF;
}
 
开发者ID:HubSpot,项目名称:NioSmtpClient,代码行数:8,代码来源:CrlfTerminatingChunkedStream.java

示例11: findDotAtBeginningOfLine

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
private static int findDotAtBeginningOfLine(ByteBuf buffer, int startAt, byte[] previousBytes) {
  int length = buffer.readableBytes();

  if (previousBytes[0] == CR && previousBytes[1] == LF && buffer.getByte(startAt) == DOT) {
    return startAt;
  }

  if (previousBytes[1] == CR && length >= 2 && buffer.getByte(startAt) == LF && buffer.getByte(startAt + 1) == DOT) {
    return startAt + 1;
  }

  int i = startAt;
  while (++i < length) {
    i = buffer.forEachByte(i, length - i, ByteProcessor.FIND_LF);
    if (i == -1) {
      return -1;
    }

    if (buffer.getByte(i - 1) == CR) {
      if (i + 1 < length && buffer.getByte(i + 1) == DOT) {
        return i + 1;
      } else {
        continue;
      }
    }
  }

  return -1;
}
 
开发者ID:HubSpot,项目名称:NioSmtpClient,代码行数:30,代码来源:DotStuffing.java

示例12: updateTrailingBytes

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
private void updateTrailingBytes(ByteBuf chunk) {
  if (chunk.readableBytes() == 0) {
    return;
  }

  if (chunk.readableBytes() == 1) {
    trailingBytes[0] = trailingBytes[1];
    trailingBytes[1] = chunk.getByte(0);
    return;
  }

  trailingBytes[0] = chunk.getByte(chunk.readableBytes() - 2);
  trailingBytes[1] = chunk.getByte(chunk.readableBytes() - 1);
}
 
开发者ID:HubSpot,项目名称:NioSmtpClient,代码行数:15,代码来源:DotStuffingChunkedStream.java

示例13: fliterCharaters

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
/**
 * Filter the invalid characters before decoding.
 * @param in input of bytes
 * @param lastReadBytes the bytes for last decoding incomplete record
 */
private static void fliterCharaters(ByteBuf in) {
    while (in.isReadable()) {
        int ch = in.getByte(in.readerIndex());
        if ((ch != ' ') && (ch != '\n') && (ch != '\t') && (ch != '\r')) {
            break;
        } else {
            in.readByte();
        }
    }
}
 
开发者ID:shlee89,项目名称:athena,代码行数:16,代码来源:JsonRpcReaderUtil.java

示例14: channelRead

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@Override
public void channelRead(final ChannelHandlerContext ctx, final Object msg) throws Exception {
  if (msg instanceof HttpRequest) {
    HttpRequest request = (HttpRequest) msg;
    //第一次建立连接取host和端口号和处理代理握手
    if (status == 0) {
      RequestProto requestProto = ProtoUtil.getRequestProto(request);
      if (requestProto == null) { //bad request
        ctx.channel().close();
        return;
      }
      status = 1;
      this.host = requestProto.getHost();
      this.port = requestProto.getPort();
      if ("CONNECT".equalsIgnoreCase(request.method().name())) {//建立代理握手
        status = 2;
        HttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1,
            HttpProxyServer.SUCCESS);
        ctx.writeAndFlush(response);
        ctx.channel().pipeline().remove("httpCodec");
        return;
      }
    }
    interceptPipeline = buildPiepeline();
    interceptPipeline.setRequestProto(new RequestProto(host, port, isSsl));
    interceptPipeline.beforeRequest(ctx.channel(), request);
  } else if (msg instanceof HttpContent) {
    if (status != 2) {
      interceptPipeline.beforeRequest(ctx.channel(), (HttpContent) msg);
    } else {
      status = 1;
    }
  } else { //ssl和websocket的握手处理
    ByteBuf byteBuf = (ByteBuf) msg;
    if (byteBuf.getByte(0) == 22) {//ssl握手
      isSsl = true;
      SslContext sslCtx = SslContextBuilder
          .forServer(serverConfig.getServerPriKey(), CertPool.getCert(this.host, serverConfig))
          .build();
      ctx.pipeline().addFirst("httpCodec", new HttpServerCodec());
      ctx.pipeline().addFirst("sslHandle", sslCtx.newHandler(ctx.alloc()));
      //重新过一遍pipeline,拿到解密后的的http报文
      ctx.pipeline().fireChannelRead(msg);
      return;
    }
    handleProxyData(ctx.channel(), msg, false);
  }
}
 
开发者ID:monkeyWie,项目名称:proxyee,代码行数:49,代码来源:HttpProxyServerHandle.java

示例15: decode

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@Override
protected void decode ( final ChannelHandlerContext ctx, final ByteBuf in, final List<Object> out ) throws Exception
{
    if ( logger.isTraceEnabled () )
    {
        logger.trace ( "decode - bytes: {}", ByteBufUtil.hexDump ( in ) );
    }

    if ( in.readableBytes () < Constants.APCI_MIN_LENGTH )
    {
        return;
    }

    final byte start = in.getByte ( in.readerIndex () + 0 );
    if ( start != Constants.START_BYTE )
    {
        throw new DecoderException ( String.format ( "ACPI must start with 0x%02x but did with 0x%02x", Constants.START_BYTE, start ) );
    }

    final short len = in.getUnsignedByte ( in.readerIndex () + 1 );

    if ( len > Constants.APCI_MAX_DATA_LENGTH )
    {
        throw new DecoderException ( String.format ( "APCI has a maximum length of %s bytes, but we received %s", Constants.APCI_MAX_DATA_LENGTH, len ) );
    }

    if ( in.readableBytes () < len + 2 )
    {
        return;
    }

    // we have the full InformationTransfer

    // skip start & len
    in.skipBytes ( 2 );

    // read control fields
    final ByteBuf controlFields = in.readSlice ( 4 );

    final ByteBuf data;
    if ( len > 4 )
    {
        data = Unpooled.copiedBuffer ( in.readSlice ( len - 4 ) ).order ( ByteOrder.LITTLE_ENDIAN );
    }
    else
    {
        data = null;
    }

    // now add the PDU

    out.add ( decode ( controlFields, data ) );
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:54,代码来源:APDUDecoder.java


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