Created
August 1, 2012 07:59
-
-
Save hengyunabc/3224771 to your computer and use it in GitHub Desktop.
Testcase for Kryo 2.18
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.ByteArrayInputStream; | |
import java.io.ByteArrayOutputStream; | |
import java.io.IOException; | |
import java.util.Arrays; | |
import java.util.HashMap; | |
import com.esotericsoftware.kryo.Kryo; | |
import com.esotericsoftware.kryo.io.Input; | |
import com.esotericsoftware.kryo.io.Output; | |
import com.esotericsoftware.kryo.serializers.FieldSerializer.Optional; | |
import com.esotericsoftware.kryo.util.DefaultClassResolver; | |
public class Test { | |
public static void main(String[] args) { | |
test(); | |
} | |
static void test() { | |
Kryo kryo = new Kryo(); | |
byte[] data = null; | |
byte[] data1 = null; | |
{ | |
ByteArrayOutputStream outStream = new ByteArrayOutputStream(); | |
Output output = new Output(outStream, 4096); | |
Hello hello = new Hello(); | |
hello.map.put(123, new World()); | |
kryo.writeClassAndObject(output, hello); | |
output.flush(); | |
data = outStream.toByteArray(); | |
data1 = data; | |
} | |
System.out.println(Arrays.toString(data)); | |
{ | |
ByteArrayOutputStream outStream = new ByteArrayOutputStream(); | |
Output output = new Output(outStream, 4096); | |
Hello hello = new Hello(); | |
hello.map.put(123, new World()); | |
kryo.writeClassAndObject(output, hello); | |
output.flush(); | |
data = outStream.toByteArray(); | |
} | |
System.out.println("equal:" + Arrays.equals(data, data1)); | |
System.out.println(Arrays.toString(data)); | |
{ | |
Input input = new Input(new ByteArrayInputStream(data), 4096); | |
Kryo kryo2 = new Kryo(); | |
Hello hello2 = (Hello) kryo2.readClassAndObject(input); | |
System.out.println(hello2); | |
} | |
{ | |
Input input = new Input(new ByteArrayInputStream(data1), 4096); | |
Kryo kryo2 = new Kryo(); | |
Hello hello2 = (Hello) kryo2.readClassAndObject(input); | |
System.out.println(hello2); | |
} | |
} | |
static class Hello { | |
public HashMap<Integer, World> map = new HashMap<Integer, World>(); | |
public Hello() { | |
} | |
} | |
static class World { | |
public HashMap<Integer, String> map = new HashMap(); | |
public World() { | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment