本文整理汇总了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]);
}
}
示例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);
}
}
示例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));
}
示例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));
}
示例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);
}
示例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));
}
示例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());
}
示例8: serialize
import akka.util.ByteString; //导入方法依赖的package包/类
protected ByteString serialize(EventEnvelope e) {
return ByteString.fromArray(serializer.toProtobuf(e).toByteArray());
}
示例9: setArrayData
import akka.util.ByteString; //导入方法依赖的package包/类
/**
* Sets bulk string data using a byte array.
*/
public void setArrayData(byte[] b) {
data = ByteString.fromArray(b);
}
示例10: Decoder
import akka.util.ByteString; //导入方法依赖的package包/类
public Decoder(byte[] data) {
this.data = ByteString.fromArray(data);
}