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


Java ByteBuf.toString方法代码示例

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


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

示例1: getBase64EncodedString

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
/** Return a Base64-encoded string. */
private static String getBase64EncodedString(String str) {
  ByteBuf byteBuf = null;
  ByteBuf encodedByteBuf = null;
  try {
    byteBuf = Unpooled.wrappedBuffer(str.getBytes(StandardCharsets.UTF_8));
    encodedByteBuf = Base64.encode(byteBuf);
    return encodedByteBuf.toString(StandardCharsets.UTF_8);
  } finally {
    // The release is called to suppress the memory leak error messages raised by netty.
    if (byteBuf != null) {
      byteBuf.release();
      if (encodedByteBuf != null) {
        encodedByteBuf.release();
      }
    }
  }
}
 
开发者ID:spafka,项目名称:spark_deep,代码行数:19,代码来源:SparkSaslServer.java

示例2: itCanAuthenticateWithAuthLogin

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@Test
public void itCanAuthenticateWithAuthLogin() throws Exception {
  String username = "user";
  String password = "password";

  // do the initial request, which just includes the username
  session.authLogin("user", "password");

  verify(channel).writeAndFlush(new DefaultSmtpRequest("AUTH", "LOGIN", encodeBase64(username)));

  // now the second request, which sends the password
  responseFuture.complete(Lists.newArrayList(INTERMEDIATE_RESPONSE));

  // this is sent to the second invocation of writeAndFlush
  ArgumentCaptor<Object> bufCaptor = ArgumentCaptor.forClass(Object.class);
  verify(channel, times(2)).writeAndFlush(bufCaptor.capture());
  ByteBuf capturedBuffer = (ByteBuf) bufCaptor.getAllValues().get(1);

  String actualString = capturedBuffer.toString(0, capturedBuffer.readableBytes(), StandardCharsets.UTF_8);
  assertThat(actualString).isEqualTo(encodeBase64(password) + "\r\n");
}
 
开发者ID:HubSpot,项目名称:NioSmtpClient,代码行数:22,代码来源:SmtpSessionTest.java

示例3: readLongString

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@Override
public String readLongString(ByteBuf source) {
  int len = readInt(source);
  String str = source.toString(source.readerIndex(), len, CharsetUtil.UTF_8);
  source.readerIndex(source.readerIndex() + len);
  return str;
}
 
开发者ID:datastax,项目名称:simulacron,代码行数:8,代码来源:ByteBufCodec.java

示例4: split

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@Override
public Iterable<String> split(final ByteBuf buffer, final Charset charset, final boolean includeRemainingData) {
    return () -> new AbstractIterator<String>() {
        @Override
        protected String computeNext() {
            ByteBuf fullLine = null;
            try {
                if (!buffer.isReadable()) {
                    return endOfData();
                }
                final int i = buffer.forEachByte(ByteBufProcessor.FIND_CRLF);
                if (i == -1) {
                    if (includeRemainingData) {
                        final ByteBuf remaining = buffer.readBytes(buffer.readableBytes());
                        return remaining.toString(charset);
                    } else {
                        return endOfData();
                    }
                }
                fullLine = buffer.readBytes(i);
                // Strip the \r/\n bytes from the buffer.
                final byte readByte = buffer.readByte(); // the \r or \n byte
                if (readByte == '\r') {
                    buffer.readByte(); // the \n byte if previous was \r
                }
                return fullLine.toString(charset);
            } finally {
                buffer.discardReadBytes();
                if (fullLine != null) {
                    fullLine.release();
                }

            }
        }
    };
}
 
开发者ID:DevOpsStudio,项目名称:Re-Collector,代码行数:37,代码来源:NewlineChunkSplitter.java

示例5: readUTF8String

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
/**
 * Read a UTF8 string from the byte buffer.
 * It is encoded as <varint length>[<UTF8 char bytes>]
 *
 * @param from The buffer to read from
 * @return The string
 */
public static String readUTF8String(ByteBuf from)
{
    int len = readVarInt(from,2);
    String str = from.toString(from.readerIndex(), len, Charsets.UTF_8);
    from.readerIndex(from.readerIndex() + len);
    return str;
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:15,代码来源:ByteBufUtils.java

示例6: readUTF8

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
public static String readUTF8(ByteBuf in) {
    ByteBuf buffer = in.alloc().buffer();
    byte b;
    while (in.readableBytes() > 0 && (b = in.readByte()) != 0) {
        buffer.writeByte(b);
    }

    return buffer.toString(Charsets.UTF_8);
}
 
开发者ID:AlexMog,项目名称:SurvivalMMO,代码行数:10,代码来源:Packet.java

示例7: validatePayload

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
public static String validatePayload(SessionId sessionId, ByteBuf payloadData) throws AdaptorException {
  try {
    String payload = payloadData.toString(UTF8);
    if (payload == null) {
      log.warn("[{}] Payload is empty!", sessionId.toUidStr());
      throw new AdaptorException(new IllegalArgumentException("Payload is empty!"));
    }
    return payload;
  } finally {
    payloadData.release();
  }
}
 
开发者ID:osswangxining,项目名称:iotplatform,代码行数:13,代码来源:JsonMqttAdaptor.java

示例8: readStatus

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
/**
 * Get the read status
 *
 * @param inStream to read
 * @throws org.apache.hadoop.ipc.RemoteException if status was not success
 */
private static void readStatus(ByteBuf inStream) throws RemoteException {
  int status = inStream.readInt(); // read status
  if (status != SaslStatus.SUCCESS.state) {
    throw new RemoteException(inStream.toString(Charset.forName("UTF-8")),
        inStream.toString(Charset.forName("UTF-8")));
  }
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:14,代码来源:SaslClientHandler.java

示例9: decodeString

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
private static Result<String> decodeString(ByteBuf buffer, int minBytes, int maxBytes) {
    final Result<Integer> decodedSize = decodeMsbLsb(buffer);
    int size = decodedSize.value;
    int numberOfBytesConsumed = decodedSize.numberOfBytesConsumed;
    if (size < minBytes || size > maxBytes) {
        buffer.skipBytes(size);
        numberOfBytesConsumed += size;
        return new Result<>(null, numberOfBytesConsumed);
    }
    ByteBuf buf = buffer.readBytes(size);
    numberOfBytesConsumed += size;
    return new Result<>(buf.toString(CharsetUtil.UTF_8), numberOfBytesConsumed);
}
 
开发者ID:12315jack,项目名称:j1st-mqtt,代码行数:14,代码来源:MqttDecoder.java

示例10: channelRead

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
/**
 *@description 接收客户端的请求数据
 *@time 创建时间:2017年7月24日下午2:30:30
 *@param ctx
 *@param msg
 *@throws Exception
 *@author dzn
 */
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
    if(msg instanceof ByteBuf){
        ByteBuf req = (ByteBuf)msg;
        String content = req.toString(Charset.defaultCharset());
        System.out.println("接收到ByteBuf类型的请求数据 : " + content);
        ctx.channel().writeAndFlush(msg);
    }else if(msg instanceof String){
        System.out.println("接收到String类型的请求数据 : " + msg.toString());
        ctx.channel().writeAndFlush(msg + "\r\n");
        System.out.println("向客户端返回响应数据 : " + msg);
    }
}
 
开发者ID:SnailFastGo,项目名称:netty_op,代码行数:22,代码来源:TimeServerHandler.java

示例11: decode

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@Override
protected void decode(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf,
	List<Object> list) throws Exception {
	String rawData = byteBuf.toString(CharsetUtil.UTF_8);
	
	HTTPRequest request = HTTPRequestParser.parseRequest(rawData);
	
	list.add(request);
	
	byteBuf.clear();
}
 
开发者ID:D3adspaceEnterprises,项目名称:echidna,代码行数:12,代码来源:HTTPDecoder.java

示例12: execute

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
private <T> Observable<T> execute(Class<T> t,HttpRequestTemplate<ByteBuf> apiTemplate){
	
	RibbonResponse<ByteBuf> result = apiTemplate.requestBuilder().withHeader("client", "client-microservice").build()
			.withMetadata().execute();
	ByteBuf buf = result.content();
	String json = buf.toString(Charset.forName("UTF-8"));
	
	try {
		return Observable.just(mapper.readValue(json, t));
	} catch (Exception e) {
		throw new RuntimeException(e);
	}
}
 
开发者ID:diegopacheco,项目名称:Building_Effective_Microservices,代码行数:14,代码来源:RibbonMeetupClient.java

示例13: split

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@Override
public Iterable<String> split(final ByteBuf buffer, final Charset charset, final boolean includeRemainingData) {
    return () -> new AbstractIterator<String>() {
        // TODO Might throw an exception if multibyte charset is used and buffer is not complete.
        //      Use CharsetDecoder to create a CharBuffer and match on that!
        private final String inputAsString = buffer.toString(charset);
        final Matcher matcher = pattern.matcher(inputAsString);
        private int positionInString = 0;

        @Override
        protected String computeNext() {
            try {
                if (!buffer.isReadable()) {
                    return endOfData();
                }
                if (matcher.find()) {
                    int firstByte = matcher.start();
                    if (firstByte == 0) {
                        // advance further, the buffer begins with our pattern.
                        if (matcher.find()) {
                            firstByte = matcher.start();
                        } else {
                            if (!includeRemainingData) {
                                // couldn't find the end of the entry (i.e. there wasn't a next line yet)
                                return endOfData();
                            } else {
                                // couldn't find another line, but we are asked to finish up, include everything that remains
                                return getRemainingContent();
                            }
                        }
                    }
                    if (firstByte == 0) {
                        // still haven't found a non-zero length string, keep waiting for more data.
                        return endOfData();
                    }
                    final String substring = inputAsString.substring(positionInString, firstByte);
                    positionInString = firstByte;
                    buffer.skipBytes(substring.getBytes(charset).length); // TODO performance
                    return substring;
                } else {
                    if (includeRemainingData) {
                        return getRemainingContent();
                    }
                    return endOfData();
                }
            } catch (IllegalStateException e) {
                // the cause contains the CharacterCodingException from the ChannelBuffer.toString() methods
                // this usually means the buffer ended with an incomplete encoding of a unicode character.
                // WHY U SO SUCK CHARACTER ENCODINGS?
                // we need to wait until more data is available
                return endOfData();
            } finally {
                buffer.discardReadBytes();
            }
        }

        private String getRemainingContent() {
            final ByteBuf channelBuffer = buffer.readBytes(buffer.readableBytes());
            return channelBuffer.toString(charset);
        }
    };
}
 
开发者ID:DevOpsStudio,项目名称:Re-Collector,代码行数:63,代码来源:PatternChunkSplitter.java

示例14: decode

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@Override
public Object decode(ByteBuf buf, State state) {
    String status = buf.toString(CharsetUtil.UTF_8);
    buf.skipBytes(1);
    return status;
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:7,代码来源:KeyValueObjectDecoder.java

示例15: decode

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@Override
public Object decode(ByteBuf buf, State state) {
    return buf.toString(CharsetUtil.UTF_8);
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:5,代码来源:SlotsDecoder.java


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