Skip to content

Commit 4677f37

Browse files
committed
Merge #24 fix in 2.4 branch as well (for 2.4.6, if ever)
1 parent a030098 commit 4677f37

File tree

5 files changed

+55
-7
lines changed

5 files changed

+55
-7
lines changed

release-notes/CREDITS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,8 @@ Steven Schlansker:
1212
brharrington@github:
1313
* Reported #17: Boundary error with `float`/`double` values, large content
1414
(2.4.1)
15+
16+
17+
mcmahon356@github:
18+
* Reported 24: Current location does not always updated properly
19+
(2.5.1)

release-notes/VERSION

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ Project: jackson-dataformat-smile
44
=== Releases ===
55
------------------------------------------------------------------------
66

7+
2.4.6 (not yet released)
8+
9+
#24: Current location does not always updated properly
10+
(reported by mcmahon356@github)
11+
712
2.4.5 (13-Jan-2015)
813
2.4.4 (24-Nov-2014)
914
2.4.3 (04-Oct-2014)

src/main/java/com/fasterxml/jackson/dataformat/smile/SmileParser.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -386,16 +386,18 @@ public JsonLocation getCurrentLocation()
386386
@Override
387387
protected final boolean loadMore() throws IOException
388388
{
389-
_currInputProcessed += _inputEnd;
390389
//_currInputRowStart -= _inputEnd;
391390

392391
if (_inputStream != null) {
393392
int count = _inputStream.read(_inputBuffer, 0, _inputBuffer.length);
393+
_currInputProcessed += _inputEnd;
394+
_inputPtr = 0;
394395
if (count > 0) {
395-
_inputPtr = 0;
396396
_inputEnd = count;
397397
return true;
398398
}
399+
// important: move pointer to same as end, to keep location accurate
400+
_inputEnd = 0;
399401
// End of input
400402
_closeInput();
401403
// Should never return 0, so let's fail
@@ -418,8 +420,8 @@ protected final void _loadToHaveAtLeast(int minAvailable) throws IOException
418420
}
419421
// Need to move remaining data in front?
420422
int amount = _inputEnd - _inputPtr;
423+
_currInputProcessed += _inputPtr;
421424
if (amount > 0 && _inputPtr > 0) {
422-
_currInputProcessed += _inputPtr;
423425
//_currInputRowStart -= _inputPtr;
424426
System.arraycopy(_inputBuffer, _inputPtr, _inputBuffer, 0, amount);
425427
_inputEnd = amount;

src/test/java/com/fasterxml/jackson/dataformat/smile/SmileTestBase.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
import java.io.ByteArrayOutputStream;
44
import java.io.IOException;
55
import java.io.InputStream;
6+
import java.io.OutputStream;
67
import java.util.Arrays;
78

89
import org.junit.Assert;
910

1011
import com.fasterxml.jackson.core.*;
1112
import com.fasterxml.jackson.databind.ObjectMapper;
12-
1313
import com.fasterxml.jackson.dataformat.smile.SmileFactory;
1414
import com.fasterxml.jackson.dataformat.smile.SmileGenerator;
1515
import com.fasterxml.jackson.dataformat.smile.SmileParser;
@@ -128,14 +128,14 @@ protected byte[] _smileDoc(SmileFactory smileFactory, String json, boolean write
128128
return out.toByteArray();
129129
}
130130

131-
protected SmileGenerator smileGenerator(ByteArrayOutputStream result, boolean addHeader)
131+
protected SmileGenerator smileGenerator(OutputStream result, boolean addHeader)
132132
throws IOException
133133
{
134134
return smileGenerator(new SmileFactory(), result, addHeader);
135135
}
136136

137137
protected SmileGenerator smileGenerator(SmileFactory f,
138-
ByteArrayOutputStream result, boolean addHeader)
138+
OutputStream result, boolean addHeader)
139139
throws IOException
140140
{
141141
f.configure(SmileGenerator.Feature.WRITE_HEADER, addHeader);

src/test/java/com/fasterxml/jackson/dataformat/smile/TestParserLocation.java

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.fasterxml.jackson.dataformat.smile;
22

3-
import java.io.IOException;
3+
import java.io.*;
44

55
import com.fasterxml.jackson.core.*;
66

@@ -57,4 +57,40 @@ public void testSimpleOffsets() throws IOException
5757
assertNull(p.nextToken());
5858
p.close();
5959
}
60+
61+
// for [databind-smile#24]
62+
public void testAscendingOffsets() throws Exception
63+
{
64+
// need to create big enough document, say at least 64k
65+
// but as importantly, try to create buffer boundaries by using 6-char (7-byte) ASCII strings
66+
final int COUNT = 57000;
67+
final int SIZE = COUNT * 7;
68+
69+
ByteArrayOutputStream bytes = new ByteArrayOutputStream(COUNT + 10);
70+
SmileGenerator gen = smileGenerator(bytes, true);
71+
gen.disable(SmileGenerator.Feature.CHECK_SHARED_STRING_VALUES);
72+
gen.writeStartArray();
73+
for (int i = 0; i < COUNT; ++i) {
74+
gen.writeString("abc123");
75+
}
76+
gen.writeEndArray();
77+
gen.close();
78+
byte[] b = bytes.toByteArray();
79+
assertEquals(4 + 2 + SIZE, b.length);
80+
81+
SmileParser p = _smileParser(new ByteArrayInputStream(b));
82+
assertToken(JsonToken.START_ARRAY, p.nextToken());
83+
// 4 byte header, start array read, so 4 bytes down:
84+
assertEquals(5, p.getCurrentLocation().getByteOffset());
85+
for (int i = 0; i < COUNT; ++i) {
86+
assertToken(JsonToken.VALUE_STRING, p.nextToken());
87+
assertEquals(6 + i*7, p.getCurrentLocation().getByteOffset());
88+
assertEquals("abc123", p.getText());
89+
}
90+
assertToken(JsonToken.END_ARRAY, p.nextToken());
91+
assertEquals(SIZE+6, p.getCurrentLocation().getByteOffset());
92+
assertNull(p.nextToken());
93+
assertEquals(SIZE+6, p.getCurrentLocation().getByteOffset());
94+
p.close();
95+
}
6096
}

0 commit comments

Comments
 (0)