/**
   * Reads a JSON object for a specific density and populates variables if the density matches
   * {@code bitmapDensity}.
   *
   * @param reader The JsonReader reading the JSON metadata.
   * @param bitmapDensity The density of the unscaled {@link Bitmap} that was loaded.
   * @return True if the JSON object being parsed corresponds to bitmapDensity.
   * @throws IOException
   */
  private boolean parseMetadataForDensity(JsonReader reader, int bitmapDensity) throws IOException {
    String name = reader.nextName();
    assert name.equals("density");
    int density = reader.nextInt();

    // If this is metadata for a density other than bitmapDensity, skip parsing the rest of the
    // object.
    if (density != bitmapDensity) {
      reader.skipValue(); // Skip width name.
      reader.skipValue(); // Skip width value.
      reader.skipValue(); // Skip height name.
      reader.skipValue(); // Skip height value.
      reader.skipValue(); // Skip rectangles name.
      reader.skipValue(); // Skip rectangles array.
      return false;
    }

    name = reader.nextName();
    assert name.equals("width");
    mSpriteWidth = reader.nextInt();

    name = reader.nextName();
    assert name.equals("height");
    mSpriteHeight = reader.nextInt();

    name = reader.nextName();
    assert name.equals("rectangles");

    parseFrameRectangles(reader);

    return true;
  }
 @Override
 protected void read(@NonNull JsonReader reader, String name) throws IOException {
   switch (name) {
     case "PortUDPSend":
       PortUDPSend = reader.nextInt();
       break;
     case "PortUDPReceive":
       PortUDPReceive = reader.nextInt();
       break;
     default:
       reader.skipValue();
       break;
   }
 }
Example #3
0
  @Override
  public void deSerializeRepresentation(JsonReader sreader) throws IOException {
    sreader.beginObject();
    Vector<StrokeData> strokes = new Vector<StrokeData>();

    while (sreader.hasNext()) {
      sreader.nextName();
      sreader.beginObject();
      StrokeData stroke = new StrokeData();

      while (sreader.hasNext()) {
        String name = sreader.nextName();
        if (name.equals(SERIAL_COLOR)) {
          stroke.mColor = sreader.nextInt();
        } else if (name.equals(SERIAL_RADIUS)) {
          stroke.mRadius = (float) sreader.nextDouble();
        } else if (name.equals(SERIAL_TYPE)) {
          stroke.mType = (byte) sreader.nextInt();
        } else if (name.equals(SERIAL_POINTS_COUNT)) {
          stroke.noPoints = sreader.nextInt();
        } else if (name.equals(SERIAL_POINTS)) {

          int count = 0;
          sreader.beginArray();
          while (sreader.hasNext()) {
            if ((count + 1) > stroke.mPoints.length) {
              stroke.mPoints = Arrays.copyOf(stroke.mPoints, count * 2);
            }
            stroke.mPoints[count++] = (float) sreader.nextDouble();
          }
          stroke.mPath = new Path();
          stroke.mPath.moveTo(stroke.mPoints[0], stroke.mPoints[1]);
          for (int i = 0; i < count; i += 2) {
            stroke.mPath.lineTo(stroke.mPoints[i], stroke.mPoints[i + 1]);
          }
          sreader.endArray();
          strokes.add(stroke);
        } else {
          sreader.skipValue();
        }
      }
      sreader.endObject();
    }

    mDrawing = strokes;

    sreader.endObject();
  }
  @Override
  public void onMessage(int instanceId, String message) {
    StringReader contents = new StringReader(message);
    JsonReader reader = new JsonReader(contents);

    int requestId = -1;
    String cmd = null;
    String url = null;
    try {
      reader.beginObject();
      while (reader.hasNext()) {
        String name = reader.nextName();
        if (name.equals(TAG_CMD)) {
          cmd = reader.nextString();
        } else if (name.equals(TAG_REQUEST_ID)) {
          requestId = reader.nextInt();
        } else if (name.equals("url")) {
          url = reader.nextString();
        } else {
          reader.skipValue();
        }
      }
      reader.endObject();
      reader.close();

      if (cmd != null && cmd.equals(CMD_REQUEST_SHOW) && requestId >= 0) {
        handleRequestShow(instanceId, url, requestId);
      }
    } catch (IOException e) {
      Log.d(TAG, "Error: " + e);
    }
  }
Example #5
0
 @SuppressWarnings("cast")
 public static some.test.Simple createUsingJsonStream(Realm realm, JsonReader reader)
     throws IOException {
   some.test.Simple obj = realm.createObject(some.test.Simple.class);
   reader.beginObject();
   while (reader.hasNext()) {
     String name = reader.nextName();
     if (name.equals("name")) {
       if (reader.peek() == JsonToken.NULL) {
         reader.skipValue();
         ((SimpleRealmProxyInterface) obj).realmSet$name(null);
       } else {
         ((SimpleRealmProxyInterface) obj).realmSet$name((String) reader.nextString());
       }
     } else if (name.equals("age")) {
       if (reader.peek() == JsonToken.NULL) {
         reader.skipValue();
         throw new IllegalArgumentException("Trying to set non-nullable field 'age' to null.");
       } else {
         ((SimpleRealmProxyInterface) obj).realmSet$age((int) reader.nextInt());
       }
     } else {
       reader.skipValue();
     }
   }
   reader.endObject();
   return obj;
 }
  /**
   * Parses the 2D JSONArray of frame rectangles and populates {@code mRectangles}.
   *
   * @param reader The JsonReader reading the JSON metadata.
   * @throws IOException
   */
  private void parseFrameRectangles(JsonReader reader) throws IOException {
    ArrayList<ArrayList<Integer>> allFrameRectangles = new ArrayList<ArrayList<Integer>>();
    int frameCount = 0;

    reader.beginArray(); // Start reading 2D rectangles array.
    while (reader.hasNext()) {
      ArrayList<Integer> frameRectangles = new ArrayList<Integer>();
      reader.beginArray(); // Start reading frame array.
      while (reader.hasNext()) {
        frameRectangles.add(reader.nextInt());
      }
      reader.endArray(); // Stop reading frame array.
      allFrameRectangles.add(frameRectangles);
      frameCount++;
    }
    reader.endArray(); // Stop reading 2D rectangles array.

    // Convert 2D ArrayList to int[][].
    mRectangles = new int[frameCount][];
    for (int i = 0; i < frameCount; i++) {
      ArrayList<Integer> frameRectangles = allFrameRectangles.get(i);
      int[] frameRectanglesArray = new int[frameRectangles.size()];
      for (int j = 0; j < frameRectangles.size(); j++) {
        frameRectanglesArray[j] = frameRectangles.get(j);
      }
      mRectangles[i] = frameRectanglesArray;
    }
  }
Example #7
0
 private void jsonToUsuario(JsonReader reader) throws JSONException, IOException {
   reader.beginObject();
   while (reader.hasNext()) {
     String name = reader.nextName();
     switch (name) {
       case "id":
         this.id = reader.nextInt();
         break;
       case "token":
         this.token = reader.nextString();
         break;
       case "latitud":
         this.latitud = reader.nextDouble();
         break;
       case "longitud":
         this.longitud = reader.nextDouble();
         break;
       case "activo":
         this.activo = reader.nextBoolean();
         break;
       case "ofreceTransito":
         this.ofreceTransito = reader.nextBoolean();
         break;
       case "autopublicar":
         this.autopublicar = reader.nextBoolean();
         break;
       case "email":
         this.email = reader.nextString();
         break;
       case "username":
         this.username = reader.nextString();
         break;
       case "password":
         this.password = reader.nextString();
         break;
       case "telefono":
         this.telefono = reader.nextString();
         break;
       case "direccion":
         this.direccion = reader.nextString();
         break;
       case "foto":
         if (reader.peek() == JsonToken.NULL) reader.nextNull();
         else {
           this.foto = null;
           reader.nextString();
           // TODO: Completar cuando el post del usuario admita json
           // this.foto.setImg(Imagen.bytesFromBase64DEFAULT(reader.nextString()));
         }
         break;
       default:
         reader.skipValue();
         break;
     }
   }
   reader.endObject();
 }
Example #8
0
  public static void read() {
    String filename = String.format(getRootDir() + "/conf.json");
    try {
      FileInputStream fin = new FileInputStream(filename);
      JsonReader reader = new JsonReader(new InputStreamReader(fin, "UTF-8"));

      reader.beginObject();

      // write common information
      while (reader.hasNext()) {
        String name = reader.nextName();
        if (name.equals("LENGTH_UNIT")) {
          LENGTH_UNIT = reader.nextString();
        } else if (name.equals("MAP_TYPE")) {
          MAP_TYPE = reader.nextString();
        } else if (name.equals("SPEED_TYPE")) {
          SPEED_TYPE = reader.nextString();
        } else if (name.equals("MIN_DISTANCE")) {
          MIN_DISTANCE = reader.nextInt();
        } else if (name.equals("INTERVAL_LOCATION")) {
          INTERVAL_LOCATION = reader.nextInt();
        } else if (name.equals("INTERVAL_LOCATION_FAST")) {
          INTERVAL_LOCATION_FAST = reader.nextInt();
        } else if (name.equals("LOCATION_ACCURACY")) {
          LOCATION_ACCURACY = reader.nextInt();
        } else if (name.equals("SPEED_AVG")) {
          SPEED_AVG = reader.nextInt();
        } else if (name.equals("GPS_ONLY")) {
          GPS_ONLY = reader.nextBoolean();
        } else if (name.equals("GPS_ONLY")) {
          ACCELERATE_FACTOR = (float) reader.nextDouble();
        } else {
          reader.skipValue();
        }
      }
      reader.endObject();

      reader.close();
      fin.close();
    } catch (Exception e) {
      Log.i(TAG, "read conf from file fail.");
    }
  }
 public static SatsClass createUsingJsonStream(Realm realm, JsonReader reader) throws IOException {
   SatsClass obj = realm.createObject(SatsClass.class);
   reader.beginObject();
   while (reader.hasNext()) {
     String name = reader.nextName();
     if (name.equals("id") && reader.peek() != JsonToken.NULL) {
       obj.setId((String) reader.nextString());
     } else if (name.equals("centerFilterId") && reader.peek() != JsonToken.NULL) {
       obj.setCenterFilterId((String) reader.nextString());
     } else if (name.equals("classTypeId") && reader.peek() != JsonToken.NULL) {
       obj.setClassTypeId((String) reader.nextString());
     } else if (name.equals("durationInMinutes") && reader.peek() != JsonToken.NULL) {
       obj.setDurationInMinutes((int) reader.nextInt());
     } else if (name.equals("instructorId") && reader.peek() != JsonToken.NULL) {
       obj.setInstructorId((String) reader.nextString());
     } else if (name.equals("name") && reader.peek() != JsonToken.NULL) {
       obj.setName((String) reader.nextString());
     } else if (name.equals("startTime") && reader.peek() != JsonToken.NULL) {
       obj.setStartTime((String) reader.nextString());
     } else if (name.equals("bookedPersonsCount") && reader.peek() != JsonToken.NULL) {
       obj.setBookedPersonsCount((int) reader.nextInt());
     } else if (name.equals("maxPersonsCount") && reader.peek() != JsonToken.NULL) {
       obj.setMaxPersonsCount((int) reader.nextInt());
     } else if (name.equals("regionId") && reader.peek() != JsonToken.NULL) {
       obj.setRegionId((String) reader.nextString());
     } else if (name.equals("waitingListCount") && reader.peek() != JsonToken.NULL) {
       obj.setWaitingListCount((int) reader.nextInt());
     } else if (name.equals("classCategoryIds") && reader.peek() != JsonToken.NULL) {
       reader.beginArray();
       while (reader.hasNext()) {
         se.greatbrain.sats.data.model.ClassCategoryIds item =
             ClassCategoryIdsRealmProxy.createUsingJsonStream(realm, reader);
         obj.getClassCategoryIds().add(item);
       }
       reader.endArray();
     } else {
       reader.skipValue();
     }
   }
   reader.endObject();
   return obj;
 }
  /** Parse single metric body */
  void parseBody() throws IOException {

    // reset values
    String metricId = null;
    int lastRowId = 0;
    String instanceId = null;
    String serverName = null;
    String name = null;
    JSONObject parameters = null;

    _reader.beginObject();
    while (_reader.hasNext()) {
      String property = _reader.nextName();
      switch (property) {
        case "uid":
          metricId = nextStringOrNull();
          break;
        case "last_rowid":
          lastRowId = _reader.nextInt();
          break;
        case "name":
          name = nextStringOrNull();
          break;
        case "server":
          instanceId = nextStringOrNull();
          break;
        case "tag_name":
          serverName = nextStringOrNull();
          break;
        case "parameters":
          parameters = nextObjectOrNull();
          break;
        default:
          _reader.skipValue();
          break;
      }
    }
    _reader.endObject();

    serverName = serverName == null ? instanceId : serverName;
    Metric metric =
        HTMITApplication.getDatabase()
            .getDataFactory()
            .createMetric(metricId, name, instanceId, serverName, lastRowId, parameters);

    String unit = metric.getUnit();
    if (unit == null) {
      // Guess metric unit based on name if not given by server
      unit = HTMITApplication.getMetricUnit(name);
      metric.setUnit(unit);
    }

    _results.add(metric);
  }
 private SearchResults readResults(JsonReader reader) throws IOException {
   SearchResults results = new SearchResults();
   reader.beginObject();
   while (reader.hasNext()) {
     String name = reader.nextName();
     if (name.equals("total_hits")) {
       results.count = reader.nextInt();
       if (results.count == 0) {
         return results;
       }
     } else if (name.equals("max_score")) {
       double max_score = reader.nextDouble();
       // we currently do nothing with this value
     } else if (name.equals("hits")) {
       results.list = readHitsArray(reader);
     } else {
       reader.skipValue();
     }
   }
   reader.endObject();
   return results;
 }
  @Override
  public void deSerializeRepresentation(JsonReader sreader) throws IOException {
    sreader.beginObject();
    Vector<Band> points = new Vector<Band>();

    while (sreader.hasNext()) {
      String name = sreader.nextName();
      if (name.startsWith(LINE_NAME)) {
        int pointNo = Integer.parseInt(name.substring(LINE_NAME.length()));
        sreader.beginArray();
        Band p = new Band();
        p.mask = false;
        sreader.hasNext();
        p.xPos1 = sreader.nextInt();
        sreader.hasNext();
        p.yPos1 = sreader.nextInt();
        sreader.hasNext();
        p.xPos2 = sreader.nextInt();
        sreader.hasNext();
        p.yPos2 = sreader.nextInt();
        sreader.hasNext();
        p.brightness = sreader.nextInt();
        sreader.hasNext();
        p.contrast = sreader.nextInt();
        sreader.hasNext();
        p.saturation = sreader.nextInt();
        sreader.hasNext();
        sreader.endArray();
        points.add(p);

      } else {
        sreader.skipValue();
      }
    }
    mBands = points;
    trimVector();
    mCurrentBand = mBands.get(0);
    sreader.endObject();
  }
  public static final List<Variant> GetVariants(String source) throws IOException {
    ArrayList<Variant> variants = new ArrayList<Variant>();
    JsonReader reader = null;

    try {
      reader = new JsonReader(new StringReader(source));
      reader.beginArray();
      while (reader.hasNext()) {
        reader.beginObject();

        Variant variant = new Variant();

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

          if (name.equals("Samples")) {
            reader.beginArray();
            while (reader.hasNext()) {
              Sample sample = new Sample();
              reader.beginObject();
              String sName = reader.nextName();

              if (sName.equals("SampleType")) {
                sample.SampleType = reader.nextString();
              } else if (sName.equals("ContainerType")) {
                sample.ContainerType = reader.nextString();
              } else if (sName.equals("Preparation")) {
                sample.Preparation = reader.nextString();
              } else if (sName.equals("Protocol")) {
                sample.Protocol = reader.nextString();
              } else if (sName.equals("MaxVolume")) {
                sample.MaxVolume = reader.nextInt();
              } else if (sName.equals("CurrentVolume")) {
                sample.CurrentVolume = reader.nextInt();
              } else if (sName.equals("SampleGroup")) {
                sample.SampleGroup = reader.nextString();
              } else if (sName.equals("DeadVolume")) {
                sample.DeadVolume = reader.nextInt();
              } else if (sName.equals("Manipulations")) {
                reader.beginArray();
                while (reader.hasNext()) {
                  Manipulation manipulation = new Manipulation();
                  reader.beginObject();

                  String mName = reader.nextName();

                  if (mName.equals("Code")) {
                    manipulation.Code = reader.nextString();
                  } else if (mName.equals("Name")) {
                    manipulation.Name = reader.nextName();
                  } else if (mName.equals("Preparation")) {
                    manipulation.Preparation = reader.nextString();
                  } else {
                    reader.skipValue();
                  }

                  reader.endObject();

                  sample.Manipulations.add(manipulation);
                }
                reader.endArray();
              } else {
                reader.skipValue();
              }

              reader.endObject();

              variant.Samples.add(sample);
            }
            reader.endArray();
          } else if (name.equals("RequiredFields")) {
            reader.beginArray();
            while (reader.hasNext()) {
              RequiredField reqField = new RequiredField();
              reader.beginObject();

              while (reader.hasNext()) {
                String rfName = reader.nextName();

                if (rfName.equals("Code")) {
                  reqField.Code = reader.nextString();
                } else if (rfName.equals("Name")) {
                  reqField.Name = reader.nextString();
                } else {
                  reader.skipValue();
                }
              }

              reader.endObject();
              variant.RequiredFields.add(reqField);
            }

            reader.endArray();
          } else {
            reader.skipValue();
          }
        }
        reader.endObject();

        variants.add(variant);
      }
      reader.endArray();

    } finally {
      if (reader != null) reader.close();
    }

    return variants;
  }
  private SaroEntry processSaroEntry(JsonReader reader) throws IOException {
    SaroEntry entry = new SaroEntry();
    reader.beginObject();
    while (reader.hasNext()) {
      String name = reader.nextName();

      if (name.equals("year")) {
        entry.setYear(reader.nextInt());
      } else if (name.equals("department_code")) {
        entry.setDepartmentCode(reader.nextString());
      } else if (name.equals("agency_code")) {
        entry.setAgencyCode(reader.nextString());
      } else if (name.equals("operating_unit")) {
        entry.setOperatingUnit(reader.nextString());
      } else if (name.equals("spf_code")) {
        entry.setSpfCode(reader.nextString());
      } else if (name.equals("sub_spf_code")) {
        entry.setSubSpfCode(reader.nextString());
      } else if (name.equals("description")) {
        entry.setDescription(reader.nextString());
      } else if (name.equals("fund_code")) {
        entry.setFundCode(reader.nextString());
      } else if (name.equals("region")) {
        entry.setRegion(reader.nextString());
      } else if (name.equals("appro_src")) {
        entry.setAppropriationSource(reader.nextString());
      } else if (name.equals("purpose")) {
        entry.setPurpose(reader.nextString());
      } else if (name.equals("program_code")) {
        entry.setProgramCode(reader.nextString());
      } else if (name.equals("program_description")) {
        entry.setProgramDescription(reader.nextString());
      } else if (name.equals("object_code")) {
        entry.setObjectCode(reader.nextString());
      } else if (name.equals("object_description")) {
        entry.setObjectDescription(reader.nextString());
      } else if (name.equals("amount")) {
        entry.setAmount(reader.nextLong());
      } else if (name.equals("issue_date")) {
        Calendar cal = Calendar.getInstance();
        SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
        try {
          cal.setTime(sdf.parse(reader.nextString()));
          entry.setIssueDate(cal);
        } catch (ParseException e) {
          e.printStackTrace();
          Log.e(
              "SAROHTTPHANDLER",
              "cannot parse time... format may have changed (MM/dd/yyyy HH:mm:ss format is accepted)");
          entry.setIssueDate(null);
        }
      } else if (name.equals("barcode_no")) {
        entry.setBarcodeNumber(reader.nextString());
      } else if (name.equals("saro_no")) {
        entry.setSaroNumber(reader.nextString());
      } else if (name.equals("id")) {
        entry.setId(reader.nextString());
      } else {
        Log.e(
            "SAROHTTPHANDLER",
            "schema for this request may have changed... "
                + "it's the government's fault, if anyone asks.");
      }
    }
    reader.endObject();
    return entry;
  }
Example #15
0
  private Post readPostObject(JsonReader reader) throws Exception {
    Post post = new Post();
    post.board = loadable.board;

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

      switch (key) {
        case "no":
          // Post number
          post.no = reader.nextInt();
          /*} else if (key.equals("time")) {
          // Time
          long time = reader.nextLong();
          post.date = new Date(time * 1000);*/
          break;
        case "now":
          post.date = reader.nextString();
          break;
        case "name":
          post.name = reader.nextString();
          break;
        case "com":
          post.rawComment = reader.nextString();
          break;
        case "tim":
          post.tim = reader.nextLong();
          break;
        case "time":
          post.time = reader.nextLong();
          break;
        case "ext":
          post.ext = reader.nextString().replace(".", "");
          break;
        case "resto":
          post.resto = reader.nextInt();
          break;
        case "w":
          post.imageWidth = reader.nextInt();
          break;
        case "h":
          post.imageHeight = reader.nextInt();
          break;
        case "fsize":
          post.fileSize = reader.nextInt();
          break;
        case "sub":
          post.subject = reader.nextString();
          break;
        case "replies":
          post.replies = reader.nextInt();
          break;
        case "filename":
          post.filename = reader.nextString();
          break;
        case "sticky":
          post.sticky = reader.nextInt() == 1;
          break;
        case "closed":
          post.closed = reader.nextInt() == 1;
          break;
        case "archived":
          post.archived = reader.nextInt() == 1;
          break;
        case "trip":
          post.tripcode = reader.nextString();
          break;
        case "country":
          post.country = reader.nextString();
          break;
        case "country_name":
          post.countryName = reader.nextString();
          break;
        case "id":
          post.id = reader.nextString();
          break;
        case "capcode":
          post.capcode = reader.nextString();
          break;
        case "images":
          post.images = reader.nextInt();
          break;
        case "spoiler":
          post.spoiler = reader.nextInt() == 1;
          break;
        default:
          // Unknown/ignored key
          //                log("Unknown/ignored key: " + key + ".");
          reader.skipValue();
          break;
      }
    }
    reader.endObject();

    Post cachedResult = null;
    for (Post possibleCached : cached) {
      if (possibleCached.no == post.no) {
        cachedResult = possibleCached;
        break;
      }
    }

    if (cachedResult != null) {
      return cachedResult;
    } else {
      if (!post.finish()) {
        throw new IOException("Incorrect data about post received.");
      }

      return post;
    }
  }