File tree Expand file tree Collapse file tree
src/main/java/org/msgpack/unpacker Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -68,14 +68,22 @@ public Value readValue() throws IOException {
6868 }
6969
7070
71+ protected abstract boolean tryReadNil () throws IOException ;
72+
7173 @ Override
7274 public <T > T read (Class <T > klass ) throws IOException {
75+ if (tryReadNil ()) {
76+ return null ;
77+ }
7378 Template <? super T > tmpl = msgpack .lookup (klass );
7479 return (T ) tmpl .read (this , null );
7580 }
7681
7782 @ Override
7883 public <T > T read (T to ) throws IOException {
84+ if (tryReadNil ()) {
85+ return null ;
86+ }
7987 Template <? super T > tmpl = msgpack .lookup ((Class <T >) to .getClass ());
8088 return (T ) tmpl .read (this , to );
8189 }
Original file line number Diff line number Diff line change @@ -56,18 +56,18 @@ private void ensureValue() throws IOException {
5656 }
5757 }
5858
59- // @Override
60- // public boolean tryReadNil() throws IOException {
61- // stack.checkCount();
62- // if(getTop().isNil()) {
63- // stack.reduceCount();
64- // if(stack.getDepth() == 0) {
65- // value = null;
66- // }
67- // return true;
68- // }
69- // return false;
70- // }
59+ @ Override
60+ public boolean tryReadNil () throws IOException {
61+ stack .checkCount ();
62+ if (getTop ().isNil ()) {
63+ stack .reduceCount ();
64+ if (stack .getDepth () == 0 ) {
65+ value = null ;
66+ }
67+ return true ;
68+ }
69+ return false ;
70+ }
7171
7272 @ Override
7373 public boolean trySkipNil () throws IOException {
@@ -403,5 +403,9 @@ public void reset() {
403403 stack .clear ();
404404 value = null ;
405405 }
406+
407+ @ Override
408+ public void close () throws IOException {
409+ }
406410}
407411
Original file line number Diff line number Diff line change @@ -319,19 +319,19 @@ private void readRawBodyCont() throws IOException {
319319 }
320320 }
321321
322- // @Override
323- //public boolean tryReadNil() throws IOException {
324- // stack.checkCount();
325- // int b = getHeadByte() & 0xff;
326- // if(b == 0xc0) {
327- // // nil is read
328- // stack.reduceCount();
329- // headByte = REQUIRE_TO_READ_HEAD;
330- // return true;
331- // }
332- // // not nil
333- // return false;
334- // }
322+ @ Override
323+ protected boolean tryReadNil () throws IOException {
324+ stack .checkCount ();
325+ int b = getHeadByte () & 0xff ;
326+ if (b == 0xc0 ) {
327+ // nil is read
328+ stack .reduceCount ();
329+ headByte = REQUIRE_TO_READ_HEAD ;
330+ return true ;
331+ }
332+ // not nil
333+ return false ;
334+ }
335335
336336 @ Override
337337 public boolean trySkipNil () throws IOException {
You can’t perform that action at this time.
0 commit comments