Java Code Examples for android.util.JsonReader#endArray()

The following examples show how to use android.util.JsonReader#endArray() . 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: 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 2
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 3
Source File: AndroidPlacesApiJsonParser.java    From android-PlacesAutocompleteTextView with BSD 2-Clause "Simplified" License 6 votes vote down vote up
List<PlaceType> readPlaceTypesArray(JsonReader reader) throws IOException {
    List<PlaceType> types = new ArrayList<>();

    reader.beginArray();
    while (reader.hasNext()) {
        switch (reader.nextString()) {
            case "route":
                types.add(PlaceType.ROUTE);
                break;
            case "geocode":
                types.add(PlaceType.GEOCODE);
                break;
            default:
                reader.skipValue();
                break;
        }
    }
    reader.endArray();
    return types;
}
 
Example 4
Source File: GeoPolygon.java    From android_maplib with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void setCoordinatesFromJSONStream(JsonReader reader, int crs) throws IOException {
    setCRS(crs);
    boolean outerRingFilled = false;
    reader.beginArray();
    while (reader.hasNext()){
        if (!outerRingFilled) {
            mOuterRing.setCoordinatesFromJSONStream(reader, crs);
            outerRingFilled = true;
        } else {
            GeoLinearRing ring = new GeoLinearRing();
            ring.setCoordinatesFromJSONStream(reader, crs);
            mInnerRings.add(ring);
        }
    }
    reader.endArray();
}
 
Example 5
Source File: SampleChooserActivity.java    From ExoPlayer-Offline with Apache License 2.0 5 votes vote down vote up
private void readSampleGroups(JsonReader reader, List<SampleGroup> groups) throws IOException {
  reader.beginArray();
  while (reader.hasNext()) {
    readSampleGroup(reader, groups);
  }
  reader.endArray();
}
 
Example 6
Source File: BatchManagerTest.java    From background-geolocation-android with Apache License 2.0 5 votes vote down vote up
@Test
public void testBatchWithNulls() throws JSONException, IOException {

    BackgroundLocation location = new BackgroundLocation();
    location.setBatchStartMillis(1000L);
    location.setStatus(BackgroundLocation.SYNC_PENDING);
    SQLiteLocationDAO dao = new SQLiteLocationDAO(mDbHelper.getWritableDatabase());
    dao.persistLocation(location);

    JSONObject templateJSON = new JSONObject("{\"Nullable\":null, \"NullRadius\": \"@radius\"}");
    LocationTemplate template = LocationTemplateFactory.fromJSON(templateJSON);

    BatchManager batchManager = new BatchManager(mContext);
    File batchFile = batchManager.createBatch(3000L, 0, template);

    HashMap hashLocation = new HashMap<String, Object>();
    JsonReader reader = new JsonReader(new FileReader(batchFile));
    reader.beginArray();
    while (reader.hasNext()) {
        reader.beginObject();
        while(reader.hasNext()) { ;
            hashLocation.put(reader.nextName(), null);
            reader.nextNull();
        }
        reader.endObject();
    }
    reader.endArray();

    Assert.assertTrue(hashLocation.containsKey("Nullable"));
    Assert.assertTrue(hashLocation.containsKey("NullRadius"));
}
 
Example 7
Source File: AndroidPlacesApiJsonParser.java    From android-PlacesAutocompleteTextView with BSD 2-Clause "Simplified" License 5 votes vote down vote up
List<RatingAspect> readAspectsArray(JsonReader reader) throws IOException {
    List<RatingAspect> aspects = new ArrayList<>();

    reader.beginArray();
    while (reader.hasNext()) {
        int rating = -1;
        String type = null;

        reader.beginObject();
        while (reader.hasNext()) {
            switch (reader.nextName()) {
                case "rating":
                    rating = reader.nextInt();
                    break;
                case "type":
                    type = reader.nextString();
                    break;
                default:
                    reader.skipValue();
                    break;
            }
        }
        reader.endObject();
        aspects.add(new RatingAspect(rating, type));
    }
    reader.endArray();
    return aspects;
}
 
Example 8
Source File: AndroidPlacesApiJsonParser.java    From android-PlacesAutocompleteTextView with BSD 2-Clause "Simplified" License 5 votes vote down vote up
List<OpenPeriod> readOpenPeriodsArray(JsonReader reader) throws IOException {
    List<OpenPeriod> periods = new ArrayList<>();

    reader.beginArray();
    while (reader.hasNext()) {
        DateTimePair open = null;
        DateTimePair close = null;

        reader.beginObject();
        while (reader.hasNext()) {
            switch (reader.nextName()) {
                case "open":
                    open = readDateTimePair(reader);
                    break;
                case "close":
                    close = readDateTimePair(reader);
                    break;
                default:
                    reader.skipValue();
                    break;
            }
        }
        reader.endObject();
        periods.add(new OpenPeriod(open, close));
    }
    reader.endArray();
    return periods;
}
 
Example 9
Source File: JSONParser.java    From guarda-android-wallets with GNU General Public License v3.0 5 votes vote down vote up
private static Vector<ZCashTransactionOutput> readTxInputs(JsonReader reader) throws IOException {
  Vector<ZCashTransactionOutput> vin = new Vector<>();
  reader.beginArray();
  while (reader.hasNext()) {
    vin.add(readTxSingleInput(reader));
  }

  reader.endArray();
  return vin;
}
 
Example 10
Source File: GeoLineString.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void setCoordinatesFromJSONStream(JsonReader reader, int crs) throws IOException {
    setCRS(crs);
    reader.beginArray();
    while (reader.hasNext()){
        GeoPoint pt = new GeoPoint();
        pt.setCoordinatesFromJSONStream(reader, crs);
        mPoints.add(pt);
    }
    reader.endArray();
}
 
Example 11
Source File: AndroidPlacesApiJsonParser.java    From android-PlacesAutocompleteTextView with BSD 2-Clause "Simplified" License 5 votes vote down vote up
List<DescriptionTerm> readDescriptionTermsArray(JsonReader reader) throws IOException {
    List<DescriptionTerm> terms = new ArrayList<>();

    reader.beginArray();
    while (reader.hasNext()) {
        int offset = -1;
        String value = null;

        reader.beginObject();
        while (reader.hasNext()) {
            switch (reader.nextName()) {
                case "offset":
                    offset = reader.nextInt();
                    break;
                case "value":
                    value = reader.nextString();
                    break;
                default:
                    reader.skipValue();
                    break;
            }
        }
        reader.endObject();
        terms.add(new DescriptionTerm(offset, value));
    }
    reader.endArray();
    return terms;
}
 
Example 12
Source File: JsonUtils.java    From Indic-Keyboard with Apache License 2.0 5 votes vote down vote up
public static List<Object> jsonStrToList(final String s) {
    final ArrayList<Object> list = new ArrayList<>();
    final JsonReader reader = new JsonReader(new StringReader(s));
    try {
        reader.beginArray();
        while (reader.hasNext()) {
            reader.beginObject();
            while (reader.hasNext()) {
                final String name = reader.nextName();
                if (name.equals(INTEGER_CLASS_NAME)) {
                    list.add(reader.nextInt());
                } else if (name.equals(STRING_CLASS_NAME)) {
                    list.add(reader.nextString());
                } else {
                    Log.w(TAG, "Invalid name: " + name);
                    reader.skipValue();
                }
            }
            reader.endObject();
        }
        reader.endArray();
        return list;
    } catch (final IOException e) {
    } finally {
        close(reader);
    }
    return Collections.<Object>emptyList();
}
 
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 List<ZCashTransactionDetails_taddr> readTxArray(JsonReader reader) throws IOException {
  List<ZCashTransactionDetails_taddr> txs = new LinkedList<>();
  reader.beginArray();
  while (reader.hasNext()) {
    txs.add(readTx(reader));
  }

  reader.endArray();
  return txs;
}
 
Example 14
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 15
Source File: AndroidPlacesApiJsonParser.java    From android-PlacesAutocompleteTextView with BSD 2-Clause "Simplified" License 5 votes vote down vote up
List<Place> readPredictionsArray(JsonReader reader) throws IOException {
    List<Place> predictions = new ArrayList<>();

    reader.beginArray();
    while (reader.hasNext()) {
        predictions.add(readPlace(reader));
    }
    reader.endArray();
    return predictions;
}
 
Example 16
Source File: AboutJSONParser.java    From pivaa with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Iterating objects
 * @param reader
 * @return
 * @throws IOException
 */
private ArrayList<AboutRecord> readMessagesArray(JsonReader reader) throws IOException {
    ArrayList<AboutRecord> messages = new ArrayList<AboutRecord>();

    reader.beginArray();
    while (reader.hasNext()) {
        messages.add(readMessage(reader));
    }
    reader.endArray();
    return messages;
}
 
Example 17
Source File: GeoMultiPolygon.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void setCoordinatesFromJSONStream(JsonReader reader, int crs) throws IOException {
    setCRS(crs);
    reader.beginArray();
    while (reader.hasNext()){
        GeoPolygon polygon = new GeoPolygon();
        polygon.setCoordinatesFromJSONStream(reader, crs);
        mGeometries.add(polygon);
    }
    reader.endArray();
}
 
Example 18
Source File: AndroidPlacesApiJsonParser.java    From android-PlacesAutocompleteTextView with BSD 2-Clause "Simplified" License 4 votes vote down vote up
List<PlaceReview> readReviewsArray(JsonReader reader) throws IOException {
    List<PlaceReview> reviews = new ArrayList<>();

    reader.beginArray();
    while (reader.hasNext()) {
        List<RatingAspect> aspects = null;
        String authorName = null;
        String authorUrl = null;
        String language = null;
        int rating = -1;
        String text = null;
        long time = -1L;

        reader.beginObject();
        while (reader.hasNext()) {
            switch (reader.nextName()) {
                case "aspects":
                    aspects = readAspectsArray(reader);
                    break;
                case "author_name":
                    authorName = reader.nextString();
                    break;
                case "author_url":
                    authorUrl = reader.nextString();
                    break;
                case "language":
                    language = reader.nextString();
                    break;
                case "rating":
                    rating = reader.nextInt();
                    break;
                case "text":
                    text = reader.nextString();
                    break;
                case "time":
                    time = reader.nextLong();
                    break;
                default:
                    reader.skipValue();
                    break;
            }
        }
        reader.endObject();
        reviews.add(new PlaceReview(aspects, authorName, authorUrl, language, rating, text, time));
    }
    reader.endArray();
    return reviews;
}
 
Example 19
Source File: GeoJSONUtil.java    From android_maplib with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static void fillLayerFromGeoJSONStream(VectorLayer layer, InputStream in, int srs, IProgressor progressor) throws IOException, NGException {
    int streamSize = in.available();
    if(null != progressor){
        progressor.setIndeterminate(false);
        progressor.setMax(streamSize);
        progressor.setMessage(layer.getContext().getString(R.string.start_fill_layer) + " " + layer.getName());
    }

    SQLiteDatabase db = null;
    if(layer.getFields() != null && layer.getFields().isEmpty()){
        db = DatabaseContext.getDbForLayer(layer);
    }

    JsonReader reader = new JsonReader(new InputStreamReader(in, "UTF-8"));
    boolean isWGS84 = srs == GeoConstants.CRS_WGS84;
    long counter = 0;
    reader.beginObject();
    while (reader.hasNext()) {
        String name = reader.nextName();
        if(name.equals(GeoConstants.GEOJSON_TYPE_FEATURES)){
            reader.beginArray();
            while (reader.hasNext()) {
                Feature feature = readGeoJSONFeature(reader, layer, isWGS84);
                if (null != feature) {
                    if(layer.getFields() != null && !layer.getFields().isEmpty()){
                        if (feature.getGeometry() != null)
                            layer.create(feature.getGeometry().getType(), feature.getFields());

                        db = DatabaseContext.getDbForLayer(layer);
                    }

                    if(feature.getGeometry() != null) {
                        layer.createFeatureBatch(feature, db);
                        if(null != progressor){
                            if (progressor.isCanceled()) {
                                layer.save();
                                return;
                            }
                            progressor.setValue(streamSize - in.available());
                            progressor.setMessage(layer.getContext().getString(R.string.process_features) + ": " + counter++);
                        }
                    }
                }
            }
            reader.endArray();
        }
        else {
            reader.skipValue();
        }
    }
    reader.endObject();
    reader.close();

    //if(null != db)
    //    db.close(); // return pragma to init

    layer.save();
}
 
Example 20
Source File: GeoJSONUtil.java    From android_maplib with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static void createLayerFromGeoJSONStream(VectorLayer layer, InputStream in, IProgressor progressor, boolean isWGS84) throws IOException, NGException {
    int streamSize = in.available();
    if(null != progressor){
        progressor.setIndeterminate(false);
        progressor.setMax(streamSize);
        progressor.setMessage(layer.getContext().getString(R.string.start_fill_layer) + " " + layer.getName());
    }

    SQLiteDatabase db = null;
    if(layer.getFields() != null && layer.getFields().isEmpty()){
        db = DatabaseContext.getDbForLayer(layer);
    }

    JsonReader reader = new JsonReader(new InputStreamReader(in, "UTF-8"));
    long counter = 0;
    reader.beginObject();
    while (reader.hasNext()) {
        String name = reader.nextName();
        if (name.equals(GeoConstants.GEOJSON_TYPE_FEATURES)) {
            reader.beginArray();
            while (reader.hasNext()) {
                Feature feature = readGeoJSONFeature(reader, layer, isWGS84);
                if (null != feature) {
                    if (layer.getFields() == null || layer.getFields().isEmpty()) {
                        if (feature.getGeometry() != null)
                            layer.create(feature.getGeometry().getType(), feature.getFields());

                        db = DatabaseContext.getDbForLayer(layer);
                    }

                    if (feature.getGeometry() != null) {
                        layer.createFeatureBatch(feature, db);
                        if(null != progressor){
                            if (progressor.isCanceled()) {
                                layer.save();
                                return;
                            }
                            progressor.setValue(streamSize - in.available());
                            progressor.setMessage(layer.getContext().getString(R.string.process_features) + ": " + counter++);
                        }
                    }
                }
            }
            reader.endArray();
        } else {
            reader.skipValue();
        }
    }
    reader.endObject();
    reader.close();

    //if(null != db)
    //   db.close(); // return pragma to init
    layer.save();
}