Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improved JSONReader performance, fix #3627
- Loading branch information
Showing
2 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
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
51 changes: 51 additions & 0 deletions
51
src/test/java/com/alibaba/json/bvt/parser/stream/JSONReaderTest_5.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,51 @@ | ||
package com.alibaba.json.bvt.parser.stream; | ||
|
||
import com.alibaba.fastjson.JSONArray; | ||
import com.alibaba.fastjson.JSONObject; | ||
import com.alibaba.fastjson.JSONReader; | ||
import junit.framework.TestCase; | ||
import org.junit.Assert; | ||
|
||
import java.io.InputStream; | ||
import java.io.InputStreamReader; | ||
import java.io.StringReader; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class JSONReaderTest_5 extends TestCase { | ||
public void test_read() throws Exception { | ||
final int COUNT = 1000 * 10; | ||
StringBuilder buf = new StringBuilder(); | ||
buf.append('['); | ||
for (int i = 0; i < COUNT; ++i) { | ||
if (i != 0) { | ||
buf.append(','); | ||
} | ||
buf.append("{\"id\":").append(i).append('}'); | ||
} | ||
buf.append(']'); | ||
|
||
|
||
JSONReader reader = new JSONReader(new StringReader(buf.toString())); | ||
|
||
reader.startArray(); | ||
Map map = new HashMap(); | ||
int count = 0; | ||
for (;;) { | ||
if (reader.hasNext()) { | ||
reader.startObject(); | ||
String key = reader.readString(); | ||
Long value = reader.readLong(); | ||
reader.endObject(); | ||
count++; | ||
} else { | ||
break; | ||
} | ||
} | ||
assertEquals(COUNT, count); | ||
|
||
reader.endArray(); | ||
|
||
reader.close(); | ||
} | ||
} |