Skip to content

Commit

Permalink
Add ByteString.emptyByteString to Java API
Browse files Browse the repository at this point in the history
To work around scala/bug#11509
  • Loading branch information
raboof committed May 15, 2019
1 parent 18a3569 commit b82d541
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 7 deletions.
3 changes: 3 additions & 0 deletions akka-actor/src/main/scala-2.13+/akka/util/ByteString.scala
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ object ByteString {

val empty: ByteString = CompactByteString(Array.empty[Byte])

/** Java API */
val emptyByteString: ByteString = empty

def newBuilder: ByteStringBuilder = new ByteStringBuilder

/** Java API */
Expand Down
3 changes: 3 additions & 0 deletions akka-actor/src/main/scala-2.13-/akka/util/ByteString.scala
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ object ByteString {

val empty: ByteString = CompactByteString(Array.empty[Byte])

/** Java API */
val emptyByteString: ByteString = empty

def newBuilder: ByteStringBuilder = new ByteStringBuilder

/** Java API */
Expand Down
5 changes: 4 additions & 1 deletion akka-docs/src/test/java/jdocs/io/UdpConnectedDocTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
import akka.io.UdpConnectedMessage;
import akka.io.UdpSO;
import akka.util.ByteString;

import static akka.util.ByteString.emptyByteString;

// #imports

public class UdpConnectedDocTest {
Expand Down Expand Up @@ -79,7 +82,7 @@ public Receive createReceive() {
builder.matchEquals(
"send",
x -> {
ByteString data = ByteString.empty();
ByteString data = emptyByteString();
// #send
connectionActor.tell(UdpConnectedMessage.send(data), getSelf());
// #send
Expand Down
3 changes: 2 additions & 1 deletion akka-docs/src/test/java/jdocs/stream/BidiFlowDocTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import akka.stream.stage.*;
import akka.util.ByteIterator;
import akka.util.ByteString;
import static akka.util.ByteString.emptyByteString;
import akka.util.ByteStringBuilder;
import static org.junit.Assert.assertArrayEquals;

Expand Down Expand Up @@ -156,7 +157,7 @@ public GraphStageLogic createLogic(Attributes inheritedAttributes) {
return new GraphStageLogic(shape) {

// this holds the received but not yet parsed bytes
private ByteString stash = ByteString.empty();
private ByteString stash = emptyByteString();
// this holds the current message length or -1 if at a boundary
private int needed = -1;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import akka.stream.stage.*;
import akka.testkit.javadsl.TestKit;
import akka.util.ByteString;
import static akka.util.ByteString.emptyByteString;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
Expand Down Expand Up @@ -78,7 +79,7 @@ public FlowShape<ByteString, ByteString> shape() {
@Override
public GraphStageLogic createLogic(Attributes inheritedAttributes) {
return new GraphStageLogic(shape) {
private ByteString buffer = ByteString.empty();
private ByteString buffer = emptyByteString();

{
setHandler(
Expand Down Expand Up @@ -149,7 +150,7 @@ private void emitChunk() {
assertTrue(chunk.size() <= 2);
}

ByteString sum = ByteString.empty();
ByteString sum = emptyByteString();
for (ByteString chunk : chunks) {
sum = sum.concat(chunk);
}
Expand Down Expand Up @@ -244,7 +245,7 @@ public void onPush() throws Exception {
.runWith(Sink.seq(), mat)
.toCompletableFuture()
.get(3, TimeUnit.SECONDS);
ByteString acc = ByteString.empty();
ByteString acc = emptyByteString();
for (ByteString b : got) {
acc = acc.concat(b);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import akka.stream.javadsl.Source;
import akka.testkit.javadsl.TestKit;
import akka.util.ByteString;
import static akka.util.ByteString.emptyByteString;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
Expand Down Expand Up @@ -51,7 +52,7 @@ public void parseLines() throws Exception {

ByteString decompressedData =
decompressedStream
.runFold(ByteString.empty(), ByteString::concat, mat)
.runFold(emptyByteString(), ByteString::concat, mat)
.toCompletableFuture()
.get(1, TimeUnit.SECONDS);
String decompressedString = decompressedData.utf8String();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import akka.testkit.javadsl.EventFilter;
import akka.testkit.javadsl.TestKit;
import akka.util.ByteString;
import static akka.util.ByteString.emptyByteString;
import org.junit.ClassRule;
import org.junit.Test;

Expand Down Expand Up @@ -85,7 +86,7 @@ public void mustWorkInHappyCase() throws Exception {
Tcp.get(system)
.outgoingConnection(serverAddress.getHostString(), serverAddress.getPort()))
.runFold(
ByteString.empty(),
emptyByteString(),
new Function2<ByteString, ByteString, ByteString>() {
public ByteString apply(ByteString acc, ByteString elem) {
return acc.concat(elem);
Expand Down

0 comments on commit b82d541

Please sign in to comment.