本文整理汇总了Java中akka.util.ByteString类的典型用法代码示例。如果您正苦于以下问题:Java ByteString类的具体用法?Java ByteString怎么用?Java ByteString使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ByteString类属于akka.util包,在下文中一共展示了ByteString类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: indexOf
import akka.util.ByteString; //导入依赖的package包/类
/**
* Returns the index of needle in the haystack.
*
* @param needle byte string to search for
* @param haystack byte string to search in
* @return the position of the needle, or -1 if not found.
*/
public static int indexOf(ByteString needle, ByteString haystack) {
byte[] n = needle.toArray();
byte[] h = haystack.toArray();
OUTER:
for (int i = 0; i <= h.length - n.length; i++) {
for (int j = 0; j < n.length; j++) {
if (h[i+j] != n[j]) {
continue OUTER;
}
}
return i;
}
return -1;
}
示例2: processRecords
import akka.util.ByteString; //导入依赖的package包/类
private void processRecords(final ByteString data) {
try {
// NOTE: The parsing occurs in the actor itself which can become a bottleneck
// if there are more records to be parsed then a single thread can handle.
final List<Record> records = _sink.getParser().parse(data.toByteBuffer());
LOGGER.trace()
.setMessage("Parsed records")
.addData("name", _sink.getName())
.addData("records", records.size())
.addData("remoteAddress", _remoteAddress.getAddress().getHostAddress())
.addData("remotePort", _remoteAddress.getPort())
.log();
records.forEach(_sink::notify);
} catch (final ParsingException e) {
BAD_REQUEST_LOGGER.warn()
.setMessage("Error processing records")
.addData("name", _sink.getName())
.addData("remoteAddress", _remoteAddress.getAddress().getHostAddress())
.addData("remotePort", _remoteAddress.getPort())
.setThrowable(e)
.log();
}
}
示例3: 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]);
}
}
示例4: flow
import akka.util.ByteString; //导入依赖的package包/类
private Flow<Message,Message,?> flow() {
return Flow.<Message>create()
.map(msg -> {
if (msg.isText()) {
log.warn("Ignoring unexpected text-kind web socket message {}", msg);
return Option.<Query.EventEnvelope>none();
} else {
return Option.<Query.EventEnvelope>some(Query.EventEnvelope.parseFrom(msg.asBinaryMessage().getStrictData().toArray()));
}
})
.filter(o -> o.isDefined())
.map(o -> o.get())
.mapAsync(maxInFlight, e -> ask(shardRegion, e, timeout))
.map(resp -> (Long) resp)
.map(l -> BinaryMessage.create(ByteString.fromArray(EventsPersisted.newBuilder().setOffset(l).build().toByteArray())));
}
示例5: onReceive
import akka.util.ByteString; //导入依赖的package包/类
@Override
public void onReceive(Object msg) throws Exception {
if (msg instanceof Udp.Bound) {
log.info("[ARDRONE2NAVDATA] Socket ARDRone 2.0 bound.");
senderRef = sender();
// Setup handlers
getContext().become(ReceiveBuilder
.match(Udp.Received.class, s -> processRawData(s.data()))
.match(Udp.Unbound.class, s -> getContext().stop(getSelf()))
.match(StopMessage.class, s -> stop())
.matchAny(s -> {
log.error("[ARDRONE2NAVDATA] No protocol handler for [{}]", s.getClass().getCanonicalName());
unhandled(s);
})
.build());
// Enable nav data
sendNavData(ByteString.fromArray(TRIGGER_NAV_BYTES));
parent.tell(new InitNavDataMessage(), getSelf());
} else {
log.error("[ARDRONE2NAVDATA] Unhandled message received ({})", msg.toString());
unhandled(msg);
}
}
示例6: extractPacket
import akka.util.ByteString; //导入依赖的package包/类
private Packet extractPacket(Frame frame) {
ByteIterator it = frame.getData().iterator();
byte type = it.getByte();
byte cmdClass = it.getByte();
short cmd = it.getShort(FrameHelper.BYTE_ORDER);
if (cmd < 0) {
log.warning("Command sign bit overflow.");
} else {
int payloadLen = frame.getData().length() - 4;
ByteString payload = null;
if (payloadLen > 0) {
payload = frame.getData().slice(4, 4 + payloadLen);
}
return new Packet(type, cmdClass, cmd, payload);
}
return null;
}
示例7: sendDataOnChannel
import akka.util.ByteString; //导入依赖的package包/类
private void sendDataOnChannel(Packet packet, DataChannel channel) {
ByteString data = PacketHelper.buildPacket(packet);
Frame frame = channel.createFrame(data);
if (channel.getType() == FrameType.DATA_WITH_ACK) {
long time = System.currentTimeMillis();
Frame f = channel.sendFrame(frame, time);
if (f != null) {
sendData(FrameHelper.getFrameData(f));//TODO: only compute once
}
} else if (channel.getType() == FrameType.DATA) {
sendData(FrameHelper.getFrameData(frame));
log.debug("Sent packet ([{}], [{}], [{}]) on channel [{}]",
packet.getType(), packet.getCommandClass(), packet.getCommand(), channel.getId());
} else {
log.warning("Sending data over invalid channel type. ID = [{}]", channel.getId());
}
}
示例8: processData
import akka.util.ByteString; //导入依赖的package包/类
private void processData(ByteString b) throws IOException {
String data = b.decodeString("UTF-8");
ObjectMapper m = new ObjectMapper();
JsonNode node = m.readTree(data);
int status = node.path("status").intValue();
if(status != 0){
log.error("Drone did not acknowledge our discovery. Other controller might be in control.");
listener.tell(new DroneDiscoveredMessage(DroneDiscoveredMessage.DroneDiscoveryStatus.FAILED), getSelf());
} else {
int c2d_port = node.path("c2d_port").intValue();
int arstream_fragment_size = node.path("arstream_fragment_size").intValue();
int arstream_fragment_maximum_number = node.path("arstream_fragment_maximum_number").intValue();
int arstream_max_ack_interval = node.path("arstream_max_ack_interval").intValue();
int c2d_update_port = node.path("c2d_update_port").intValue();
int c2d_user_port = node.path("c2d_user_port").intValue();
log.info("Discovery succes, c2d port = [{}]", c2d_port);
listener.tell(new DroneDiscoveredMessage(DroneDiscoveredMessage.DroneDiscoveryStatus.SUCCESS, c2d_port, commandPort,
arstream_fragment_size, arstream_fragment_maximum_number, arstream_max_ack_interval,
c2d_update_port, c2d_user_port ), getSelf());
}
sentResult = true;
}
示例9: decode
import akka.util.ByteString; //导入依赖的package包/类
@Override
public int decode(ByteString bytes) throws PacketIncompleteException {
int lengthEnd = Builder.indexOf(Builder.delimiter, bytes);
int length = Integer.parseInt(bytes.slice(
Builder.BulkStringToken.length(),
lengthEnd).utf8String());
int dataStart = lengthEnd + Builder.delimiter.length();
if (length == -1) {
data = null;
return lengthEnd;
}
return dataStart + decodeInner(length,
bytes.slice(dataStart, bytes.size()));
}
示例10: pushData
import akka.util.ByteString; //导入依赖的package包/类
/**
* Writes data to the decoder, and tries to decode any packets
* it's able to out of there.
* @param data the byte data to push
*/
protected void pushData(ByteString data) {
this.decoder.write(data);
List<Packet> todo = new ArrayList<>();
while (true) {
try {
todo.add(decoder.packet());
} catch (PacketIncompleteException e) {
break;
}
}
for (Packet input : todo) {
processPacket(input);
}
}
示例11: testBasic
import akka.util.ByteString; //导入依赖的package包/类
@Test
public void testBasic() throws Exception {
Pool p = new Pool();
Publishable pub1 = mock(Publishable.class);
Publishable pub2 = mock(Publishable.class);
p.subscribe("asdf", pub1);
Event ev1 = new Event("asdf", ByteString.fromString("hello"));
Event ev2 = new Event("wasd", ByteString.fromString("hello"));
Event ev3 = new Event("asdf", ByteString.fromString("bye"));
p.publish(ev1);
p.publish(ev2);
p.subscribe("asdf", pub2);
p.publish(ev3);
verify(pub1).publish(ev1);
verify(pub1, never()).publish(ev2);
verify(pub1).publish(ev3);
verify(pub2).publish(ev3);
}
示例12: testPatterns
import akka.util.ByteString; //导入依赖的package包/类
@Test
public void testPatterns() throws Exception {
Pool p = new Pool();
Publishable pub1 = mock(Publishable.class);
Publishable pub2 = mock(Publishable.class);
p.psubscribe("h?llo", pub1);
p.psubscribe("h*llo", pub2);
Event ev1 = new Event("hello", ByteString.fromString("hello"));
p.publish(ev1);
verify(pub1).publish(ev1);
verify(pub2).publish(ev1);
Event ev2 = new Event("heeello", ByteString.fromString("hello"));
p.publish(ev2);
verify(pub1, never()).publish(ev2);
verify(pub2).publish(ev2);
}
示例13: testMixes
import akka.util.ByteString; //导入依赖的package包/类
@Test
public void testMixes() throws Exception {
Pool p = new Pool();
Publishable pub1 = mock(Publishable.class);
p.psubscribe("h[e]llo", pub1);
Publishable pub2 = mock(Publishable.class);
p.subscribe("h[e]llo", pub2);
Event ev1 = new Event("h[e]llo", ByteString.fromString("hello"));
p.publish(ev1);
verify(pub1, never()).publish(ev1);
verify(pub2).publish(ev1);
Event ev2 = new Event("hello", ByteString.fromString("hello"));
p.publish(ev2);
verify(pub1).publish(ev2);
verify(pub2, never()).publish(ev2);
}
示例14: testAddsToExisting
import akka.util.ByteString; //导入依赖的package包/类
@Test
public void testAddsToExisting() throws Exception {
Pool p = new Pool();
Publishable pub1 = mock(Publishable.class);
Publishable pub2 = mock(Publishable.class);
p.subscribe("a", pub1);
p.subscribe("a", pub2);
Event ev1 = new Event("a", ByteString.fromString("hello"));
p.publish(ev1);
verify(pub1).publish(ev1);
verify(pub2).publish(ev1);
p.unsubscribe(pub1);
Event ev2 = new Event("a", ByteString.fromString("hello"));
p.publish(ev2);
verify(pub1, never()).publish(ev2);
verify(pub2).publish(ev2);
}
示例15: apply
import akka.util.ByteString; //导入依赖的package包/类
/**
* Delegates underlying functionality to another body parser and converts the
* result to Java API.
*/
@Override
public play.libs.streams.Accumulator<ByteString, F.Either<Result, Http.MultipartFormData<A>>> apply(Http.RequestHeader request) {
return delegate.apply(request._underlyingHeader())
.asJava()
.map(result -> {
if (result.isLeft()) {
return F.Either.Left(result.left().get().asJava());
} else {
final play.api.mvc.MultipartFormData<A> scalaData = result.right().get();
return F.Either.Right(new DelegatingMultipartFormData(scalaData));
}
},
JavaParsers.trampoline()
);
}
开发者ID:play2-maven-plugin,项目名称:play2-maven-test-projects,代码行数:20,代码来源:DelegatingMultipartFormDataBodyParser.java