2222import java .io .IOException ;
2323import java .nio .ByteBuffer ;
2424
25- import org .msgpack .template .FieldList ;
2625import org .msgpack .template .Template ;
2726import org .msgpack .packer .StreamPacker ;
2827import org .msgpack .packer .BufferPacker ;
@@ -44,83 +43,94 @@ public MessagePack(MessagePack msgpack) {
4443 registry = new TemplateRegistry (msgpack .registry );
4544 }
4645
47- public byte [] pack (Object v ) throws IOException {
48- return pack (v , registry .lookup (v .getClass ()));
46+ public byte [] write (Object v ) throws IOException {
47+ return write (v , registry .lookup (v .getClass ()));
4948 }
5049
51- public byte [] pack (Object v , Template tmpl ) throws IOException {
52- BufferPacker pk = new BufferPacker ();
53- tmpl .write (pk , v );
54- return pk .toByteArray ();
50+ public byte [] write (Object v , Template tmpl ) throws IOException { // TODO IOException
51+ BufferPacker pk = new BufferPacker ();
52+ tmpl .write (pk , v );
53+ return pk .toByteArray ();
5554 }
5655
57- public void pack (OutputStream out , Object v ) throws IOException {
58- pack (out , v , registry .lookup (v .getClass ()));
56+ public void write (OutputStream out , Object v ) throws IOException {
57+ write (out , v , registry .lookup (v .getClass ()));
5958 }
6059
61- public void pack (OutputStream out , Object v , Template tmpl ) throws IOException {
60+ public void write (OutputStream out , Object v , Template tmpl ) throws IOException {
6261 StreamPacker pk = new StreamPacker (out );
6362 tmpl .write (pk , v );
6463 }
6564
66- public byte [] pack (Value v ) throws IOException {
65+ public byte [] write (Value v ) throws IOException { // TODO IOException
6766 // FIXME ValueTemplate should do this
6867 BufferPacker pk = new BufferPacker ();
6968 pk .write (v );
7069 return pk .toByteArray ();
7170 }
7271
73- public <T > T unpack (InputStream in , T v ) throws IOException {
74- Template tmpl = registry .lookup (v .getClass ());
75- return (T )tmpl .read (new StreamUnpacker (in ), v );
76- }
77-
78- public <T > T unpack (InputStream in , Class <T > c ) throws IOException {
79- Template tmpl = registry .lookup (c );
80- return (T )tmpl .read (new StreamUnpacker (in ), null );
81- }
82-
83- public Value unpack (byte [] b ) throws IOException {
84- return unpack (b , 0 , b .length );
72+ public Value read (byte [] b ) throws IOException { // TODO IOException
73+ return read (b , 0 , b .length );
8574 }
8675
87- public Value unpack (byte [] b , int off , int len ) throws IOException {
76+ public Value read (byte [] b , int off , int len ) throws IOException { // TODO IOException
8877 return new BufferUnpacker ().wrap (b , off , len ).readValue ();
8978 }
9079
91- public Value unpack (ByteBuffer buf ) throws IOException {
80+ public Value read (ByteBuffer buf ) throws IOException { // TODO IOException
9281 return new BufferUnpacker ().wrap (buf ).readValue ();
9382 }
9483
95- public <T > T unpack (byte [] b , T v ) throws IOException {
84+ public Value read (InputStream in ) throws IOException {
85+ return new StreamUnpacker (in ).readValue ();
86+ }
87+
88+ public <T > T read (byte [] b , T v ) throws IOException { // TODO IOException
89+ // TODO
9690 Template tmpl = registry .lookup (v .getClass ());
9791 BufferUnpacker u = new BufferUnpacker ();
9892 u .wrap (b );
9993 return (T )tmpl .read (u , v );
10094 }
10195
102- public <T > T unpack (byte [] b , Class <T > c ) throws IOException {
96+ public <T > T read (byte [] b , Class <T > c ) throws IOException { // TODO IOException
97+ // TODO
10398 Template tmpl = registry .lookup (c );
10499 BufferUnpacker u = new BufferUnpacker ();
105100 u .wrap (b );
106101 return (T )tmpl .read (u , null );
107102 }
108103
109- public <T > T unpack (ByteBuffer b , T v ) throws IOException {
104+ public <T > T read (ByteBuffer b , T v ) throws IOException { // TODO IOException
105+ // TODO
110106 Template tmpl = registry .lookup (v .getClass ());
111107 BufferUnpacker u = new BufferUnpacker ();
112108 u .wrap (b );
113109 return (T )tmpl .read (u , v );
114110 }
115111
116- public <T > T unpack (ByteBuffer b , Class <T > c ) {
112+ public <T > T read (ByteBuffer b , Class <T > c ) { // TODO IOException
113+ // TODO
117114 Template tmpl = registry .lookup (c );
118115 BufferUnpacker u = new BufferUnpacker ();
119116 u .wrap (b );
120117 return null ;
121118 }
122119
123- public <T > T convert (Value v , T to ) throws IOException {
120+ public <T > T read (InputStream in , T v ) throws IOException {
121+ // TODO
122+ Template tmpl = registry .lookup (v .getClass ());
123+ return (T )tmpl .read (new StreamUnpacker (in ), v );
124+ }
125+
126+ public <T > T read (InputStream in , Class <T > c ) throws IOException {
127+ // TODO
128+ Template tmpl = registry .lookup (c );
129+ return (T )tmpl .read (new StreamUnpacker (in ), null );
130+ }
131+
132+ public <T > T convert (Value v , T to ) throws IOException { // TODO IOException
133+ // TODO
124134 Template tmpl = registry .lookup (to .getClass ());
125135 return (T )tmpl .read (new Converter (v ), to );
126136 }
@@ -148,45 +158,81 @@ public void register(Class<?> type, Template tmpl) {
148158 registry .register (type , tmpl );
149159 }
150160
151- public void register (Class <?> type , FieldList flist ) {
152- registry .register (type , flist );
161+ private static final MessagePack globalMessagePack = new MessagePack ();
162+
163+ @ Deprecated
164+ public static byte [] pack (Object obj ) throws IOException { // TODO IOException
165+ return globalMessagePack .write (obj );
153166 }
154167
155- /*
156- // TODO
157- private static final MessagePack globalMessagePack;
168+ @ Deprecated
169+ public static void pack (OutputStream out , Object obj ) throws IOException {
170+ globalMessagePack .write (out , obj );
171+ }
172+
173+ @ Deprecated
174+ public static byte [] pack (Object obj , Template tmpl ) throws IOException { // TODO IOException
175+ BufferPacker pk = new BufferPacker ();
176+ tmpl .write (pk , obj );
177+ return pk .toByteArray ();
178+ }
179+
180+ @ Deprecated
181+ public static void pack (OutputStream out , Object obj , Template tmpl ) throws IOException {
182+ StreamPacker pk = new StreamPacker (out );
183+ tmpl .write (pk , obj );
184+ }
158185
159186 @ Deprecated
160- public static <T> T unpack(InputStream in, T v) {
161- return globalMessagePack.unpack(in, v );
187+ public static Value unpack (byte [] buffer ) throws IOException {
188+ return globalMessagePack .read ( buffer );
162189 }
163190
164191 @ Deprecated
165- public static <T> T unpack(InputStream in, Class<T> c) {
166- return globalMessagePack.unpack(in, c);
192+ public static <T > T unpack (byte [] buffer , Template tmpl ) throws IOException {
193+ BufferUnpacker u = new BufferUnpacker ().wrap (buffer );
194+ return (T )tmpl .read (u , null );
195+ }
196+
197+ @ Deprecated
198+ public static <T > T unpack (byte [] buffer , Template tmpl , T to ) throws IOException {
199+ BufferUnpacker u = new BufferUnpacker ().wrap (buffer );
200+ return (T )tmpl .read (u , to );
167201 }
168202
169203 @ Deprecated
170- public static <T> T unpack(byte[] b, T v) {
171- return globalMessagePack.unpack(b, v );
204+ public static <T > T unpack (byte [] buffer , Class < T > klass ) throws IOException {
205+ return globalMessagePack .read ( buffer , klass );
172206 }
173207
174208 @ Deprecated
175- public static <T> T unpack(byte[] b, Class<T> c) {
176- return globalMessagePack.unpack(b, c );
209+ public static <T > T unpack (byte [] buffer , T to ) throws IOException {
210+ return globalMessagePack .read ( buffer , to );
177211 }
178212
179213 @ Deprecated
180- public static <T> T unpack(ByteBuffer b, T v) {
181- return globalMessagePack.unpack(b, v );
214+ public static Value unpack (InputStream in ) throws IOException {
215+ return globalMessagePack .read ( in );
182216 }
183217
184218 @ Deprecated
185- public static <T> T unpack(ByteBuffer b, Class<T> c) {
186- return globalMessagePack.unpack(b, c );
219+ public static Object unpack (InputStream in , Template tmpl ) throws IOException , MessageTypeException {
220+ return tmpl . read ( new StreamUnpacker ( in ), null );
187221 }
188- */
189222
223+ @ Deprecated
224+ public static <T > T unpack (InputStream in , Template tmpl , T to ) throws IOException , MessageTypeException {
225+ return (T )tmpl .read (new StreamUnpacker (in ), to );
226+ }
190227
228+ @ Deprecated
229+ public static <T > T unpack (InputStream in , Class <T > klass ) throws IOException {
230+ return globalMessagePack .read (in , klass );
231+ }
232+
233+ @ Deprecated
234+ public static <T > T unpack (InputStream in , T to ) throws IOException {
235+ return globalMessagePack .read (in , to );
236+ }
191237}
192238
0 commit comments