@@ -71,18 +71,6 @@ public byte[] write(Value v) throws IOException { // TODO IOException
7171 return pk .toByteArray ();
7272 }
7373
74- public <T > T read (InputStream in , T v ) throws IOException {
75- // TODO
76- Template tmpl = getTemplate (v .getClass ());
77- return (T )tmpl .read (new StreamUnpacker (in ), v );
78- }
79-
80- public <T > T read (InputStream in , Class <T > c ) throws IOException {
81- // TODO
82- Template tmpl = getTemplate (c );
83- return (T )tmpl .read (new StreamUnpacker (in ), null );
84- }
85-
8674 public Value read (byte [] b ) throws IOException { // TODO IOException
8775 return read (b , 0 , b .length );
8876 }
@@ -95,6 +83,10 @@ public Value read(ByteBuffer buf) throws IOException { // TODO IOException
9583 return new BufferUnpacker ().wrap (buf ).readValue ();
9684 }
9785
86+ public Value read (InputStream in ) throws IOException {
87+ return new StreamUnpacker (in ).readValue ();
88+ }
89+
9890 public <T > T read (byte [] b , T v ) throws IOException { // TODO IOException
9991 // TODO
10092 Template tmpl = getTemplate (v .getClass ());
@@ -127,6 +119,18 @@ public <T> T read(ByteBuffer b, Class<T> c) { // TODO IOException
127119 return null ;
128120 }
129121
122+ public <T > T read (InputStream in , T v ) throws IOException {
123+ // TODO
124+ Template tmpl = getTemplate (v .getClass ());
125+ return (T )tmpl .read (new StreamUnpacker (in ), v );
126+ }
127+
128+ public <T > T read (InputStream in , Class <T > c ) throws IOException {
129+ // TODO
130+ Template tmpl = getTemplate (c );
131+ return (T )tmpl .read (new StreamUnpacker (in ), null );
132+ }
133+
130134 public <T > T convert (Value v , T to ) throws IOException { // TODO IOException
131135 // TODO
132136 Template tmpl = getTemplate (to .getClass ());
@@ -162,41 +166,82 @@ public void registerTemplate(Class<?> type, Template tmpl) {
162166 registry .register (type , tmpl );
163167 }
164168
165- /*
166- // TODO
167- private static final MessagePack globalMessagePack;
169+
170+ private static final MessagePack globalMessagePack = new MessagePack ();
168171
169172 @ Deprecated
170- public static <T> T unpack(InputStream in, T v) {
171- return globalMessagePack.unpack(in, v );
173+ public static byte [] pack ( Object obj ) throws IOException { // TODO IOException
174+ return globalMessagePack .write ( obj );
172175 }
173176
174177 @ Deprecated
175- public static <T> T unpack(InputStream in, Class<T> c) {
176- return globalMessagePack.unpack(in, c );
178+ public static void pack ( OutputStream out , Object obj ) throws IOException {
179+ globalMessagePack .write ( out , obj );
177180 }
178181
179182 @ Deprecated
180- public static <T> T unpack(byte[] b, T v) {
181- return globalMessagePack.unpack(b, v);
183+ public static byte [] pack (Object obj , Template tmpl ) throws IOException { // TODO IOException
184+ BufferPacker pk = new BufferPacker ();
185+ tmpl .write (pk , obj );
186+ return pk .toByteArray ();
187+ }
188+
189+ @ Deprecated
190+ public static void pack (OutputStream out , Object obj , Template tmpl ) throws IOException {
191+ StreamPacker pk = new StreamPacker (out );
192+ tmpl .write (pk , obj );
193+ }
194+
195+ @ Deprecated
196+ public static Value unpack (byte [] buffer ) throws IOException {
197+ return globalMessagePack .read (buffer );
198+ }
199+
200+ @ Deprecated
201+ public static <T > T unpack (byte [] buffer , Template tmpl ) throws IOException {
202+ BufferUnpacker u = new BufferUnpacker ().wrap (buffer );
203+ return (T )tmpl .read (u , null );
182204 }
183205
184206 @ Deprecated
185- public static <T> T unpack(byte[] b, Class<T> c) {
186- return globalMessagePack.unpack(b, c);
207+ public static <T > T unpack (byte [] buffer , Template tmpl , T to ) throws IOException {
208+ BufferUnpacker u = new BufferUnpacker ().wrap (buffer );
209+ return (T )tmpl .read (u , to );
187210 }
188211
189212 @ Deprecated
190- public static <T> T unpack(ByteBuffer b, T v) {
191- return globalMessagePack.unpack(b, v );
213+ public static <T > T unpack (byte [] buffer , Class < T > klass ) throws IOException {
214+ return globalMessagePack .read ( buffer , klass );
192215 }
193216
194217 @ Deprecated
195- public static <T> T unpack(ByteBuffer b, Class<T> c) {
196- return globalMessagePack.unpack(b, c );
218+ public static <T > T unpack (byte [] buffer , T to ) throws IOException {
219+ return globalMessagePack .read ( buffer , to );
197220 }
198- */
199221
222+ @ Deprecated
223+ public static Value unpack (InputStream in ) throws IOException {
224+ return globalMessagePack .read (in );
225+ }
200226
227+ @ Deprecated
228+ public static Object unpack (InputStream in , Template tmpl ) throws IOException , MessageTypeException {
229+ return tmpl .read (new StreamUnpacker (in ), null );
230+ }
231+
232+ @ Deprecated
233+ public static <T > T unpack (InputStream in , Template tmpl , T to ) throws IOException , MessageTypeException {
234+ return (T )tmpl .read (new StreamUnpacker (in ), to );
235+ }
236+
237+ @ Deprecated
238+ public static <T > T unpack (InputStream in , Class <T > klass ) throws IOException {
239+ return globalMessagePack .read (in , klass );
240+ }
241+
242+ @ Deprecated
243+ public static <T > T unpack (InputStream in , T to ) throws IOException {
244+ return globalMessagePack .read (in , to );
245+ }
201246}
202247
0 commit comments