diff options
author | Daniel Martin <daniel.martin@crowdstrike.com> | 2014-11-25 12:58:34 -0500 |
---|---|---|
committer | Daniel Martin <daniel.martin@crowdstrike.com> | 2014-11-25 13:00:03 -0500 |
commit | 5ff8dc8e005f5312af98655786c1c8438a617efb (patch) | |
tree | 4af7d4dfc83d1725c124cb45eb07b35bd39df584 /java/src/test | |
parent | 99aa0f9e8f1a88def7bdebf1385678559cda0707 (diff) | |
download | protobuf-5ff8dc8e005f5312af98655786c1c8438a617efb.tar.gz protobuf-5ff8dc8e005f5312af98655786c1c8438a617efb.tar.bz2 protobuf-5ff8dc8e005f5312af98655786c1c8438a617efb.zip |
Make ByteStrings serializable with java serialization.
Diffstat (limited to 'java/src/test')
-rw-r--r-- | java/src/test/java/com/google/protobuf/LiteralByteStringTest.java | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/java/src/test/java/com/google/protobuf/LiteralByteStringTest.java b/java/src/test/java/com/google/protobuf/LiteralByteStringTest.java index 475f7ffb..ff39ca3f 100644 --- a/java/src/test/java/com/google/protobuf/LiteralByteStringTest.java +++ b/java/src/test/java/com/google/protobuf/LiteralByteStringTest.java @@ -32,9 +32,12 @@ package com.google.protobuf; import junit.framework.TestCase; +import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; import java.io.OutputStream; import java.io.UnsupportedEncodingException; import java.nio.ByteBuffer; @@ -393,4 +396,17 @@ public class LiteralByteStringTest extends TestCase { assertSame("empty concatenated with " + classUnderTest + " must give " + classUnderTest, ByteString.EMPTY.concat(stringUnderTest), stringUnderTest); } + + public void testJavaSerialization() throws Exception { + ByteArrayOutputStream out = new ByteArrayOutputStream(); + ObjectOutputStream oos = new ObjectOutputStream(out); + oos.writeObject(stringUnderTest); + oos.close(); + byte[] pickled = out.toByteArray(); + InputStream in = new ByteArrayInputStream(pickled); + ObjectInputStream ois = new ObjectInputStream(in); + Object o = ois.readObject(); + assertTrue("Didn't get a ByteString back", o instanceof ByteString); + assertEquals("Should get an equal ByteString back", stringUnderTest, o); + } } |