本文整理汇总了Java中javax.json.stream.JsonParser.close方法的典型用法代码示例。如果您正苦于以下问题:Java JsonParser.close方法的具体用法?Java JsonParser.close怎么用?Java JsonParser.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.json.stream.JsonParser
的用法示例。
在下文中一共展示了JsonParser.close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testGetInt_2
import javax.json.stream.JsonParser; //导入方法依赖的package包/类
@Test
public void testGetInt_2 () throws IOException
{
File file = new File ("../tests/data/types.json".replace ('/', File.separatorChar));
JsonParser p = getJsonParser (file, 1);
int[] ints = new int[9];
int count = 0;
while (p.hasNext ())
{
if (p.next () == Event.VALUE_NUMBER)
{
ints[count++] = p.getInt ();
}
}
p.close ();
Assert.assertArrayEquals (new int[]{ 1234, 1942892530, -115429390, 12345, 1234, 1942892530, -115429390, 12345, 1 }, ints);
}
示例2: testFile
import javax.json.stream.JsonParser; //导入方法依赖的package包/类
void testFile (String f1, String f2) throws IOException
{
File file1 = new File (f1.replace ('/', File.separatorChar));
File file2 = new File (f2.replace ('/', File.separatorChar));
StringWriter out1 = new StringWriter ();
BsonParser p1 = new BsonParser (new FileInputStream (file1));
p1.setRootAsArray (true);
Assert.assertEquals (true, p1.isRootAsArray ());
TextJsonGenerator g1 = new TextJsonGenerator (out1);
Utils.convert (p1, g1);
p1.close ();
g1.close ();
StringWriter out2 = new StringWriter ();
JsonProvider provider = new org.glassfish.json.JsonProviderImpl ();
JsonParser p2 = provider.createParser (new FileInputStream (file2));
JsonGenerator g2 = new TextJsonGenerator (out2);
Utils.convert (p2, g2);
p2.close ();
g2.close ();
Assert.assertEquals (out1.toString (), out2.toString ());
}
示例3: testNumber1
import javax.json.stream.JsonParser; //导入方法依赖的package包/类
@Test
public void testNumber1 ()
{
String json = "{\"abc\" : 0 }";
JsonParser p = new UTF8TextJsonParser (new ByteArrayInputStream (json.getBytes (BOM.utf8)));
while (p.hasNext ())
{
switch (p.next ())
{
case VALUE_NUMBER:
Assert.assertEquals ("0", p.getString ());
break;
default:
break;
}
}
p.close ();
}
示例4: testFile
import javax.json.stream.JsonParser; //导入方法依赖的package包/类
private void testFile (Charset charset) throws IOException
{
File file = new File ("../tests/data/types.json".replace ('/', File.separatorChar));
CookJsonProvider provider = new CookJsonProvider ();
ByteArrayOutputStream bos = new ByteArrayOutputStream ();
JsonParser p = TextJsonConfigHandler.getJsonParser (new FileInputStream (file));
JsonGenerator g = provider.createGeneratorFactory (new HashMap<String, Object> ()).createGenerator (bos, charset);
Utils.convert (p, g);
p.close ();
g.close ();
StringWriter sw = new StringWriter ();
p = provider.createParser (new ByteArrayInputStream (bos.toByteArray ()));
g = provider.createGenerator (sw);
Utils.convert (p, g);
p.close ();
g.close ();
Assert.assertEquals (Utils.getString (file), sw.toString ());
}
示例5: testNumber2
import javax.json.stream.JsonParser; //导入方法依赖的package包/类
@Test
public void testNumber2 ()
{
String json = "{\"abc\" : 0.1 }";
JsonParser p = new UTF8TextJsonParser (new ByteArrayInputStream (json.getBytes (BOM.utf8)));
while (p.hasNext ())
{
switch (p.next ())
{
case VALUE_NUMBER:
Assert.assertEquals ("0.1", p.getString ());
break;
default:
break;
}
}
p.close ();
}
示例6: testNumber6
import javax.json.stream.JsonParser; //导入方法依赖的package包/类
@Test
public void testNumber6 ()
{
String json = "{\"abc\" : -0.1234567890 }";
JsonParser p = new UTF8TextJsonParser (new ByteArrayInputStream (json.getBytes (BOM.utf8)));
while (p.hasNext ())
{
switch (p.next ())
{
case VALUE_NUMBER:
Assert.assertEquals ("-0.1234567890", p.getString ());
break;
default:
break;
}
}
p.close ();
}
示例7: testFile
import javax.json.stream.JsonParser; //导入方法依赖的package包/类
void testFile (String f) throws IOException
{
File file = new File (f.replace ('/', File.separatorChar));
JsonProvider provider = new org.glassfish.json.JsonProviderImpl ();
StringWriter out1 = new StringWriter ();
JsonParser p1 = provider.createParser (new FileInputStream (file));
TextJsonGenerator g1 = new TextJsonGenerator (out1);
Utils.convert (p1, g1);
p1.close ();
g1.close ();
StringWriter out2 = new StringWriter ();
JsonParser p2 = provider.createParser (new FileInputStream (file));
JsonGenerator g2 = provider.createGenerator (out2);
Utils.convert (p2, g2);
p2.close ();
g2.close ();
Assert.assertEquals (out1.toString (), out2.toString ());
}
示例8: testGetInt
import javax.json.stream.JsonParser; //导入方法依赖的package包/类
@Test
public void testGetInt () throws IOException
{
File file = new File ("../tests/data/types.json".replace ('/', File.separatorChar));
JsonParser p = getJsonParser (file, 0);
int[] ints = new int[9];
int count = 0;
while (p.hasNext ())
{
if (p.next () == Event.VALUE_NUMBER)
{
ints[count++] = p.getInt ();
}
}
p.close ();
Assert.assertArrayEquals (new int[]
{ 1234, 1942892530, -115429390, 12345, 1234, 1942892530, -115429390, 12345, 1 }, ints);
}
示例9: testGetInt
import javax.json.stream.JsonParser; //导入方法依赖的package包/类
@Test
public void testGetInt () throws IOException
{
File file = new File ("../tests/data/types.json".replace ('/', File.separatorChar));
JsonParser p = getJsonParser (file, 0);
int[] ints = new int[9];
int count = 0;
while (p.hasNext ())
{
if (p.next () == Event.VALUE_NUMBER)
{
ints[count++] = p.getInt ();
}
}
p.close ();
Assert.assertArrayEquals (new int[]{ 1234, 1942892530, -115429390, 12345, 1234, 1942892530, -115429390, 12345, 1 }, ints);
}
示例10: testGetLong
import javax.json.stream.JsonParser; //导入方法依赖的package包/类
@Test
public void testGetLong () throws IOException
{
File file = new File ("../tests/data/types.json".replace ('/', File.separatorChar));
JsonParser p = getJsonParser (file, 0);
long[] longs = new long[9];
int count = 0;
while (p.hasNext ())
{
if (p.next () == Event.VALUE_NUMBER)
{
longs[count++] = p.getLong ();
}
}
p.close ();
Assert.assertArrayEquals (new long[]
{ 1234, 12345678901234L, 7888426545362939890L, 12345, 1234, 12345678901234L, 7888426545362939890L, 12345, 1 },
longs);
}
示例11: testGetLong_2
import javax.json.stream.JsonParser; //导入方法依赖的package包/类
@Test
public void testGetLong_2 () throws IOException
{
File file = new File ("../tests/data/types.json".replace ('/', File.separatorChar));
JsonParser p = getJsonParser (file, 1);
long[] longs = new long[9];
int count = 0;
while (p.hasNext ())
{
if (p.next () == Event.VALUE_NUMBER)
{
longs[count++] = p.getLong ();
}
}
p.close ();
Assert.assertArrayEquals (new long[]
{ 1234, 12345678901234L, 7888426545362939890L, 12345, 1234, 12345678901234L, 7888426545362939890L, 12345, 1 },
longs);
}
示例12: testGetDecimal
import javax.json.stream.JsonParser; //导入方法依赖的package包/类
@Test
public void testGetDecimal () throws IOException
{
File file = new File ("../tests/data/types.json".replace ('/', File.separatorChar));
JsonParser p = getJsonParser (file, 0);
BigDecimal[] decimals = new BigDecimal[9];
int count = 0;
while (p.hasNext ())
{
if (p.next () == Event.VALUE_NUMBER)
{
decimals[count++] = p.getBigDecimal ();
}
}
p.close ();
Assert.assertArrayEquals (new BigDecimal[]
{ new BigDecimal (1234), new BigDecimal (12345678901234L), new BigDecimal ("1234567890123412345678901234"),
new BigDecimal (12345.5), new BigDecimal (1234), new BigDecimal (12345678901234L),
new BigDecimal ("1234567890123412345678901234"), new BigDecimal (12345.5), new BigDecimal (1) },
decimals);
}
示例13: testCookJson
import javax.json.stream.JsonParser; //导入方法依赖的package包/类
@Benchmark
public void testCookJson () throws IOException
{
JsonProvider glassFishProvider = new JsonProviderImpl ();
JsonProvider provider = new CookJsonProvider ();
JsonParser p = glassFishProvider.createParser (getReader ());
JsonGenerator g = provider.createGenerator (new StringWriter ());
Utils.convert (p, g);
p.close ();
g.close ();
}
示例14: testGlassFish
import javax.json.stream.JsonParser; //导入方法依赖的package包/类
@Benchmark
public void testGlassFish () throws IOException
{
JsonProvider glassFishProvider = new JsonProviderImpl ();
JsonParser p = glassFishProvider.createParser (getReader ());
JsonGenerator g = glassFishProvider.createGenerator (new StringWriter ());
Utils.convert (p, g);
p.close ();
g.close ();
}
示例15: testGlassFish
import javax.json.stream.JsonParser; //导入方法依赖的package包/类
@Benchmark
public void testGlassFish () throws IOException
{
JsonProvider provider = new JsonProviderImpl ();
JsonParser p = provider.createParser (getReader ());
perfTest (p);
p.close ();
}