Skip to content
This repository was archived by the owner on Dec 23, 2023. It is now read-only.

Commit 118c921

Browse files
author
Dino Oliva
committed
Updates serialize() to be more consistent with java.io.Serializable
1 parent 01ecf09 commit 118c921

File tree

4 files changed

+13
-13
lines changed

4 files changed

+13
-13
lines changed

core/java/com/google/instrumentation/stats/StatsContext.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
package com.google.instrumentation.stats;
1515

16+
import java.io.IOException;
1617
import java.io.OutputStream;
1718

1819
/**
@@ -55,9 +56,8 @@ public final StatsContext with(
5556
* the {@link StatsContext} protobuf representation.
5657
*
5758
* @param output the {@link OutputStream} to add the serialized form of this {@link StatsContext}.
58-
* @return the given {@link OutputStream}
5959
*/
60-
public abstract OutputStream serialize(OutputStream output);
60+
public abstract void serialize(OutputStream output) throws IOException;
6161

6262
/**
6363
* Builder for {@link StatsContext}.

core/javatests/com/google/instrumentation/stats/StatsContextTest.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import com.google.common.testing.EqualsTester;
1919

2020
import java.io.ByteArrayOutputStream;
21+
import java.io.IOException;
2122
import java.nio.ByteBuffer;
2223
import org.junit.Test;
2324
import org.junit.runner.RunWith;
@@ -142,7 +143,11 @@ public void testToString() {
142143

143144
private static void testSerialization(StatsContext expected) {
144145
ByteArrayOutputStream output = new ByteArrayOutputStream();
145-
expected.serialize(output);
146+
try {
147+
expected.serialize(output);
148+
} catch (IOException exn) {
149+
// ignore
150+
}
146151
ByteBuffer input = ByteBuffer.wrap(output.toByteArray());
147152
StatsContext actual = Stats.getStatsContextFactory().deserialize(input);
148153
assertThat(actual).isEqualTo(expected);

core_impl/java/com/google/instrumentation/stats/StatsContextImpl.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
package com.google.instrumentation.stats;
1515

16+
import java.io.IOException;
1617
import java.io.OutputStream;
1718
import java.util.HashMap;
1819

@@ -42,8 +43,8 @@ public StatsContextImpl record(MeasurementMap stats) {
4243
* <p>The encoded tags are of the form: {@code <tag prefix> + 'key' + <tag delim> + 'value'}*
4344
*/
4445
@Override
45-
public OutputStream serialize(OutputStream output) {
46-
return StatsSerializer.serialize(this, output);
46+
public void serialize(OutputStream output) throws IOException {
47+
StatsSerializer.serialize(this, output);
4748
}
4849

4950
@Override

core_impl/java/com/google/instrumentation/stats/StatsSerializer.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ final class StatsSerializer {
3333

3434
// Serializes a StatsContext by transforming it into a StatsContextProto. The
3535
// encoded tags are of the form: (<tag prefix> + 'key' + <tag delim> + 'value')*
36-
static OutputStream serialize(StatsContextImpl context, OutputStream output) {
36+
static void serialize(StatsContextImpl context, OutputStream output) throws IOException {
3737
StringBuilder builder = new StringBuilder();
3838
for (Entry<String, String> tag : context.tags.entrySet()) {
3939
builder
@@ -42,13 +42,7 @@ static OutputStream serialize(StatsContextImpl context, OutputStream output) {
4242
.append(TAG_DELIM)
4343
.append(tag.getValue());
4444
}
45-
try {
46-
StatsContextProto.StatsContext.newBuilder().setTags(builder.toString()).build()
47-
.writeTo(output);
48-
} catch (IOException exn) {
49-
// ignored
50-
}
51-
return output;
45+
StatsContextProto.StatsContext.newBuilder().setTags(builder.toString()).build().writeTo(output);
5246
}
5347

5448
// Deserializes based on an serialized StatsContextProto. The encoded tags are of the form:

0 commit comments

Comments
 (0)