From 584bc9286ca6aaddb266b0db60eb5f5dfb4843d7 Mon Sep 17 00:00:00 2001 From: Philip Aston Date: Mon, 1 Feb 2016 18:52:07 +0000 Subject: [PATCH] Fix reported location after non-stream input has been parsed. --- .../jackson/dataformat/cbor/CBORParser.java | 4 +-- .../dataformat/cbor/ParserSimpleTest.java | 28 +++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/fasterxml/jackson/dataformat/cbor/CBORParser.java b/src/main/java/com/fasterxml/jackson/dataformat/cbor/CBORParser.java index e5235f2..2926313 100644 --- a/src/main/java/com/fasterxml/jackson/dataformat/cbor/CBORParser.java +++ b/src/main/java/com/fasterxml/jackson/dataformat/cbor/CBORParser.java @@ -2841,9 +2841,9 @@ private final int _decodeChunkedUTF8_4(int c) throws IOException protected final boolean loadMore() throws IOException { - _currInputProcessed += _inputEnd; - if (_inputStream != null) { + _currInputProcessed += _inputEnd; + int count = _inputStream.read(_inputBuffer, 0, _inputBuffer.length); if (count > 0) { _inputPtr = 0; diff --git a/src/test/java/com/fasterxml/jackson/dataformat/cbor/ParserSimpleTest.java b/src/test/java/com/fasterxml/jackson/dataformat/cbor/ParserSimpleTest.java index c66bf94..964bcd4 100644 --- a/src/test/java/com/fasterxml/jackson/dataformat/cbor/ParserSimpleTest.java +++ b/src/test/java/com/fasterxml/jackson/dataformat/cbor/ParserSimpleTest.java @@ -240,6 +240,34 @@ private void _testMedium(int len) throws Exception p.close(); } + public void testCurrentLocationByteOffset() throws Exception { + ByteArrayOutputStream out = new ByteArrayOutputStream(); + CBORGenerator gen = cborGenerator(out); + gen.writeString("1234567890"); + gen.writeString("1234567890"); + gen.close(); + + final byte[] b = out.toByteArray(); + + JsonParser p = cborParser(b); + + assertToken(JsonToken.VALUE_STRING, p.nextToken()); + assertEquals(1, p.getCurrentLocation().getByteOffset()); + p.getText(); // fully read token. + assertEquals(11, p.getCurrentLocation().getByteOffset()); + + assertToken(JsonToken.VALUE_STRING, p.nextToken()); + assertEquals(12, p.getCurrentLocation().getByteOffset()); + p.getText(); + assertEquals(22, p.getCurrentLocation().getByteOffset()); + + assertNull(p.nextToken()); + assertEquals(22, p.getCurrentLocation().getByteOffset()); + + p.close(); + assertEquals(22, p.getCurrentLocation().getByteOffset()); + } + public void testLongNonChunkedText() throws Exception { ByteArrayOutputStream out = new ByteArrayOutputStream();