This repository has been archived by the owner on Jan 22, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Back port #13 test; 2.5 does not have this bug.
- Loading branch information
1 parent
d9c97bc
commit 8166462
Showing
1 changed file
with
49 additions
and
0 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
src/test/java/com/fasterxml/jackson/dataformat/cbor/ParserInputStreamTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.fasterxml.jackson.dataformat.cbor; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import org.junit.Test; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.IOException; | ||
import java.io.SequenceInputStream; | ||
|
||
public class ParserInputStreamTest extends CBORTestBase { | ||
|
||
@Test | ||
public void testInpuStream() throws Exception { | ||
CBORFactory f = new CBORFactory(); | ||
ObjectMapper cborMapper = new ObjectMapper(new CBORFactory()); | ||
byte[] buffer = generateHugeCBOR(f); | ||
|
||
// split the buffer in two smaller buffer | ||
int len = 160; | ||
byte[] buf1 = new byte[len]; | ||
byte[] buf2 = new byte[buffer.length - len]; | ||
System.arraycopy(buffer, 0, buf1, 0, len); | ||
System.arraycopy(buffer, len, buf2, 0, buffer.length - len); | ||
|
||
// aggregate the two buffers via a SequenceInputStream | ||
ByteArrayInputStream in1 = new ByteArrayInputStream(buf1); | ||
ByteArrayInputStream in2 = new ByteArrayInputStream(buf2); | ||
SequenceInputStream inputStream = new SequenceInputStream(in1, in2); | ||
|
||
JsonNode jsonNode = cborMapper.readTree(inputStream); | ||
assertNotNull(jsonNode); | ||
} | ||
|
||
private byte[] generateHugeCBOR(CBORFactory f) throws IOException { | ||
String hugeJson = "{"; | ||
for (char c='a'; c <= 'z'; c++) { | ||
for (char cc='a'; cc <= 'z'; cc++) { | ||
hugeJson += "\"" + c + cc + "\":0,"; | ||
} | ||
for (int i = 0; i < 50; i++) { | ||
hugeJson += "\"" + c + i + "\":" + i + ","; | ||
} | ||
} | ||
hugeJson += "\"name\":123"; | ||
hugeJson += "}"; | ||
return cborDoc(f, hugeJson); | ||
} | ||
} |