List of usage examples for com.google.gson.stream JsonToken NAME
JsonToken NAME
To view the source code for com.google.gson.stream JsonToken NAME.
Click Source Link
From source file:org.bimserver.emf.SharedJsonDeserializer.java
License:Open Source License
@SuppressWarnings("rawtypes") public IfcModelInterface read(InputStream in, IfcModelInterface model, boolean checkWaitingList) throws DeserializeException { if (model.getPackageMetaData().getSchemaDefinition() == null) { throw new DeserializeException("No SchemaDefinition available"); }/*from ww w . jav a 2 s . co m*/ WaitingList<Long> waitingList = new WaitingList<Long>(); final boolean log = false; if (log) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { IOUtils.copy(in, baos); File file = new File("debug.json"); System.out.println(file.getAbsolutePath()); FileUtils.writeByteArrayToFile(file, baos.toByteArray()); } catch (IOException e) { e.printStackTrace(); } in = new ByteArrayInputStream(baos.toByteArray()); } JsonReader jsonReader = new JsonReader(new InputStreamReader(in, Charsets.UTF_8)); int nrObjects = 0; try { JsonToken peek = jsonReader.peek(); if (peek != null && peek == JsonToken.BEGIN_OBJECT) { jsonReader.beginObject(); peek = jsonReader.peek(); while (peek == JsonToken.NAME) { String nextName = jsonReader.nextName(); if (nextName.equals("objects")) { jsonReader.beginArray(); while (jsonReader.hasNext()) { nrObjects++; processObject(model, waitingList, jsonReader, null); } jsonReader.endArray(); } else if (nextName.equals("header")) { IfcHeader ifcHeader = (IfcHeader) processObject(model, waitingList, jsonReader, StorePackage.eINSTANCE.getIfcHeader()); model.getModelMetaData().setIfcHeader(ifcHeader); } peek = jsonReader.peek(); } jsonReader.endObject(); } } catch (IOException e) { LOGGER.error("", e); } catch (IfcModelInterfaceException e) { LOGGER.error("", e); } finally { LOGGER.info("# Objects: " + nrObjects); try { jsonReader.close(); } catch (IOException e) { LOGGER.error("", e); } } boolean checkUnique = false; if (checkUnique) { for (IdEObject idEObject : model.getValues()) { for (EStructuralFeature eStructuralFeature : idEObject.eClass().getEAllStructuralFeatures()) { Object value = idEObject.eGet(eStructuralFeature); if (eStructuralFeature instanceof EReference) { if (eStructuralFeature.isMany()) { List list = (List) value; if (eStructuralFeature.isUnique()) { Set<Object> t = new HashSet<>(); for (Object v : list) { if (t.contains(v)) { // LOGGER.error("NOT UNIQUE " + idEObject.eClass().getName() + "." + eStructuralFeature.getName()); } t.add(v); } } } } } } } if (checkWaitingList && waitingList.size() > 0) { try { waitingList.dumpIfNotEmpty(); } catch (BimServerClientException e) { e.printStackTrace(); } throw new DeserializeException("Waitinglist should be empty (" + waitingList.size() + ")"); } return model; }
From source file:org.eclipse.skalli.core.rest.JSONRestReader.java
License:Open Source License
@Override public boolean isKey() throws IOException { if (state == STATE_FINAL) { return false; }//w w w . j a v a 2s .com return lookAhead != null || json.peek() == JsonToken.NAME; }
From source file:org.eclipse.skalli.core.rest.JSONRestReader.java
License:Open Source License
@Override public boolean isKeyAnyOf(String... keys) throws IOException { if (state == STATE_FINAL) { return false; }// w w w . j a va 2s . c o m if (keys == null) { return false; } if (lookAhead == null) { if (json.peek() != JsonToken.NAME) { return false; } lookAhead = key(); } for (String key : keys) { if (key.equals(lookAhead)) { return true; } } return false; }
From source file:org.gradle.api.internal.artifacts.ivyservice.ivyresolve.parser.ModuleMetadataParser.java
License:Apache License
public void parse(final LocallyAvailableExternalResource resource, final MutableModuleComponentResolveMetadata metadata) { resource.withContent(new Transformer<Void, InputStream>() { @Override/*from ww w. j av a 2s . co m*/ public Void transform(InputStream inputStream) { try { JsonReader reader = new JsonReader(new InputStreamReader(inputStream, "utf-8")); reader.beginObject(); if (reader.peek() != JsonToken.NAME) { throw new RuntimeException("Module metadata should contain a 'formatVersion' value."); } String name = reader.nextName(); if (!name.equals("formatVersion")) { throw new RuntimeException(String.format( "The 'formatVersion' value should be the first value in a module metadata. Found '%s' instead.", name)); } if (reader.peek() != JsonToken.STRING) { throw new RuntimeException("The 'formatVersion' value should have a string value."); } String version = reader.nextString(); if (!version.equals(FORMAT_VERSION)) { throw new RuntimeException(String.format( "Unsupported format version '%s' specified in module metadata. This version of Gradle supports format version %s only.", version, FORMAT_VERSION)); } consumeTopLevelElements(reader, metadata); return null; } catch (Exception e) { throw new MetaDataParseException("module metadata", resource, e); } } }); }
From source file:org.immutables.gson.stream.JsonParserReader.java
License:Apache License
private static JsonToken toGsonToken(com.fasterxml.jackson.core.JsonToken token) { switch (token) { case START_ARRAY: return JsonToken.BEGIN_ARRAY; case END_ARRAY: return JsonToken.END_ARRAY; case START_OBJECT: return JsonToken.BEGIN_OBJECT; case END_OBJECT: return JsonToken.END_OBJECT; case FIELD_NAME: return JsonToken.NAME; case VALUE_FALSE: return JsonToken.BOOLEAN; case VALUE_TRUE: return JsonToken.BOOLEAN; case VALUE_NULL: return JsonToken.NULL; case VALUE_NUMBER_INT: return JsonToken.NUMBER; case VALUE_NUMBER_FLOAT: return JsonToken.NUMBER; case VALUE_STRING: return JsonToken.STRING; default: // Not semantically equivalent return JsonToken.NULL; }// w ww . j a v a 2 s. com }
From source file:org.immutables.mongo.bson4gson.BsonReader.java
License:Apache License
@Override public JsonToken peek() throws IOException { switch (state()) { case INITIAL: case SCOPE_DOCUMENT: case TYPE://from w w w . ja v a 2 s .c o m advance(); return toGsonToken(delegate.getCurrentBsonType()); case NAME: return JsonToken.NAME; case END_OF_DOCUMENT: return JsonToken.END_OBJECT; case END_OF_ARRAY: return JsonToken.END_ARRAY; case DONE: return JsonToken.END_DOCUMENT; case VALUE: return toGsonToken(delegate.getCurrentBsonType()); default: throw new IllegalStateException( "Unexpected state: " + state() + " currentType:" + delegate.getCurrentBsonType()); } }
From source file:org.jclouds.http.functions.ParseFirstJsonValueNamed.java
License:Apache License
private boolean nnn(JsonReader reader, JsonToken token, AtomicReference<String> name) throws IOException { if (token == JsonToken.NAME) { String name2 = reader.nextName(); if (nameChoices.contains(name2)) { name.set(name2);/*from w ww .j a v a 2 s . co m*/ return false; } } return true; }
From source file:org.jetbrains.io.JsonReaderEx.java
License:Apache License
/** * Returns the type of the next token without consuming it. */// w w w . ja v a 2 s . co m public JsonToken peek() { int p = peeked; if (p == PEEKED_NONE) { p = doPeek(); } switch (p) { case PEEKED_BEGIN_OBJECT: return JsonToken.BEGIN_OBJECT; case PEEKED_END_OBJECT: return JsonToken.END_OBJECT; case PEEKED_BEGIN_ARRAY: return JsonToken.BEGIN_ARRAY; case PEEKED_END_ARRAY: return JsonToken.END_ARRAY; case PEEKED_SINGLE_QUOTED_NAME: case PEEKED_DOUBLE_QUOTED_NAME: case PEEKED_UNQUOTED_NAME: return JsonToken.NAME; case PEEKED_TRUE: case PEEKED_FALSE: return JsonToken.BOOLEAN; case PEEKED_NULL: return JsonToken.NULL; case PEEKED_SINGLE_QUOTED: case PEEKED_DOUBLE_QUOTED: case PEEKED_UNQUOTED: case PEEKED_BUFFERED: return JsonToken.STRING; case PEEKED_LONG: case PEEKED_NUMBER: return JsonToken.NUMBER; case PEEKED_EOF: return JsonToken.END_DOCUMENT; default: throw new AssertionError(); } }
From source file:org.mythdroid.services.GuideService.java
License:Open Source License
/** * Get ProgramGuide data//www . ja v a 2 s. com * @param start Date for start of data * @param end Date for end of data * @return ArrayList of Channels */ public ArrayList<Channel> GetProgramGuide(Date start, Date end) throws IOException { final Params params = new Params(); params.put("StartTime", Globals.utcFormat(start)); //$NON-NLS-1$ params.put("EndTime", Globals.utcFormat(end)); //$NON-NLS-1$ params.put("StartChanId", 0); //$NON-NLS-1$ params.put("NumChannels", -1); //$NON-NLS-1$ params.put("Details", "true"); //$NON-NLS-1$ //$NON-NLS-2$ InputStream is = jc.GetStream("GetProgramGuide", params); //$NON-NLS-1$ JsonReader jreader = new JsonReader(new BufferedReader(new InputStreamReader(is, "UTF-8")) //$NON-NLS-1$ ); ArrayList<Channel> channels = new ArrayList<Channel>(); jreader.beginObject(); skipTo(jreader, JsonToken.BEGIN_OBJECT); jreader.beginObject(); skipTo(jreader, JsonToken.NAME); while (jreader.hasNext()) { String name = jreader.nextName(); if (name.equals("NumOfChannels")) { //$NON-NLS-1$ channels.ensureCapacity(jreader.nextInt()); break; } jreader.skipValue(); } skipTo(jreader, JsonToken.BEGIN_ARRAY); jreader.beginArray(); while (jreader.hasNext()) { jreader.beginObject(); channels.add((Channel) gson.fromJson(jreader, Channel.class)); jreader.endObject(); } jreader.endArray(); jreader.endObject(); jreader.endObject(); jreader.close(); jc.endStream(); return channels; }
From source file:org.translator.java.AppInventorProperties.java
License:Apache License
protected AppInventorProperties(JsonReader reader) throws IOException { reader.beginObject();//from w ww. j a v a2s .c o m while (reader.peek() == JsonToken.NAME) { String name = reader.nextName(); if (name.equals("$Components")) { reader.beginArray(); while (reader.peek() == JsonToken.BEGIN_OBJECT) components.add(new AppInventorProperties(reader)); reader.endArray(); } else { String n = reader.nextString(); if (n.matches("True|False")) n = n.toLowerCase(); properties.put(name, n); } } reader.endObject(); }