Created
November 8, 2010 18:57
-
-
Save kzk/668092 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.DataInputStream; | |
import java.io.DataOutputStream; | |
import java.io.FileInputStream; | |
import java.io.FileOutputStream; | |
import java.io.IOException; | |
public class Main { | |
public static class MyClass { | |
public String s; | |
public int v; | |
} | |
public static class MyClassWritable extends MessagePackWritable<MyClass> { | |
public MyClassWritable() { | |
super(new MyClass()); | |
} | |
public MyClassWritable(MyClass obj) { | |
super(obj); | |
} | |
} | |
public static void main(String[] args) throws Exception { | |
MyClass b = new MyClass(); | |
b.s = "aiueo"; | |
b.v = 3; | |
MyClassWritable bw = new MyClassWritable(b); | |
DataOutputStream dos = new DataOutputStream(new FileOutputStream("test.txt")); | |
bw.write(dos); | |
dos.close(); | |
DataInputStream dis = new DataInputStream(new FileInputStream("test.txt")); | |
MyClassWritable aw = new MyClassWritable(); | |
aw.readFields(dis); | |
dis.close(); | |
System.out.println(aw.get().s); | |
System.out.println(aw.get().v); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment