| import org.codehaus.jackson.*; |
| public class GenerateIntDoc |
| final static int AVG_ARRAY_LEN = 32; |
| private GenerateIntDoc() { } |
| private void generate(OutputStream out, int kbSize) |
| int bsize = kbSize * 1000; |
| // Let's first buffer in memory, to know exact length |
| ByteArrayOutputStream bos = new ByteArrayOutputStream(bsize + 500); |
| Random r = new Random(kbSize); |
| JsonGenerator gen = new JsonFactory().createJsonGenerator(bos, JsonFactory.Encoding.UTF8); |
| gen.writeStartArray(); // outermost array |
| gen.writeStartArray(); // inner array |
| // First, do we close current, start new array? |
| if (r.nextInt(AVG_ARRAY_LEN) == 3) { // to get average array length of 16 |
| // Then need to calculate number to output |
| nr *= r.nextInt(256); // up to 8k |
| nr *= r.nextInt(0x20000); // up to 1G |
| } while (bos.size() < bsize); |
| public static void main(String[] args) |
| System.err.println("Usage: java test.GenerateIntDoc <size-in-kbytes>"); |
| new GenerateIntDoc().generate(System.out, Integer.parseInt(args[0])); |