package com.alibaba.fastjson.validate;

import com.alibaba.fastjson.JSONValidator;
import junit.framework.TestCase;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.io.Reader;

public class JSONValidateTest_file extends TestCase
{
    public void test_for_file() throws Exception {
        for (int i = 0; i < 10; ++i) {
            long start = System.currentTimeMillis();

            File file = new File("/Users/wenshao/Downloads/000002_0.json");
            FileInputStream is = new FileInputStream(file);
            JSONValidator validator = JSONValidator.fromUtf8(is);
            assertTrue(validator.validate());
            validator.close();

            // 642 335 796
            System.out.println("millis " + (System.currentTimeMillis() - start));
        }
    }

    public void test_for_fileReader() throws Exception {
        for (int i = 0; i < 10; ++i) {
            long start = System.currentTimeMillis();

            File file = new File("/Users/wenshao/Downloads/000002_0.json");
            Reader is = new InputStreamReader(new FileInputStream(file), "UTF8");
            JSONValidator validator = JSONValidator.from(is);
            assertTrue(validator.validate());
            validator.close();

            // 642 335 796
            System.out.println("millis " + (System.currentTimeMillis() - start));
        }
    }
}

@@ -109,16 +109,93 @@
 stCase;%0A
+import org.apache.commons.io.FileUtils;%0A%0Aimport java.io.ByteArrayInputStream;
 %0Aimport 
@@ -902,16 +902,637 @@
 %0A    %7D%0A%0A
+    public void test_for_file2() throws Exception %7B%0A        File file = new File(%22/Users/wenshao/Downloads/000002_0.json%22);%0A        byte%5B%5D bytes = FileUtils.readFileToByteArray(file);%0A%0A        for (int i = 0; i %3C 10; ++i) %7B%0A            long start = System.currentTimeMillis();%0A%0A            ByteArrayInputStream is = new ByteArrayInputStream(bytes);%0A%0A            JSONValidator validator = JSONValidator.fromUtf8(is);%0A            assertTrue(validator.validate());%0A            validator.close();%0A%0A            // 642 335 796%0A            System.out.println(%22millis %22 + (System.currentTimeMillis() - start));%0A        %7D%0A    %7D%0A%0A%0A
     publ

add test for file