Mercurial > hg > Members > nobuyasu > PracticeJava
changeset 7:98144dbff410 default tip
Added WriteHardDisk.java : Msgpack practice
author | one |
---|---|
date | Sat, 12 Oct 2013 19:42:55 +0900 |
parents | b82cdd44b1c1 |
children | |
files | .classpath src/ie/oshiro/messagepack/io/WriteHardDisk.java src/ie/oshiro/messagepack/practice/MSGFJListTest.java |
diffstat | 3 files changed, 41 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/.classpath Mon Jun 10 00:21:06 2013 +0900 +++ b/.classpath Sat Oct 12 19:42:55 2013 +0900 @@ -7,5 +7,6 @@ <classpathentry kind="lib" path="/Users/nobuyasu/workspace/PracticeJava/lib/msgpack-0.6.8-SNAPSHOT-sources.jar"/> <classpathentry kind="lib" path="/Users/nobuyasu/workspace/PracticeJava/lib/msgpack-0.6.8-SNAPSHOT.jar"/> <classpathentry kind="lib" path="/Users/nobuyasu/workspace/jungle-core/target/jungle-core-0.0.1-SNAPSHOT.jar"/> + <classpathentry kind="lib" path="/Alice/Alice.jar"/> <classpathentry kind="output" path="bin"/> </classpath>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/ie/oshiro/messagepack/io/WriteHardDisk.java Sat Oct 12 19:42:55 2013 +0900 @@ -0,0 +1,39 @@ +package ie.oshiro.messagepack.io; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; + +import org.msgpack.MessagePack; +import org.msgpack.annotation.Message; +import org.msgpack.type.Value; + +public class WriteHardDisk { + + public static void main(String[] args) throws IOException { + MessagePack msgpack = new MessagePack(); + ClassA c = new ClassA(); + Value v = msgpack.unconvert(c); + ClassA convertedC = msgpack.convert(v, ClassA.class); + + File file = new File("./tmp/WriteHardDiskOut"); + FileOutputStream out = new FileOutputStream(file); + msgpack.write(out, v); + out.flush(); + FileInputStream in = new FileInputStream(file); + Value v2 = msgpack.read(in); + ClassA convertedC2 = msgpack.convert(v2, ClassA.class); + System.out.println(convertedC.getNum() == convertedC2.getNum()); + } + + @Message + public static class ClassA { + int num; + public ClassA() { num = 0; } + public ClassA(int _num) { num = _num; } + public void setNum(int _num) { num = _num; } + public int getNum() { return num; } + } + +}
--- a/src/ie/oshiro/messagepack/practice/MSGFJListTest.java Mon Jun 10 00:21:06 2013 +0900 +++ b/src/ie/oshiro/messagepack/practice/MSGFJListTest.java Sat Oct 12 19:42:55 2013 +0900 @@ -24,6 +24,7 @@ for(Value v: (List<Value>) msgpack.read(bytes, List.class)) { System.out.println(v.asIntegerValue()); } + System.out.println(writeList); /* // Cannot find template for class fj.data.List class Value v = msgpack.unconvert(writeList);