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


Java ByteBufUtil.getBytes方法代码示例

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


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

示例1: toByteArray

import io.netty.buffer.ByteBufUtil; //导入方法依赖的package包/类
/**
 * Returns this aggregation as a byte array
 * @return a byte array
 */
public byte[] toByteArray() {
	final ByteBuf b = BufferManager.getInstance().buffer(size==-1 ? 128 : size);
	try {
		b.writeByte(sticky ? 1 : 0);
		b.writeByte(doubleType ? 1 : 0);
		b.writeLong(createTime);
		b.writeLong(period);
		b.writeByte(periodUnit.ordinal());
		values.position(0);
		b.writeBytes(values);
		b.writeByte(tags.size());
		BufferManager.writeUTF(metricName, b);
		for(Map.Entry<String, String> entry: tags.entrySet()) {
			BufferManager.writeUTF(entry.getKey(), b);
			BufferManager.writeUTF(entry.getValue(), b);
		}
		return ByteBufUtil.getBytes(b);
	} finally {
		try { b.release(); } catch (Exception x) {/* No Op */}
	}
}
 
开发者ID:nickman,项目名称:HeliosStreams,代码行数:26,代码来源:StreamedMetricAggregation.java

示例2: toByteArray

import io.netty.buffer.ByteBufUtil; //导入方法依赖的package包/类
/**
 * Returns a byte array containing the serialized streammetric
 * @return a byte array 
 */
@Override
public byte[] toByteArray() {
	final ByteBuf buff = BufferManager.getInstance().directBuffer(byteSize);
	try {
		buff.writeByte(TYPE_CODE);
		writeByteArray(buff);
		if(isDoubleValue) {
			buff.writeByte(0);
			buff.writeDouble(doubleValue);
		} else {
			buff.writeByte(1);
			buff.writeLong(longValue);
		}
		return ByteBufUtil.getBytes(buff, 0, buff.readableBytes());
	} finally {
		try { buff.release(); } catch (Exception x) {/* No Op */}
	}
}
 
开发者ID:nickman,项目名称:HeliosStreams,代码行数:23,代码来源:StreamedMetricValue.java

示例3: parseTemplatesShallow

import io.netty.buffer.ByteBufUtil; //导入方法依赖的package包/类
/**
 * Like above, but only retrieves the bytes and template ids
 */
public static List<Map.Entry<Integer, byte[]>> parseTemplatesShallow(ByteBuf bb) {
    final ImmutableList.Builder<Map.Entry<Integer, byte[]>> templates = ImmutableList.builder();
    int len = bb.readUnsignedShort();

    int p = 4; // flow set id and length field itself
    while (p < len) {
        final int start = bb.readerIndex();
        final int templateId = bb.readUnsignedShort();
        final int fieldCount = bb.readUnsignedShort();
        final ImmutableList.Builder<NetFlowV9FieldDef> fieldDefs = ImmutableList.builder();
        for (int i = 0; i < fieldCount; i++) {
            int fieldType = bb.readUnsignedShort();
            int fieldLength = bb.readUnsignedShort();
        }
        final byte[] bytes = ByteBufUtil.getBytes(bb, start, bb.readerIndex() - start);
        final Map.Entry<Integer, byte[]> template = Maps.immutableEntry(templateId, bytes);
        templates.add(template);

        p += 4 + fieldCount * 4;
    }

    return templates.build();
}
 
开发者ID:Graylog2,项目名称:graylog-plugin-netflow,代码行数:27,代码来源:NetFlowV9Parser.java

示例4: fetchDecoderOutput

import io.netty.buffer.ByteBufUtil; //导入方法依赖的package包/类
private byte[] fetchDecoderOutput() {
    CompositeByteBuf decoded = Unpooled.compositeBuffer();
    for (;;) {
        ByteBuf buf = decoder.readInbound();
        if (buf == null) {
            break;
        }
        if (!buf.isReadable()) {
            buf.release();
            continue;
        }
        decoded.addComponent(true, buf);
    }
    byte[] ret = ByteBufUtil.getBytes(decoded);
    decoded.release();
    return ret;
}
 
开发者ID:line,项目名称:armeria,代码行数:18,代码来源:ZlibStreamDecoder.java

示例5: assertReadHttpMessageHasContent

import io.netty.buffer.ByteBufUtil; //导入方法依赖的package包/类
private void assertReadHttpMessageHasContent(EmbeddedChannel embeddedChannel, String expectedContent) {
    FullHttpResponse response = (FullHttpResponse) embeddedChannel.outboundMessages().poll();
    assertNotNull("Expected response to exist, maybe you did not wait long enough?", response);
    assertNotNull("Expected response to have content " + expectedContent, response.content());
    String data = new String(ByteBufUtil.getBytes(response.content()), StandardCharsets.UTF_8);
    assertThat(data, is(expectedContent));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:8,代码来源:Netty4HttpPipeliningHandlerTests.java

示例6: toByteArray

import io.netty.buffer.ByteBufUtil; //导入方法依赖的package包/类
/**
 * Returns a byte array containing the serialized streammetric
 * @return a byte array 
 */
public byte[] toByteArray() {
	final ByteBuf buff = BufferManager.getInstance().directBuffer(byteSize);
	try {
		buff.writeByte(TYPE_CODE);
		writeByteArray(buff);
		return ByteBufUtil.getBytes(buff, 0, buff.readableBytes());
				
	} finally {
		try { buff.release(); } catch (Exception x) {/* No Op */}
	}
}
 
开发者ID:nickman,项目名称:HeliosStreams,代码行数:16,代码来源:StreamedMetric.java

示例7: serialize

import io.netty.buffer.ByteBufUtil; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 * @see org.apache.kafka.common.serialization.Serializer#serialize(java.lang.String, java.lang.Object)
 */
@Override
public byte[] serialize(final String topic, final ByteBuf data) {
	final int len = data.readableBytes();
	try {
		final byte[] b =  ByteBufUtil.getBytes(data, 0, data.readableBytes());
		System.err.println("==== ByteBuf Ser: was:" + len + ", final:" + b.length);
		return b;
	} finally {
		data.release();
	}
}
 
开发者ID:nickman,项目名称:HeliosStreams,代码行数:16,代码来源:ByteBufSerde.java

示例8: channelRead

import io.netty.buffer.ByteBufUtil; //导入方法依赖的package包/类
@Override
public void channelRead(final ChannelHandlerContext ctx, final Object msg) {
	ByteBuf buf = (ByteBuf) msg;
	String data = new String(ByteBufUtil.getBytes(buf));
	ByteBuf bufData = buf;
	
	
	if(Config.getInstance().isEncrypted() && data.contains(StringCache.HTTP)){
		data = data.replace(StringCache.HTTP, StringCache.HTTPS);
		bufData = Unpooled.wrappedBuffer(data.getBytes());
	}
	
	ProxyFrontendHandler.writeToFile("backend", ByteBufUtil.getBytes(bufData));
	
	
	inboundChannel.writeAndFlush(bufData).addListener(new ChannelFutureListener() {
		@Override
		public void operationComplete(ChannelFuture future) {
			if (future.isSuccess()) {
				ctx.channel().read();
				
			} else {
				future.channel().close();
			}
		}
	});

}
 
开发者ID:mwambler,项目名称:xockets.io,代码行数:29,代码来源:ProxyBackendHandler.java

示例9: channelRead

import io.netty.buffer.ByteBufUtil; //导入方法依赖的package包/类
@Override
public void channelRead(final ChannelHandlerContext ctx, final Object msg) throws Exception {
    final ByteBuf byteBuf = (ByteBuf) msg;
    final byte[] bytes = ByteBufUtil.getBytes(byteBuf);
    final String str = new String(bytes, CharsetUtil.UTF_8);

    strFuture.set(str);
}
 
开发者ID:kgusarov,项目名称:spring-boot-netty,代码行数:9,代码来源:MultipleServersIntegrationTest.java

示例10: parseOptionTemplateShallow

import io.netty.buffer.ByteBufUtil; //导入方法依赖的package包/类
public static Map.Entry<Integer, byte[]> parseOptionTemplateShallow(ByteBuf bb) {
    final int start = bb.readerIndex();
    int length = bb.readUnsignedShort();
    final int templateId = bb.readUnsignedShort();

    int optionScopeLength = bb.readUnsignedShort();
    int optionLength = bb.readUnsignedShort();

    int p = bb.readerIndex();
    int endOfScope = p + optionScopeLength;
    int endOfOption = endOfScope + optionLength;
    int endOfTemplate = p - 10 + length;

    while (bb.readerIndex() < endOfScope) {
        int scopeType = bb.readUnsignedShort();
        int scopeLength = bb.readUnsignedShort();
    }

    // skip padding
    bb.readerIndex(endOfScope);

    while (bb.readerIndex() < endOfOption) {
        int optType = bb.readUnsignedShort();
        int optLength = bb.readUnsignedShort();
    }

    // skip padding
    bb.readerIndex(endOfTemplate);

    final byte[] bytes = ByteBufUtil.getBytes(bb, start, bb.readerIndex() - start);
    return Maps.immutableEntry(templateId, bytes);
}
 
开发者ID:Graylog2,项目名称:graylog-plugin-netflow,代码行数:33,代码来源:NetFlowV9Parser.java

示例11: convertToRawMessage

import io.netty.buffer.ByteBufUtil; //导入方法依赖的package包/类
private RawMessage convertToRawMessage(CodecAggregator.Result result, SocketAddress remoteAddress) {
    final ByteBuf buffer = result.getMessage();
    assertThat(buffer).isNotNull();

    final byte[] payload = ByteBufUtil.getBytes(buffer);

    return new RawMessage(payload, (InetSocketAddress) remoteAddress);
}
 
开发者ID:Graylog2,项目名称:graylog-plugin-netflow,代码行数:9,代码来源:NetflowV9CodecAggregatorTest.java

示例12: uncompressedFrame

import io.netty.buffer.ByteBufUtil; //导入方法依赖的package包/类
public static byte[] uncompressedFrame(ByteBuf proto) {
    ByteBuf buf = Unpooled.buffer();
    buf.writeByte(0);
    buf.writeInt(proto.readableBytes());
    buf.writeBytes(proto);
    proto.release();
    byte[] result = ByteBufUtil.getBytes(buf);
    buf.release();
    return result;
}
 
开发者ID:line,项目名称:armeria,代码行数:11,代码来源:GrpcTestUtil.java

示例13: compressedFrame

import io.netty.buffer.ByteBufUtil; //导入方法依赖的package包/类
public static byte[] compressedFrame(ByteBuf uncompressed) throws Exception {
    ByteBuf compressed = Unpooled.buffer();
    try (ByteBufInputStream is = new ByteBufInputStream(uncompressed, true);
         GZIPOutputStream os = new GZIPOutputStream(new ByteBufOutputStream(compressed))) {
        ByteStreams.copy(is, os);
    }
    ByteBuf buf = Unpooled.buffer();
    buf.writeByte(1);
    buf.writeInt(compressed.readableBytes());
    buf.writeBytes(compressed);
    compressed.release();
    byte[] result = ByteBufUtil.getBytes(buf);
    buf.release();
    return result;
}
 
开发者ID:line,项目名称:armeria,代码行数:16,代码来源:GrpcTestUtil.java

示例14: array

import io.netty.buffer.ByteBufUtil; //导入方法依赖的package包/类
@Override
public byte[] array() {
    if (buf.hasArray()) {
        return buf.array();
    } else {
        return ByteBufUtil.getBytes(buf);
    }
}
 
开发者ID:line,项目名称:armeria,代码行数:9,代码来源:ByteBufHttpData.java

示例15: processDevicePublish

import io.netty.buffer.ByteBufUtil; //导入方法依赖的package包/类
private void processDevicePublish(ChannelHandlerContext ctx, MqttPublishMessage mqttMsg, String topicName,
    int msgId) {
  // AdaptorToSessionActorMsg msg = null;
  int refCnt = mqttMsg.refCnt();
  int messageId = mqttMsg.variableHeader().messageId();
  log.info("[{}] refCnt: [{}], messageId: [{}]", sessionId, refCnt, messageId);
  MqttPublishMessage retainedDuplicate = mqttMsg.retainedDuplicate();
  String kafkaOutboundTopic = null;
  try {
    if (topicName.equals(DEVICE_TELEMETRY_TOPIC)) {
      // msg = adaptor.convertToActorMsg(deviceSessionCtx,
      // POST_TELEMETRY_REQUEST, mqttMsg);
      kafkaOutboundTopic = KafkaTopics.DEVICE_TELEMETRY_TOPIC;
    } else if (topicName.equals(DEVICE_ATTRIBUTES_TOPIC)) {
      kafkaOutboundTopic = KafkaTopics.DEVICE_ATTRIBUTES_TOPIC;
      // msg = adaptor.convertToActorMsg(deviceSessionCtx,
      // POST_ATTRIBUTES_REQUEST, mqttMsg);

      // MqttMessage createSubscribeResponseMessage =
      // createSubscribeResponseMessage(msgId);
      //// System.out.println(createSubscribeResponseMessage.payload());
      // ctx.writeAndFlush(createSubscribeResponseMessage);

    } else if (topicName.startsWith(DEVICE_ATTRIBUTES_REQUEST_TOPIC_PREFIX)) {
      // msg = adaptor.convertToActorMsg(deviceSessionCtx,
      // GET_ATTRIBUTES_REQUEST, mqttMsg);
      kafkaOutboundTopic = KafkaTopics.DEVICE_ATTRIBUTES_REQUEST_TOPIC_PREFIX;
      if (msgId >= 0) {
        ctx.writeAndFlush(createMqttPubAckMsg(msgId));
      }
    } else if (topicName.startsWith(DEVICE_RPC_RESPONSE_TOPIC)) {
      // msg = adaptor.convertToActorMsg(deviceSessionCtx,
      // TO_DEVICE_RPC_RESPONSE, mqttMsg);
      kafkaOutboundTopic = KafkaTopics.DEVICE_ATTRIBUTES_RESPONSE_TOPIC_PREFIX;
      if (msgId >= 0) {
        ctx.writeAndFlush(createMqttPubAckMsg(msgId));
      }
    } else if (topicName.startsWith(DEVICE_RPC_REQUESTS_TOPIC)) {
      // msg = adaptor.convertToActorMsg(deviceSessionCtx,
      // TO_SERVER_RPC_REQUEST, mqttMsg);
      kafkaOutboundTopic = KafkaTopics.DEVICE_RPC_REQUESTS_TOPIC;
      if (msgId >= 0) {
        ctx.writeAndFlush(createMqttPubAckMsg(msgId));
      }
    }
  } catch (Exception e) {
    log.warn("[{}] Failed to process publish msg [{}][{}]", sessionId, topicName, msgId, e);
  }
  if (kafkaOutboundTopic != null) {
    String payload = new String(ByteBufUtil.getBytes(retainedDuplicate.payload()));

    Set<ChannelEntity> channelEntitys = MemoryMetaPool.getChannelByTopics(topicName);
    if (channelEntitys != null) {
      for (ChannelEntity channelEntity : channelEntitys) {
        log.info("PUBLISH to ChannelEntity topic = " + topicName + " payload = " + payload);
        channelEntity.write(retainedDuplicate);
      }
    }

    Device device = deviceSessionCtx.getDevice();
    if (device != null && device.getId() != null) {
      // BasicToDeviceActorSessionMsg basicToDeviceActorSessionMsg = new
      // BasicToDeviceActorSessionMsg(
      // device, msg);
      JsonObject root = new JsonObject();
      JsonElement jsonElement = new JsonParser().parse(payload);
      root.add("d", jsonElement);
      root.addProperty("messageId", messageId);
      log.info("[{}] msg: {}", sessionId, root.toString());

      this.msgProducer.send(kafkaOutboundTopic, device.getId().toString(), root.toString());
    }
    // processor.process(basicToDeviceActorSessionMsg);
  } else {
    log.info("[{}] Closing current session due to invalid publish msg [{}][{}]", sessionId, topicName, msgId);
    ctx.close();
  }
}
 
开发者ID:osswangxining,项目名称:iothub,代码行数:79,代码来源:MqttTransportHandler.java


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