Advertisement
Guest User

Untitled

a guest
Feb 18th, 2015
356
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. package my.kryo;
  2.  
  3. import java.io.FileInputStream;
  4. import java.io.FileOutputStream;
  5. import java.io.IOException;
  6.  
  7. import com.esotericsoftware.kryo.Kryo;
  8. import com.esotericsoftware.kryo.io.Input;
  9. import com.esotericsoftware.kryo.io.Output;
  10. import com.esotericsoftware.kryo.serializers.CompatibleFieldSerializer;
  11. import com.esotericsoftware.minlog.Log;
  12.  
  13. public class TestKryoMain
  14. {
  15.  
  16. public static void main(String[] args)
  17. throws IOException
  18. {
  19. Log.DEBUG();
  20.  
  21. Kryo kryo = new Kryo();
  22. // Set serializer that can handle added & removed fields (but can't
  23. // handle type change).
  24. kryo.setDefaultSerializer(CompatibleFieldSerializer.class);
  25.  
  26. if( true )
  27. {
  28. Output output = new Output(new FileOutputStream("kryo.dat"));
  29. kryo.writeObject(output, new TestKryoData());
  30. output.close();
  31. }
  32. else
  33. {
  34. Input input = new Input(new FileInputStream("kryo.dat"));
  35. TestKryoData dataWrapper = kryo.readObject(input,
  36. TestKryoData.class);
  37. input.close();
  38.  
  39. System.out.println("ddd value should be 'bbb', got: "
  40. + dataWrapper.ddd);
  41. }
  42.  
  43. System.out.println("Done!");
  44. }
  45.  
  46. static public class TestKryoData
  47. {
  48. public String aaa = "aaa";
  49. public String bbb = "bbb";
  50. public String ccc = "ccc";
  51. public String ddd = bbb;
  52. // public String ddd = "ddd";
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement