Created
June 13, 2012 07:29
-
-
Save hengyunabc/2922529 to your computer and use it in GitHub Desktop.
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.util.Arrays; | |
import java.util.HashMap; | |
import com.esotericsoftware.kryo.Kryo; | |
import com.esotericsoftware.kryo.FieldSerializerTest.Hello; | |
import com.esotericsoftware.kryo.io.Input; | |
import com.esotericsoftware.kryo.io.Output; | |
import com.esotericsoftware.kryo.serializers.MapSerializer; | |
public class Test { | |
static class Hello { | |
public int size = 100; | |
public HashMap<String, String> map = new HashMap<String, String>(); | |
public Hello() { | |
map = new HashMap<String, String>(); | |
map.put("001", "xxx"); | |
} | |
} | |
static void test() { | |
Kryo kryo = new Kryo(); | |
kryo.register(HashMap.class); | |
kryo.register(Hello.class); | |
ByteArrayOutputStream outStream = new ByteArrayOutputStream(); | |
Output output = new Output(outStream, 4096); | |
Hello hello = new Hello(); | |
kryo.writeClassAndObject(output, hello); | |
output.flush(); | |
byte[] data = outStream.toByteArray(); | |
System.out.println(Arrays.toString(data)); | |
Input input = new Input(new ByteArrayInputStream(data), 4096); | |
Hello hello2 = (Hello) kryo.readClassAndObject(input); | |
System.out.println(hello2); | |
} | |
public static void main(String[] args) { | |
test(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The code can work with Kryo 2.12 but not Kryo 2.14...