本文整理汇总了Java中javax.json.stream.JsonParserFactory.createParser方法的典型用法代码示例。如果您正苦于以下问题:Java JsonParserFactory.createParser方法的具体用法?Java JsonParserFactory.createParser怎么用?Java JsonParserFactory.createParser使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.json.stream.JsonParserFactory
的用法示例。
在下文中一共展示了JsonParserFactory.createParser方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testReader
import javax.json.stream.JsonParserFactory; //导入方法依赖的package包/类
void testReader (String fileName, HashMap<String, Object> config) throws IOException
{
File file = new File (fileName.replace ('/', File.separatorChar));
JsonProvider provider1 = new CookJsonProvider ();
JsonParserFactory f1 = provider1.createParserFactory (config);
StringWriter out1 = new StringWriter ();
JsonParser p1 = f1.createParser (new InputStreamReader (new FileInputStream (file), BOM.utf8));
JsonGenerator g1 = new TextJsonGenerator (out1);
Utils.convert (p1, g1);
p1.close ();
g1.close ();
StringWriter out2 = new StringWriter ();
JsonProvider provider2 = new org.glassfish.json.JsonProviderImpl ();
JsonParserFactory f2 = provider2.createParserFactory (config);
JsonParser p2 = f2.createParser (new InputStreamReader (new FileInputStream (file), BOM.utf8));
JsonGenerator g2 = new TextJsonGenerator (out2);
Utils.convert (p2, g2);
p2.close ();
g2.close ();
Assert.assertEquals (out1.toString (), out2.toString ());
}
示例2: testInputStream
import javax.json.stream.JsonParserFactory; //导入方法依赖的package包/类
void testInputStream (String fileName, HashMap<String, Object> config) throws IOException
{
File file = new File (fileName.replace ('/', File.separatorChar));
JsonProvider provider1 = new CookJsonProvider ();
JsonParserFactory f1 = provider1.createParserFactory (config);
StringWriter out1 = new StringWriter ();
JsonParser p1 = f1.createParser (new FileInputStream (file));
JsonGenerator g1 = new TextJsonGenerator (out1);
Utils.convert (p1, g1);
p1.close ();
g1.close ();
StringWriter out2 = new StringWriter ();
JsonProvider provider2 = new org.glassfish.json.JsonProviderImpl ();
JsonParserFactory f2 = provider2.createParserFactory (config);
JsonParser p2 = f2.createParser (new FileInputStream (file));
JsonGenerator g2 = new TextJsonGenerator (out2);
Utils.convert (p2, g2);
p2.close ();
g2.close ();
Assert.assertEquals (out1.toString (), out2.toString ());
}
示例3: testCharset
import javax.json.stream.JsonParserFactory; //导入方法依赖的package包/类
void testCharset (String fileName, HashMap<String, Object> config) throws IOException
{
File file = new File (fileName.replace ('/', File.separatorChar));
JsonProvider provider1 = new CookJsonProvider ();
JsonParserFactory f1 = provider1.createParserFactory (config);
StringWriter out1 = new StringWriter ();
JsonParser p1 = f1.createParser (new FileInputStream (file), BOM.utf8);
JsonGenerator g1 = new TextJsonGenerator (out1);
Utils.convert (p1, g1);
p1.close ();
g1.close ();
StringWriter out2 = new StringWriter ();
JsonProvider provider2 = new org.glassfish.json.JsonProviderImpl ();
JsonParserFactory f2 = provider2.createParserFactory (config);
JsonParser p2 = f2.createParser (new FileInputStream (file), BOM.utf8);
JsonGenerator g2 = new TextJsonGenerator (out2);
Utils.convert (p2, g2);
p2.close ();
g2.close ();
Assert.assertEquals (out1.toString (), out2.toString ());
}
示例4: run
import javax.json.stream.JsonParserFactory; //导入方法依赖的package包/类
@Test
@Ignore("buggy but pushing to share the use case")
public void run() throws NoSuchFieldException, IllegalAccessException { // shouldnt fail by default
final JsonParserFactory factory = Json.createParserFactory(emptyMap());
final int length = 1024 * 1024;
assertEquals(0, get(Queue.class, get(
BufferStrategy.BufferProvider.class, factory, "bufferProvider"), "queue").size());
try (final JsonParser parser = factory.createParser(newDynamicInput(length))) {
int eventCount = 0;
while (parser.hasNext()) {
eventCount++;
final JsonParser.Event next = parser.next();
if (eventCount == 2 && next == JsonParser.Event.VALUE_STRING) {
assertEquals(length, parser.getString().length());
}
}
}
assertEquals(1, get(Queue.class, get(
BufferStrategy.BufferProvider.class, factory, "bufferProvider"), "queue").size());
}
示例5: createParser
import javax.json.stream.JsonParserFactory; //导入方法依赖的package包/类
private JsonParser createParser (JsonProvider provider, JsonValue value)
{
HashMap<String, Object> config = new HashMap<String, Object> ();
JsonParserFactory f = provider.createParserFactory (config);
if (value instanceof JsonArray)
return f.createParser ((JsonArray)value);
else if (value instanceof JsonObject)
return f.createParser ((JsonObject)value);
throw new IllegalArgumentException ("Invalid value type.");
}