android.util.JsonToken Java Examples

The following examples show how to use android.util.JsonToken. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NGWUtil.java    From android_maplib with GNU Lesser General Public License v3.0 6 votes vote down vote up
private static void readNGWFeatureAttachments(Feature feature, JsonReader reader)
        throws IOException
{
    //add extensions
    reader.beginObject();
    while (reader.hasNext()) {
        String name = reader.nextName();
        if (name.equals("attachment") && reader.peek() != JsonToken.NULL) {
            reader.beginArray();
            while (reader.hasNext()) {
                readNGWFeatureAttachment(feature, reader);
            }
            reader.endArray();
        } else {
            reader.skipValue();
        }
    }

    reader.endObject();
}
 
Example #2
Source File: GalleryData.java    From NClientV2 with Apache License 2.0 6 votes vote down vote up
private void parseJSON(JsonReader jr) throws IOException {
    jr.beginObject();
    while(jr.peek()!= JsonToken.END_OBJECT){
        switch(jr.nextName()){
            case "upload_date":uploadDate=new Date(jr.nextLong()*1000);break;
            case "num_favorites":favoriteCount=jr.nextInt();break;
            case "media_id":mediaId=jr.nextInt();break;
            case "title":readTitles(jr);break;
            case "images":readImages(jr); break;
            case "tags":readTags(jr);break;
            case "id":id=jr.nextInt();break;
            case "num_pages":pageCount=jr.nextInt();break;
            case "error":jr.skipValue(); valid=false;break;
            default:jr.skipValue();break;
        }
    }
    jr.endObject();
}
 
Example #3
Source File: GalleryData.java    From NClientV2 with Apache License 2.0 6 votes vote down vote up
private void readImages(JsonReader jr) throws IOException {
    int actualPage=0;
    jr.beginObject();
    while (jr.peek()!=JsonToken.END_OBJECT){
        switch (jr.nextName()){
            case "cover":
                cover= new Page(ImageType.COVER,jr);
                break;
            case "pages":
                jr.beginArray();
                while(jr.hasNext())
                    pages.add(new Page(ImageType.PAGE,jr,actualPage++));
                jr.endArray();
                break;
            case "thumbnail":
                thumbnail= new Page(ImageType.THUMBNAIL,jr);
                break;
            default:
                jr.skipValue();
                break;
        }
    }
    jr.endObject();
    pages.trimToSize();
}
 
Example #4
Source File: BundleDeltaClient.java    From react-native-GPay with MIT License 6 votes vote down vote up
private static int patchDelta(JsonReader jsonReader, LinkedHashMap<Number, byte[]> map)
  throws IOException {
  jsonReader.beginArray();

  int numModules = 0;
  while (jsonReader.hasNext()) {
    jsonReader.beginArray();

    int moduleId = jsonReader.nextInt();

    if (jsonReader.peek() == JsonToken.NULL) {
      jsonReader.skipValue();
      map.remove(moduleId);
    } else {
      map.put(moduleId, jsonReader.nextString().getBytes());
    }

    jsonReader.endArray();
    numModules++;
  }

  jsonReader.endArray();

  return numModules;
}
 
Example #5
Source File: LogResponse.java    From firebase-android-sdk with Apache License 2.0 6 votes vote down vote up
@NonNull
public static LogResponse fromJson(@NonNull Reader reader) throws IOException {
  JsonReader jsonReader = new JsonReader(reader);
  try {
    jsonReader.beginObject();
    while (jsonReader.hasNext()) {
      String name = jsonReader.nextName();
      if (name.equals("nextRequestWaitMillis")) {
        if (jsonReader.peek() == JsonToken.STRING) {
          return LogResponse.create(Long.parseLong(jsonReader.nextString()));
        } else {
          return LogResponse.create(jsonReader.nextLong());
        }
      }
      jsonReader.skipValue();
    }
    throw new IOException("Response is missing nextRequestWaitMillis field.");
  } finally {
    jsonReader.close();
  }
}
 
Example #6
Source File: Comment.java    From NClientV2 with Apache License 2.0 5 votes vote down vote up
public Comment(JsonReader reader) throws IOException {
    reader.beginObject();
    while(reader.peek()!= JsonToken.END_OBJECT){
        switch (reader.nextName()){
            case "id":id=reader.nextInt();break;
            case "post_date":postDate=new Date(reader.nextLong()*1000);break;
            case "body":body=reader.nextString();break;
            case "poster":poster=new User(reader);break;
            default:reader.skipValue();break;
        }
    }
    reader.endObject();
}
 
Example #7
Source File: NGWUtil.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
private static void readNGWFeatureAttachment(Feature feature, JsonReader reader)
        throws IOException
{
    reader.beginObject();
    String attachId = "";
    String name = "";
    String mime = "";
    String descriptionText = "";
    while (reader.hasNext()) {
        String keyName = reader.nextName();
        if (reader.peek() == JsonToken.NULL) {
            reader.skipValue();
            continue;
        }

        if (keyName.equals(NGWUtil.NGWKEY_ID)) {
            attachId += reader.nextLong();
        } else if (keyName.equals(NGWUtil.NGWKEY_NAME)) {
            name += reader.nextString();
        } else if (keyName.equals(NGWUtil.NGWKEY_MIME)) {
            mime += reader.nextString();
        } else if (keyName.equals(NGWUtil.NGWKEY_DESCRIPTION)) {
            descriptionText += reader.nextString();
        } else {
            reader.skipValue();
        }
    }
    AttachItem item = new AttachItem(attachId, name, mime, descriptionText);
    feature.addAttachment(item);

    reader.endObject();
}
 
Example #8
Source File: NGWUtil.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static Feature readNGWFeature(
        JsonReader reader,
        List<Field> fields,
        int nSRS)
        throws IOException, IllegalStateException, NumberFormatException, OutOfMemoryError
{
    final Feature feature = new Feature(Constants.NOT_FOUND, fields);

    reader.beginObject();
    while (reader.hasNext()) {
        String name = reader.nextName();
        if (name.equals(NGWUtil.NGWKEY_ID)) {
            feature.setId(reader.nextLong());
        } else if (name.equals(NGWUtil.NGWKEY_GEOM)) {
            String wkt = reader.nextString();
            GeoGeometry geom = GeoGeometryFactory.fromWKT(wkt, nSRS);
            geom.setCRS(nSRS);
            if (nSRS != GeoConstants.CRS_WEB_MERCATOR) {
                geom.project(GeoConstants.CRS_WEB_MERCATOR);
            }
            feature.setGeometry(geom);
        } else if (name.equals(NGWUtil.NGWKEY_FIELDS)) {
            readNGWFeatureFields(feature, reader, fields);
        } else if (name.equals(NGWUtil.NGWKEY_EXTENSIONS)) {
            if (reader.peek() != JsonToken.NULL) {
                readNGWFeatureAttachments(feature, reader);
            }
        } else {
            reader.skipValue();
        }
    }
    reader.endObject();
    return feature;
}
 
Example #9
Source File: BlocklistProcessor.java    From focus-android with Mozilla Public License 2.0 5 votes vote down vote up
private static void extractSite(final JsonReader reader, final UrlListCallback callback) throws IOException {
    reader.beginObject();

    final String siteOwner = reader.nextName();
    {
        reader.beginObject();

        while (reader.hasNext()) {
            // We can get the site name using reader.nextName() here:
            reader.skipValue();

            JsonToken nextToken = reader.peek();

            if (nextToken.name().equals("STRING")) {
                // Sometimes there's a "dnt" entry, with unspecified purpose.
                reader.skipValue();
            } else {
                reader.beginArray();

                while (reader.hasNext()) {
                    final String blockURL = reader.nextString();
                    callback.put(blockURL, siteOwner);
                }

                reader.endArray();
            }
        }

        reader.endObject();
    }

    reader.endObject();
}
 
Example #10
Source File: ShareManager.java    From samba-documents-provider with GNU General Public License v3.0 5 votes vote down vote up
private static ShareTuple decodeTuple(JsonReader reader) throws IOException {
  if (reader.peek() == JsonToken.NULL) {
    reader.nextNull();
    return ShareTuple.EMPTY_TUPLE;
  }

  String workgroup = null;
  String username = null;
  String password = null;
  boolean mounted = true;

  reader.beginObject();
  while (reader.hasNext()) {
    String name = reader.nextName();

    switch (name) {
      case WORKGROUP_KEY:
        workgroup = reader.nextString();
        break;
      case USERNAME_KEY:
        username = reader.nextString();
        break;
      case PASSWORD_KEY:
        password = reader.nextString();
        break;
      case MOUNT_KEY:
        mounted = reader.nextBoolean();
      default:
        Log.w(TAG, "Ignoring unknown key " + name);
    }
  }
  reader.endObject();

  return new ShareTuple(workgroup, username, password, mounted);
}
 
Example #11
Source File: JSDebuggerWebSocketClient.java    From react-native-GPay with MIT License 5 votes vote down vote up
@Override
public void onMessage(WebSocket webSocket, String text) {
  Integer replyID = null;

  try {
    JsonReader reader = new JsonReader(new StringReader(text));
    String result = null;
    reader.beginObject();
    while (reader.hasNext()) {
      String field = reader.nextName();

      if (JsonToken.NULL == reader.peek()) {
        reader.skipValue();
        continue;
      }

      if ("replyID".equals(field)) {
        replyID = reader.nextInt();
      } else if ("result".equals(field)) {
        result = reader.nextString();
      } else if ("error".equals(field)) {
        String error = reader.nextString();
        abort(error, new JavascriptException(error));
      }
    }
    if (replyID != null) {
      triggerRequestSuccess(replyID, result);
    }
  } catch (IOException e) {
    if (replyID != null) {
      triggerRequestFailure(replyID, e);
    } else {
      abort("Parsing response message from websocket failed", e);
    }
  }
}
 
Example #12
Source File: BlocklistProcessor.java    From firefox-echo-show with Mozilla Public License 2.0 5 votes vote down vote up
private static void extractSite(final JsonReader reader, final UrlListCallback callback) throws IOException {
    reader.beginObject();

    final String siteOwner = reader.nextName();
    {
        reader.beginObject();

        while (reader.hasNext()) {
            // We can get the site name using reader.nextName() here:
            reader.skipValue();

            JsonToken nextToken = reader.peek();

            if (nextToken.name().equals("STRING")) {
                // Sometimes there's a "dnt" entry, with unspecified purpose.
                reader.skipValue();
            } else {
                reader.beginArray();

                while (reader.hasNext()) {
                    final String blockURL = reader.nextString();
                    callback.put(blockURL, siteOwner);
                }

                reader.endArray();
            }
        }

        reader.endObject();
    }

    reader.endObject();
}
 
Example #13
Source File: JSONParser.java    From guarda-android-wallets with GNU General Public License v3.0 5 votes vote down vote up
private static ZCashTransactionInput readTxSingleInput(JsonReader reader) throws IOException {
  ZCashTransactionInput input = new ZCashTransactionInput();
  reader.beginObject();
  while (reader.peek() != JsonToken.END_OBJECT) {
    String name = reader.nextName();
    switch (name) {
      case COINBASE:
        input.coinbase = reader.nextString();
        break;
      case SEQUENCE:
        input.sequence = reader.nextLong();
        break;
      case TXID:
        input.txid = reader.nextString();
        break;
      case VOUT:
        input.n = reader.nextLong();
        break;
      case SCRIPTSIG:
        reader.skipValue();
        break;
      case RETRIEVEDVOUT:
        input.copyDataFrom(readTxSingleOutput(reader));
        break;
      default:
        reader.skipValue();
    }
  }

  reader.endObject();
  return input;
}
 
Example #14
Source File: JSONParser.java    From guarda-android-wallets with GNU General Public License v3.0 5 votes vote down vote up
private static ZCashTransactionInput readTxSingleInput(JsonReader reader) throws IOException {
  ZCashTransactionInput input = new ZCashTransactionInput();
  reader.beginObject();
  while (reader.peek() != JsonToken.END_OBJECT) {
    String name = reader.nextName();
    switch (name) {
      case COINBASE:
        input.coinbase = reader.nextString();
        break;
      case SEQUENCE:
        input.sequence = reader.nextLong();
        break;
      case TXID:
        input.txid = reader.nextString();
        break;
      case VOUT:
        input.n = reader.nextLong();
        break;
      case SCRIPTSIG:
        reader.skipValue();
        break;
      case RETRIEVEDVOUT:
        input.copyDataFrom(readTxSingleOutput(reader));
        break;
      default:
        reader.skipValue();
    }
  }

  reader.endObject();
  return input;
}
 
Example #15
Source File: VersionChecker.java    From NClientV2 with Apache License 2.0 5 votes vote down vote up
private static String[] parseVersionJson(JsonReader jr) throws IOException {
    String[]vars=new String[3];//ver code,body,changelog
    jr.beginObject();
    while(jr.peek()!=JsonToken.END_OBJECT){
        switch (jr.nextName()){
            case "tag_name":vars[0]=jr.nextString();break;
            case "body":vars[1]=jr.nextString();break;
            case "assets":
                jr.beginArray();
                while(jr.hasNext()){
                    if(vars[2]!=null){
                        jr.skipValue();
                        continue;
                    }
                    jr.beginObject();
                    while(jr.peek()!=JsonToken.END_OBJECT){
                        if ("browser_download_url".equals(jr.nextName())) {
                            String url=jr.nextString();
                            if(url.contains("Release"))
                                vars[2] = url;
                        } else {
                            jr.skipValue();
                        }
                    }
                    jr.endObject();
                }
                jr.endArray();
                break;
            default:jr.skipValue();break;
        }
    }
    return vars;
}
 
Example #16
Source File: GalleryData.java    From NClientV2 with Apache License 2.0 5 votes vote down vote up
private void readTitles(JsonReader jr) throws IOException {
    jr.beginObject();
    while(jr.peek()!=JsonToken.END_OBJECT){
        switch (jr.nextName()){
            case "japanese":setTitle(TitleType.JAPANESE,jr.peek()!=JsonToken.NULL?jr.nextString():"");break;
            case "english": setTitle(TitleType.ENGLISH ,jr.peek()!=JsonToken.NULL?jr.nextString():"");break;
            case "pretty":  setTitle(TitleType.PRETTY  ,jr.peek()!=JsonToken.NULL?jr.nextString():"");break;
            default:jr.skipValue();break;
        }
        if(jr.peek()==JsonToken.NULL)jr.skipValue();
    }
    jr.endObject();
}
 
Example #17
Source File: Tag.java    From NClientV2 with Apache License 2.0 5 votes vote down vote up
public Tag(JsonReader jr) throws IOException {
    jr.beginObject();
    while(jr.peek()!= JsonToken.END_OBJECT){
        switch (jr.nextName()){
            case "count":count=jr.nextInt();break;
            case "type":type=TagType.typeByName(jr.nextString());break;
            case "id":id=jr.nextInt();break;
            case "name":name=jr.nextString();break;
            case "url": LogUtility.d("Tag URL: "+jr.nextString());break;
            default:jr.skipValue();break;
        }
    }
    jr.endObject();
}
 
Example #18
Source File: Page.java    From NClientV2 with Apache License 2.0 5 votes vote down vote up
public Page(ImageType type, JsonReader reader,int page)throws IOException{
    this.imageType=type;
    this.page=page;
    reader.beginObject();
    while (reader.peek()!= JsonToken.END_OBJECT){
        switch (reader.nextName()){
            case "t":imageExt=stringToExt(reader.nextString()); break;
            case "w":size.setWidth(reader.nextInt());  break;
            case "h":size.setHeight(reader.nextInt()); break;
            default:reader.skipValue();break;
        }
    }
    reader.endObject();
}
 
Example #19
Source File: User.java    From NClientV2 with Apache License 2.0 5 votes vote down vote up
public User(JsonReader reader) throws IOException {
    reader.beginObject();
    while(reader.peek()!= JsonToken.END_OBJECT){
        switch (reader.nextName()){
            case "id":id=reader.nextInt();break;
            case "post_date":username=reader.nextString();break;
            case "avatar_url":avatarUrl=reader.nextString();break;
            default:reader.skipValue();break;
        }
    }
    reader.endObject();
}
 
Example #20
Source File: JSONParser.java    From guarda-android-wallets with GNU General Public License v3.0 4 votes vote down vote up
private static ZCashTransactionOutput readTxSingleOutput(JsonReader reader) throws IOException {
  ZCashTransactionOutput output = new ZCashTransactionOutput();
  reader.beginObject(); //output
  while (reader.peek() != JsonToken.END_OBJECT) {
    String name = reader.nextName();
    switch (name) {
      case N:
        output.n = reader.nextLong();
        break;
      case SCRIPTPUBKEY:
        reader.beginObject();
        while (reader.peek() != JsonToken.END_OBJECT) {
          name = reader.nextName();
          switch (name) {
            case ADDRESSES:
              reader.beginArray();
              while (reader.hasNext()) {
                output.address = reader.nextString();
              }
              reader.endArray();
              break;
            case ASM:
              output.asm = reader.nextString();
              break;
            case HEX:
              output.hex = reader.nextString();
              break;
            case REQSIGS:
              output.regSigs = reader.nextLong();
              break;
            case TYPE:
              output.type = reader.nextString();
              break;
            default:
              reader.skipValue();
          }
        }
        reader.endObject();
        break;
      case VALUE:
        output.value = Double.valueOf(reader.nextDouble() * 1e8).longValue();
        break;
      case VALUEZAT:
        output.value = reader.nextLong();
        break;
      default:
        reader.skipValue();
    }
  }

  reader.endObject(); //output end
  return output;
}
 
Example #21
Source File: JSONParser.java    From guarda-android-wallets with GNU General Public License v3.0 4 votes vote down vote up
private static ZCashTransactionDetails_taddr readTx(JsonReader reader) throws IOException, IllegalStateException {
  ZCashTransactionDetails_taddr tx = new ZCashTransactionDetails_taddr();
  if(reader.peek() != JsonToken.BEGIN_OBJECT) {
    throw new IOException("Cannot parse JSON");
  }

  reader.beginObject();
  while (reader.peek() != JsonToken.END_OBJECT) {
    String name = reader.nextName();
    switch (name) {
      case HASH:
        tx.hash = reader.nextString();
        break;
      case MAINCHAIN:
        tx.mainChain = reader.nextBoolean();
        break;
      case FEE:
        tx.fee = Double.valueOf(reader.nextDouble() * 1e8).longValue();
        break;
      case TYPE:
        tx.type = reader.nextString();
        break;
      case SHIELDED:
        tx.shielded = reader.nextBoolean();
        break;
      case INDEX:
        tx.index = reader.nextLong();
        break;
      case BLOCKHASH:
        tx.blockHash = reader.nextString();
        break;
      case BLOCKHEIGHT:
        tx.blockHeight = reader.nextLong();
        break;
      case VERSION:
        tx.version = reader.nextLong();
        break;
      case LOCKTIME:
        tx.locktime = reader.nextLong();
        break;
      case TIME:
        tx.time = reader.nextLong();
        break;
      case TIMESTAMP:
        tx.timestamp = reader.nextLong();
        break;
      case VIN:
        tx.vin = readTxInputs(reader);
        break;
      case VOUT:
        tx.vout = readTxOutputs(reader, null);
        break;
      case VJOINSPLIT:
        skipJoinSplits(reader);
        break;
      case VALUE:
        tx.value = Double.valueOf(reader.nextDouble() * 1e8).longValue();
        break;
      case OUTPUTVALUE:
        tx.outputValue = Double.valueOf(reader.nextDouble() * 1e8).longValue();
        break;
      case SHIELDEDVALUE:
        tx.shieldedValue = Double.valueOf(reader.nextDouble() * 1e8).longValue();
        break;
      default:
        reader.skipValue();
    }
  }

  reader.endObject();
  return tx;
}
 
Example #22
Source File: BatchManagerTest.java    From background-geolocation-android with Apache License 2.0 4 votes vote down vote up
private List<BackgroundLocation> readLocationsArray(JsonReader reader) throws IOException {
    List<BackgroundLocation> locations = new ArrayList<BackgroundLocation>();
    reader.beginArray();
    while (reader.hasNext()) {
        BackgroundLocation l = new BackgroundLocation();
        reader.beginObject();
        while (reader.hasNext()) {
            String name = reader.nextName();
            if (name.equals("id")) {
                l.setLocationId(reader.nextLong());
            } else if (name.equals("time")) {
                l.setTime(reader.nextLong());
            } else if (name.equals("latitude")) {
                l.setLatitude(reader.nextDouble());
            } else if (name.equals("longitude")) {
                l.setLongitude(reader.nextDouble());
            } else if (name.equals("accuracy")) {
                l.setAccuracy((float)reader.nextDouble());
            } else if (name.equals("speed")) {
                l.setSpeed((float)reader.nextDouble());
            } else if (name.equals("bearing")) {
                l.setBearing((float)reader.nextDouble());
            } else if (name.equals("altitude")) {
                l.setAltitude(reader.nextDouble());
            } else if (name.equals("radius")) {
                JsonToken token = reader.peek();
                if (token != JsonToken.NULL) {
                    l.setRadius((float)reader.nextDouble());
                } else {
                    reader.skipValue();
                }
            } else if (name.equals("provider")) {
                l.setProvider(reader.nextString());
            } else if (name.equals("locationProvider")) {
                l.setLocationProvider(reader.nextInt());
            } else {
                reader.skipValue();
            }
        }
        reader.endObject();
        locations.add(l);
    }
    reader.endArray();
    return locations;
}
 
Example #23
Source File: JSONParser.java    From guarda-android-wallets with GNU General Public License v3.0 4 votes vote down vote up
private static ZCashTransactionOutput readTxSingleOutput(JsonReader reader) throws IOException {
  ZCashTransactionOutput output = new ZCashTransactionOutput();
  reader.beginObject(); //output
  while (reader.peek() != JsonToken.END_OBJECT) {
    String name = reader.nextName();
    switch (name) {
      case N:
        output.n = reader.nextLong();
        break;
      case SCRIPTPUBKEY:
        reader.beginObject();
        while (reader.peek() != JsonToken.END_OBJECT) {
          name = reader.nextName();
          switch (name) {
            case ADDRESSES:
              reader.beginArray();
              while (reader.hasNext()) {
                output.address = reader.nextString();
              }
              reader.endArray();
              break;
            case ASM:
              output.asm = reader.nextString();
              break;
            case HEX:
              output.hex = reader.nextString();
              break;
            case REQSIGS:
              output.regSigs = reader.nextLong();
              break;
            case TYPE:
              output.type = reader.nextString();
              break;
            default:
              reader.skipValue();
          }
        }
        reader.endObject();
        break;
      case VALUE:
        output.value = Double.valueOf(reader.nextDouble() * 1e8).longValue();
        break;
      case VALUEZAT:
        output.value = reader.nextLong();
        break;
      default:
        reader.skipValue();
    }
  }

  reader.endObject(); //output end
  return output;
}
 
Example #24
Source File: JSONParser.java    From guarda-android-wallets with GNU General Public License v3.0 4 votes vote down vote up
private static ZCashTransactionDetails_taddr readTx(JsonReader reader) throws IOException, IllegalStateException {
  ZCashTransactionDetails_taddr tx = new ZCashTransactionDetails_taddr();
  if(reader.peek() != JsonToken.BEGIN_OBJECT) {
    throw new IOException("Cannot parse JSON");
  }

  reader.beginObject();
  while (reader.peek() != JsonToken.END_OBJECT) {
    String name = reader.nextName();
    switch (name) {
      case HASH:
        tx.hash = reader.nextString();
        break;
      case MAINCHAIN:
        tx.mainChain = reader.nextBoolean();
        break;
      case FEE:
        tx.fee = Double.valueOf(reader.nextDouble() * 1e8).longValue();
        break;
      case TYPE:
        tx.type = reader.nextString();
        break;
      case SHIELDED:
        tx.shielded = reader.nextBoolean();
        break;
      case INDEX:
        tx.index = reader.nextLong();
        break;
      case BLOCKHASH:
        tx.blockHash = reader.nextString();
        break;
      case BLOCKHEIGHT:
        tx.blockHeight = reader.nextLong();
        break;
      case VERSION:
        tx.version = reader.nextLong();
        break;
      case LOCKTIME:
        tx.locktime = reader.nextLong();
        break;
      case TIME:
        tx.time = reader.nextLong();
        break;
      case TIMESTAMP:
        tx.timestamp = reader.nextLong();
        break;
      case VIN:
        tx.vin = readTxInputs(reader);
        break;
      case VOUT:
        tx.vout = readTxOutputs(reader, null);
        break;
      case VJOINSPLIT:
        skipJoinSplits(reader);
        break;
      case VALUE:
        tx.value = Double.valueOf(reader.nextDouble() * 1e8).longValue();
        break;
      case OUTPUTVALUE:
        tx.outputValue = Double.valueOf(reader.nextDouble() * 1e8).longValue();
        break;
      case SHIELDEDVALUE:
        tx.shieldedValue = Double.valueOf(reader.nextDouble() * 1e8).longValue();
        break;
      default:
        reader.skipValue();
    }
  }

  reader.endObject();
  return tx;
}
 
Example #25
Source File: XulDataNode.java    From starcor.xul with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static XulDataNode buildFromJson(Reader reader) {
	JsonReader jsonReader = new JsonReader(reader);
	ArrayList<XulDataNode> parseStack = new ArrayList<XulDataNode>();
	XulDataNode lastDataNode = null;
	try {
		JsonToken peek;
		while ((peek = jsonReader.peek()) != JsonToken.END_DOCUMENT) {
			switch (peek) {
			case NAME:
				String nameStr = jsonReader.nextName();
				if (!jsonReader.hasNext()) {
					continue;
				}
				switch ((peek = jsonReader.peek())) {
				case BEGIN_OBJECT:
				case BEGIN_ARRAY:
					if (peek == JsonToken.BEGIN_OBJECT) {
						jsonReader.beginObject();
					} else {
						jsonReader.beginArray();
					}
					lastDataNode = lastDataNode.appendChild(nameStr);
					parseStack.add(lastDataNode);
					break;
				case STRING:
				case NUMBER:
					lastDataNode.setAttribute(nameStr, jsonReader.nextString());
					break;
				case BOOLEAN:
					lastDataNode.setAttribute(nameStr, String.valueOf(jsonReader.nextBoolean()));
					break;
				case NULL:
					jsonReader.nextNull();
					lastDataNode.setAttribute(nameStr, null);
					break;
				}
				break;
			case BEGIN_OBJECT:
			case BEGIN_ARRAY:
				if (peek == JsonToken.BEGIN_OBJECT) {
					jsonReader.beginObject();
				} else {
					jsonReader.beginArray();
				}
				if (lastDataNode != null) {
					lastDataNode = lastDataNode.appendChild(String.valueOf(lastDataNode.size()));
				} else {
					lastDataNode = XulDataNode.obtainDataNode(null);
				}
				parseStack.add(lastDataNode);
				break;
			case END_OBJECT:
			case END_ARRAY:
				if (peek == JsonToken.END_OBJECT) {
					jsonReader.endObject();
				} else {
					jsonReader.endArray();
				}
				parseStack.remove(parseStack.size() - 1);
				if (!parseStack.isEmpty()) {
					lastDataNode = parseStack.get(parseStack.size() - 1);
				}
				break;
			default:
				// array
				switch (peek) {
				case STRING:
				case NUMBER:
					lastDataNode.appendChild(String.valueOf(lastDataNode.size()), jsonReader.nextString());
					break;
				case BOOLEAN:
					lastDataNode.appendChild(String.valueOf(lastDataNode.size()), String.valueOf(jsonReader.nextBoolean()));
					break;
				case NULL:
					jsonReader.nextNull();
					lastDataNode.appendChild(String.valueOf(lastDataNode.size()));
					break;
				default:
					jsonReader.skipValue();
					break;
				}
				break;
			}
		}
	} catch (Exception e) {
		e.printStackTrace();
	}
	return lastDataNode;
}
 
Example #26
Source File: NGWUtil.java    From android_maplib with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static void readNGWFeatureFields(Feature feature, JsonReader reader, List<Field> fields)
        throws IOException, IllegalStateException, NumberFormatException
{
    reader.beginObject();
    while (reader.hasNext()) {
        String name = reader.nextName();
        if (reader.peek() == JsonToken.NULL) {
            reader.skipValue();
        } else {
            boolean bAdded = false;
            for (Field field : fields) {
                if (field.getName().equals(name) || field.getName().equals(LayerUtil.normalizeFieldName(name))) {
                    switch (field.getType()) {
                        case GeoConstants.FTReal:
                            feature.setFieldValue(field.getName(), reader.nextDouble());
                            bAdded = true;
                            break;
                        case GeoConstants.FTInteger:
                            feature.setFieldValue(field.getName(), reader.nextInt());
                            bAdded = true;
                            break;
                        case GeoConstants.FTString:
                            feature.setFieldValue(field.getName(), reader.nextString());
                            bAdded = true;
                            break;
                        case GeoConstants.FTDate:
                        case GeoConstants.FTTime:
                        case GeoConstants.FTDateTime:
                            readNGWDate(feature, reader, field.getName());
                            bAdded = true;
                            break;
                        default:
                            break;
                    }
                    break;
                }
            }
            if (!bAdded) {
                reader.skipValue();
            }
        }
    }
    reader.endObject();
}
 
Example #27
Source File: JsonStatusContentHandler.java    From android-vlc-remote with GNU General Public License v3.0 4 votes vote down vote up
private boolean parseBoolean(JsonToken token) throws IOException {
    if(JsonToken.NUMBER.equals(token)) {
        return reader.nextInt() == 0;
    }
    return reader.nextBoolean();
}