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


Java ByteString.fromArray方法代码示例

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


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

示例1: testHostIdentification

import akka.util.ByteString; //导入方法依赖的package包/类
@Test
public void testHostIdentification() {
    final GeneratedMessage protobufMessage = Messages.HostIdentification.getDefaultInstance();
    final AggregationMessage message = AggregationMessage.create(protobufMessage);
    Assert.assertNotNull(message);
    Assert.assertSame(protobufMessage, message.getMessage());

    final Buffer vertxBuffer = message.serialize();
    final byte[] messageBuffer = vertxBuffer.getBytes();
    final byte[] protobufBuffer = protobufMessage.toByteArray();
    ByteString.fromArray(vertxBuffer.getBytes());

    // Assert length
    Assert.assertEquals(protobufBuffer.length + 5, messageBuffer.length);
    Assert.assertEquals(protobufBuffer.length + 5, vertxBuffer.getInt(0));
    Assert.assertEquals(protobufBuffer.length + 5, message.getLength());

    // Assert payload type
    Assert.assertEquals(1, messageBuffer[4]);

    // Assert the payload was not corrupted
    for (int i = 0; i < protobufBuffer.length; ++i) {
        Assert.assertEquals(protobufBuffer[i], messageBuffer[i + 5]);
    }
}
 
开发者ID:ArpNetworking,项目名称:metrics-aggregator-daemon,代码行数:26,代码来源:AggregationMessageTest.java

示例2: encodeStyleBody

import akka.util.ByteString; //导入方法依赖的package包/类
private static ByteString encodeStyleBody (final String style) {
	if (style == null || style.isEmpty ()) {
		return ByteString.empty ();
	}
	
	try (final ByteArrayOutputStream output = new ByteArrayOutputStream ()) {
		try (final GZIPOutputStream gzipStream = new GZIPOutputStream (output)) {
			try (final Writer writer = new OutputStreamWriter (gzipStream, Charset.forName ("UTF-8"))) {
				writer.write (style);
			}
		}
		
		return ByteString.fromArray (output.toByteArray ());
	} catch (IOException e) {
		throw new RuntimeException (e);
	}
}
 
开发者ID:IDgis,项目名称:geo-publisher,代码行数:18,代码来源:Style.java

示例3: parseRecords

import akka.util.ByteString; //导入方法依赖的package包/类
private static List<Record> parseRecords(
        final String fileName,
        final Parser<List<Record>, HttpRequest> parser)
        throws ParsingException, IOException {
    final ByteString body =
            ByteString.fromArray(Resources.toByteArray(Resources.getResource(ProtobufV1ToRecordParserTest.class, fileName)));
    return parser.parse(new HttpRequest(ImmutableMultimap.of(), body));
}
 
开发者ID:ArpNetworking,项目名称:metrics-aggregator-daemon,代码行数:9,代码来源:ProtobufV1ToRecordParserTest.java

示例4: parseRecords

import akka.util.ByteString; //导入方法依赖的package包/类
private static List<Record> parseRecords(
        final String fileName,
        final Parser<List<Record>, HttpRequest> parser)
        throws ParsingException, IOException {
    final ByteString body =
            ByteString.fromArray(Resources.toByteArray(Resources.getResource(ProtobufV2ToRecordParserTest.class, fileName)));
    return parser.parse(new HttpRequest(ImmutableMultimap.of(), body));
}
 
开发者ID:ArpNetworking,项目名称:metrics-aggregator-daemon,代码行数:9,代码来源:ProtobufV2ToRecordParserTest.java

示例5: stringToBytes

import akka.util.ByteString; //导入方法依赖的package包/类
/**
 * Attempts to encode the string to a byte array using the default encoding.
 */
public static ByteString stringToBytes(String str) {
    byte[] strbytes;
    try {
        strbytes = str.getBytes(charset);
    } catch (UnsupportedEncodingException e) {
        strbytes = str.getBytes();
    }

    return ByteString.fromArray(strbytes);
}
 
开发者ID:connor4312,项目名称:HubSub,代码行数:14,代码来源:Builder.java

示例6: parseFile

import akka.util.ByteString; //导入方法依赖的package包/类
private static List<Record> parseFile(final String fileName, final ImmutableMultimap<String, String> headers)
        throws IOException, ParsingException {
    final ByteString body =
            ByteString.fromArray(Resources.toByteArray(Resources.getResource(CollectdJsonToRecordParser.class, fileName)));
    return new CollectdJsonToRecordParser().parse(new HttpRequest(headers, body));
}
 
开发者ID:ArpNetworking,项目名称:metrics-aggregator-daemon,代码行数:7,代码来源:CollectdJsonToRecordParserTest.java

示例7: serialize

import akka.util.ByteString; //导入方法依赖的package包/类
/**
 * Serializes the given akka event envelope into actual bytes that will become an HTTP chunk in the response.
 */
protected ByteString serialize(EventEnvelope envelope) {
    return ByteString.fromArray(serializer.toProtobuf(envelope).toByteArray());
}
 
开发者ID:Tradeshift,项目名称:ts-reaktive,代码行数:7,代码来源:EventRoute.java

示例8: serialize

import akka.util.ByteString; //导入方法依赖的package包/类
protected ByteString serialize(EventEnvelope e) {
    return ByteString.fromArray(serializer.toProtobuf(e).toByteArray());
}
 
开发者ID:Tradeshift,项目名称:ts-reaktive,代码行数:4,代码来源:WebSocketDataCenterClient.java

示例9: setArrayData

import akka.util.ByteString; //导入方法依赖的package包/类
/**
 * Sets bulk string data using a byte array.
 */
public void setArrayData(byte[] b) {
    data = ByteString.fromArray(b);
}
 
开发者ID:connor4312,项目名称:HubSub,代码行数:7,代码来源:BulkStringPacket.java

示例10: Decoder

import akka.util.ByteString; //导入方法依赖的package包/类
public Decoder(byte[] data) {
    this.data = ByteString.fromArray(data);
}
 
开发者ID:connor4312,项目名称:HubSub,代码行数:4,代码来源:Decoder.java


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