Example usage for com.fasterxml.jackson.core JsonToken END_ARRAY

List of usage examples for com.fasterxml.jackson.core JsonToken END_ARRAY

Introduction

In this page you can find the example usage for com.fasterxml.jackson.core JsonToken END_ARRAY.

Prototype

JsonToken END_ARRAY

To view the source code for com.fasterxml.jackson.core JsonToken END_ARRAY.

Click Source Link

Document

END_ARRAY is returned when encountering ']' which signals ending of an Array value

Usage

From source file:com.bazaarvoice.jackson.rison.RisonParser.java

/**
 * @return Next token from the stream, if any found, or null
 *   to indicate end-of-input/*from   w ww  .  j av a 2  s.co m*/
 */
@Override
public JsonToken nextToken() throws IOException, JsonParseException {
    _numTypesValid = NR_UNKNOWN;

    if (_currToken == null && _parsingContext.inRoot()) {
        if (isRisonEnabled(Feature.A_RISON)) {
            _parsingContext = _parsingContext.createChildArrayContext(_tokenInputRow, _tokenInputCol);
            return (_currToken = JsonToken.START_ARRAY);
        } else if (isRisonEnabled(Feature.O_RISON)) {
            _parsingContext = _parsingContext.createChildObjectContext(_tokenInputRow, _tokenInputCol);
            return (_currToken = JsonToken.START_OBJECT);
        }
    }

    /* First: field names are special -- we will always tokenize
     * (part of) value along with field name to simplify
     * state handling. If so, can and need to use secondary token:
     */
    if (_currToken == JsonToken.FIELD_NAME) {
        return _nextAfterName();
    }
    if (_tokenIncomplete) {
        _skipString(); // only strings can be partial
    }
    int i = _nextChOrEnd();
    if (i < 0) { // end-of-input
        /* 19-Feb-2009, tatu: Should actually close/release things
         *    like input source, symbol table and recyclable buffers now.
         */
        close();
        if (_parsingContext.getParent().inRoot()) {
            if (isRisonEnabled(Feature.A_RISON) && _parsingContext.inArray()) {
                _parsingContext = _parsingContext.getParent();
                return (_currToken = JsonToken.END_ARRAY);
            }
            if (isRisonEnabled(Feature.O_RISON) && _parsingContext.inObject()) {
                _parsingContext = _parsingContext.getParent();
                return (_currToken = JsonToken.END_OBJECT);
            }
        }
        _handleEOF();
        return (_currToken = null);
    }

    /* First, need to ensure we know the starting location of token
     * after skipping leading white space
     */
    _tokenInputTotal = _currInputProcessed + _inputPtr - 1;
    _tokenInputRow = _currInputRow;
    _tokenInputCol = _inputPtr - _currInputRowStart - 1;

    // finally: clear any data retained so far
    _binaryValue = null;

    // Closing scope?
    if (i == ')') {
        if (_parsingContext.inArray()) {
            _parsingContext = _parsingContext.getParent();
            return (_currToken = JsonToken.END_ARRAY);
        }
        if (_parsingContext.inObject()) {
            _parsingContext = _parsingContext.getParent();
            return (_currToken = JsonToken.END_OBJECT);
        }
        _reportMismatchedEndMarker(i, ')');
    }

    // Nope: do we then expect a comma?
    if (_parsingContext.expectComma()) {
        if (i != INT_COMMA) {
            _reportUnexpectedChar(i,
                    "was expecting comma to separate " + _parsingContext.getTypeDesc() + " entries");
        }
        i = _nextCh();
    }

    /* And should we now have a name? Always true for
     * Object contexts, since the intermediate 'expect-value'
     * state is never retained.
     */
    boolean inObject = _parsingContext.inObject();
    if (inObject) {
        // First, field name itself:
        String name;
        if (i != INT_APOSTROPHE) {
            name = _parseUnquotedFieldName(i);
        } else {
            name = _parseFieldName(i);
        }
        _parsingContext.setCurrentName(name);
        _currToken = JsonToken.FIELD_NAME;
        i = _nextCh();
        if (i != INT_COLON) {
            _reportUnexpectedChar(i, "was expecting a colon to separate field name and value");
        }
        i = _nextCh();
    }

    // Ok: we must have a value... what is it?

    JsonToken t;

    switch (i) {
    case INT_APOSTROPHE:
        _tokenIncomplete = true;
        t = JsonToken.VALUE_STRING;
        break;
    case '(':
        if (!inObject) {
            _parsingContext = _parsingContext.createChildObjectContext(_tokenInputRow, _tokenInputCol);
        }
        t = JsonToken.START_OBJECT;
        break;
    case ')':
        // Error: ')' is not valid at this point; valid closers have
        // been handled earlier
        _reportUnexpectedChar(i, "expected a value");

    case INT_MINUS:
        /* Should we have separate handling for plus? Although
        * it is not allowed per se, it may be erroneously used,
        * and could be indicate by a more specific error message.
        */
    case INT_0:
    case INT_1:
    case INT_2:
    case INT_3:
    case INT_4:
    case INT_5:
    case INT_6:
    case INT_7:
    case INT_8:
    case INT_9:
        t = parseNumberText(i);
        break;

    case '!':
        i = _nextCh();
        switch (i) {
        case '(':
            if (!inObject) {
                _parsingContext = _parsingContext.createChildArrayContext(_tokenInputRow, _tokenInputCol);
            }
            t = JsonToken.START_ARRAY;
            break;
        case INT_t:
            t = JsonToken.VALUE_TRUE;
            break;
        case INT_f:
            t = JsonToken.VALUE_FALSE;
            break;
        case INT_n:
            t = JsonToken.VALUE_NULL;
            break;
        default:
            t = _handleUnexpectedValue(i);
            break;
        }
        break;
    default:
        if (IdentifierUtils.isIdStartLenient(i)) {
            t = JsonToken.VALUE_STRING;
            _inputPtr--; // push back the first char
            _parseUnquotedString();
        } else {
            t = _handleUnexpectedValue(i);
        }
        break;
    }

    if (inObject) {
        _nextToken = t;
        return _currToken;
    }
    _currToken = t;
    return t;
}

From source file:com.amazonaws.services.cloudtrail.processinglibrary.serializer.AbstractEventSerializer.java

/**
 * Parse a list of Resource/*  w w  w .  j a va 2s . com*/
 *
 * @param eventData the resources belong to
 * @throws IOException
 */
private void parseResources(CloudTrailEventData eventData) throws IOException {
    JsonToken nextToken = this.jsonParser.nextToken();
    if (nextToken == JsonToken.VALUE_NULL) {
        eventData.add(CloudTrailEventField.resources.name(), null);
        return;
    }

    if (nextToken != JsonToken.START_ARRAY) {
        throw new JsonParseException("Not a list of resources object", this.jsonParser.getCurrentLocation());
    }

    List<Resource> resources = new ArrayList<Resource>();

    while (this.jsonParser.nextToken() != JsonToken.END_ARRAY) {
        resources.add(this.parseResource());
    }

    eventData.add(CloudTrailEventField.resources.name(), resources);
}

From source file:com.netflix.hollow.jsonadapter.HollowJsonAdapter.java

private int addStructuredMap(JsonParser parser, String mapTypeName, HollowMapWriteRecord mapRec)
        throws IOException {
    JsonToken token = parser.nextToken();
    mapRec.reset();//from ww w . j ava  2s. c om

    HollowMapSchema schema = (HollowMapSchema) hollowSchemas.get(mapTypeName);

    while (token != JsonToken.END_ARRAY) {
        if (token == JsonToken.START_OBJECT) {
            int keyOrdinal = -1, valueOrdinal = -1;
            while (token != JsonToken.END_OBJECT) {

                if (token == JsonToken.START_OBJECT || token == JsonToken.START_ARRAY) {
                    if ("key".equals(parser.getCurrentName()))
                        keyOrdinal = parseSubType(parser, token, schema.getKeyType());
                    else if ("value".equals(parser.getCurrentName()))
                        valueOrdinal = parseSubType(parser, token, schema.getValueType());
                }

                token = parser.nextToken();
            }

            mapRec.addEntry(keyOrdinal, valueOrdinal);
        }

        token = parser.nextToken();
    }

    return stateEngine.add(schema.getName(), mapRec);
}

From source file:org.apache.lucene.server.handlers.AddDocumentHandler.java

/** Parses the current json token into the corresponding
 *  java object. *//*from w w  w  .j  a  v  a2 s.  c  o m*/
private static Object getNativeValue(FieldDef fd, JsonToken token, JsonParser p) throws IOException {
    Object o;
    if (token == JsonToken.VALUE_STRING) {
        o = p.getText();
    } else if (token == JsonToken.VALUE_NUMBER_INT) {
        o = Long.valueOf(p.getLongValue());
    } else if (token == JsonToken.VALUE_NUMBER_FLOAT) {
        o = Double.valueOf(p.getDoubleValue());
    } else if (token == JsonToken.VALUE_TRUE) {
        o = Boolean.TRUE;
    } else if (token == JsonToken.VALUE_FALSE) {
        o = Boolean.FALSE;
    } else if (fd.faceted.equals("hierarchy") && token == JsonToken.START_ARRAY) {
        if (fd.multiValued == false) {
            List<String> values = new ArrayList<>();
            while (true) {
                token = p.nextToken();
                if (token == JsonToken.END_ARRAY) {
                    break;
                } else if (token != JsonToken.VALUE_STRING) {
                    if (token == JsonToken.START_ARRAY) {
                        fail(fd.name, "expected array of strings, but saw array inside array");
                    } else {
                        fail(fd.name, "expected array of strings, but saw " + token + " inside array");
                    }
                }
                values.add(p.getText());
            }
            o = values;
        } else {
            List<List<String>> values = new ArrayList<>();
            while (true) {
                token = p.nextToken();
                if (token == JsonToken.END_ARRAY) {
                    break;
                } else if (token == JsonToken.START_ARRAY) {
                    List<String> sub = new ArrayList<>();
                    values.add(sub);
                    while (true) {
                        token = p.nextToken();
                        if (token == JsonToken.VALUE_STRING) {
                            sub.add(p.getText());
                        } else if (token == JsonToken.END_ARRAY) {
                            break;
                        } else {
                            fail(fd.name, "expected array of strings or array of array of strings, but saw "
                                    + token + " inside inner array");
                        }
                    }
                } else if (token == JsonToken.VALUE_STRING) {
                    List<String> sub = new ArrayList<>();
                    values.add(sub);
                    sub.add(p.getText());
                } else if (token == JsonToken.START_ARRAY) {
                    fail(fd.name, "expected array of strings, but saw array inside array");
                } else {
                    fail(fd.name, "expected array of strings, but saw " + token + " inside array");
                }
            }
            o = values;
        }
    } else if (fd.valueType == FieldDef.FieldValueType.LAT_LON) {
        if (token != JsonToken.START_ARRAY) {
            fail(fd.name, "latlon field must be [lat, lon] value; got " + token);
        }
        double[] latLon = new double[2];
        token = p.nextToken();
        if (token != JsonToken.VALUE_NUMBER_FLOAT) {
            fail(fd.name, "latlon field must be [lat, lon] value; got " + token);
        }
        latLon[0] = p.getDoubleValue();
        token = p.nextToken();
        if (token != JsonToken.VALUE_NUMBER_FLOAT) {
            fail(fd.name, "latlon field must be [lat, lon] value; got " + token);
        }
        latLon[1] = p.getDoubleValue();
        token = p.nextToken();
        if (token != JsonToken.END_ARRAY) {
            fail(fd.name, "latlon field must be [lat, lon] value; got " + token);
        }
        o = latLon;
    } else {
        String message;
        if (token == JsonToken.VALUE_NULL) {
            message = "null field value not supported; just omit this field from the document instead";
        } else {
            message = "value in inner object field value should be string, int/long, float/double or boolean; got "
                    + token;
        }

        fail(fd.name, message);

        // Dead code but compiler disagrees:
        o = null;
    }
    return o;
}

From source file:com.zenesis.qx.remote.RequestHandler.java

private Object[] readParameters(JsonParser jp, Class[] types) throws IOException {
    if (types == null) {
        // Check for parameters
        if (jp.getCurrentToken() == JsonToken.FIELD_NAME && jp.getCurrentName().equals("parameters")
                && jp.nextToken() == JsonToken.START_ARRAY) {
            while (jp.nextToken() != JsonToken.END_ARRAY)
                ;//from   w  ww .j a  v a  2  s  .  co  m
        }
        return null;
    }
    Object[] values = new Object[types.length];
    Object[] params = null;

    // Check for parameters
    if (jp.getCurrentToken() == JsonToken.FIELD_NAME && jp.getCurrentName().equals("parameters")
            && jp.nextToken() == JsonToken.START_ARRAY) {

        params = readArray(jp, types);
    }

    for (int i = 0; i < values.length; i++)
        if (i < params.length)
            values[i] = params[i];
        else
            values[i] = null;

    return values;
}

From source file:com.zenesis.qx.remote.RequestHandler.java

/**
 * Called when the client has disposed of
 * @param jp/* ww  w  .  j  ava  2 s  .com*/
 * @throws ServletException
 * @throws IOException
 */
protected void cmdDispose(JsonParser jp) throws ServletException, IOException {
    skipFieldName(jp, "serverIds");
    while (jp.nextToken() != JsonToken.END_ARRAY) {
        int serverId = jp.readValueAs(Integer.class);
        tracker.forget(serverId);
    }

    jp.nextToken();
}

From source file:io.protostuff.JsonIOUtil.java

/**
 * Parses the {@code messages} from the parser using the given {@code schema}.
 *///from   w w w .  j a  va2  s. c om
public static <T> List<T> parseListFrom(JsonParser parser, Schema<T> schema, boolean numeric)
        throws IOException {
    if (parser.nextToken() != JsonToken.START_ARRAY) {
        throw new JsonInputException("Expected token: [ but was " + parser.getCurrentToken() + " on message: "
                + schema.messageFullName());
    }

    final JsonInput input = new JsonInput(parser, numeric);
    final List<T> list = new ArrayList<>();
    for (JsonToken t = parser.nextToken(); t != JsonToken.END_ARRAY; t = parser.nextToken()) {
        if (t != JsonToken.START_OBJECT) {
            throw new JsonInputException("Expected token: { but was " + parser.getCurrentToken()
                    + " on message " + schema.messageFullName());
        }

        final T message = schema.newMessage();
        schema.mergeFrom(input, message);

        if (parser.getCurrentToken() != JsonToken.END_OBJECT) {
            throw new JsonInputException("Expected token: } but was " + parser.getCurrentToken()
                    + " on message " + schema.messageFullName());
        }

        list.add(message);
        input.reset();
    }
    return list;
}

From source file:com.netflix.hollow.jsonadapter.HollowJsonAdapter.java

private void skipSubArray(JsonParser parser) throws IOException {
    JsonToken token = parser.nextToken();

    while (token != JsonToken.END_ARRAY) {

        if (token == JsonToken.START_OBJECT) {
            skipObject(parser);//from w  ww  . j a v a2s  .  c om
        } else {
            skipObjectField(parser, token);
        }

        token = parser.nextToken();
    }
}

From source file:com.github.heuermh.personalgenome.client.converter.JacksonPersonalGenomeConverter.java

@Override
public List<Relative> parseRelatives(final InputStream inputStream) {
    checkNotNull(inputStream);//  w w w  .j a va 2  s  . c o  m
    JsonParser parser = null;
    try {
        parser = jsonFactory.createParser(inputStream);
        parser.nextToken();

        List<Relative> relatives = new ArrayList<Relative>();

        String profileId = null;
        String matchId = null;
        double similarity = 0.0d;
        int sharedSegments = 0;
        Relationship relationship = null;
        Relationship userRelationship = null;
        Set<Relationship> range = new HashSet<Relationship>();

        while (parser.nextToken() != JsonToken.END_OBJECT) {
            String field = parser.getCurrentName();
            parser.nextToken();

            if ("id".equals(field)) {
                profileId = parser.getText();
            } else if ("relatives".equals(field)) {
                while (parser.nextToken() != JsonToken.END_ARRAY) {
                    while (parser.nextToken() != JsonToken.END_OBJECT) {
                        String relativeField = parser.getCurrentName();
                        parser.nextToken();

                        if ("match_id".equals(relativeField)) {
                            matchId = parser.getText();
                        } else if ("similarity".equals(relativeField)) {
                            similarity = Double.parseDouble(parser.getText());
                        } else if ("shared_segments".equals(relativeField)) {
                            sharedSegments = parser.getIntValue();
                        } else if ("relationship".equals(relativeField)) {
                            relationship = Relationship.fromDescription(parser.getText());
                        } else if ("user_relationship_code".equals(relativeField)) {
                            String code = parser.getText();
                            userRelationship = code == "null" ? null
                                    : Relationship.fromCode(Integer.parseInt(code));
                        } else if ("predicted_relationship_code".equals(relativeField)) {
                            if (relationship == null) {
                                String code = parser.getText();
                                relationship = code == "null" ? null
                                        : Relationship.fromCode(Integer.parseInt(code));
                            }
                        } else if ("range".equals(relativeField)) {
                            while (parser.nextToken() != JsonToken.END_ARRAY) {
                                range.add(Relationship.fromDescription(parser.getText()));
                            }
                        }
                        // ignored nested fields
                        else if ("family_locations".equals(relativeField)) {
                            while (parser.nextToken() != JsonToken.END_ARRAY) {
                                // ignore
                            }
                        } else if ("family_surnames".equals(relativeField)) {
                            while (parser.nextToken() != JsonToken.END_ARRAY) {
                                // ignore
                            }
                        } else if ("profile_picture_urls".equals(relativeField)) {
                            while (parser.nextToken() != JsonToken.END_OBJECT) {
                                // ignore
                            }
                        }
                    }
                }
                relatives.add(new Relative(profileId, matchId, similarity, sharedSegments, relationship,
                        userRelationship, range));
                matchId = null;
                similarity = 0.0d;
                sharedSegments = 0;
                relationship = null;
                userRelationship = null;
                range.clear();
            }
        }
        return relatives;
    } catch (IOException e) {
        logger.warn("could not parse relatives", e);
    } finally {
        try {
            inputStream.close();
        } catch (Exception e) {
            // ignored
        }
        try {
            parser.close();
        } catch (Exception e) {
            // ignored
        }
    }
    return null;
}

From source file:pl.selvin.android.syncframework.content.BaseContentProvider.java

protected boolean Sync(String service, String scope, String params) {
    final Date start = new Date();
    boolean hasError = false;
    if (params == null)
        params = "";
    final SQLiteDatabase db = mDB.getWritableDatabase();
    final ArrayList<TableInfo> notifyTableInfo = new ArrayList<TableInfo>();

    final String download = String.format(contentHelper.DOWNLOAD_SERVICE_URI, service, scope, params);
    final String upload = String.format(contentHelper.UPLOAD_SERVICE_URI, service, scope, params);
    final String scopeServerBlob = String.format("%s.%s.%s", service, scope, _.serverBlob);
    String serverBlob = null;//from   ww w .  jav a 2s .c  o  m
    Cursor cur = db.query(BlobsTable.NAME, new String[] { BlobsTable.C_VALUE }, BlobsTable.C_NAME + "=?",
            new String[] { scopeServerBlob }, null, null, null);
    final String originalBlob;
    if (cur.moveToFirst()) {
        originalBlob = serverBlob = cur.getString(0);
    } else {
        originalBlob = null;
    }
    cur.close();
    db.beginTransaction();
    try {
        boolean nochanges = false;
        if (serverBlob != null) {
            nochanges = !contentHelper.hasDirtTable(db, scope);
        }
        boolean resolve = false;
        final Metadata meta = new Metadata();
        final HashMap<String, Object> vals = new HashMap<String, Object>();
        final ContentValues cv = new ContentValues(2);
        JsonFactory jsonFactory = new JsonFactory();
        JsonToken current = null;
        String name = null;
        boolean moreChanges = false;
        boolean forceMoreChanges = false;
        do {
            final int requestMethod;
            final String serviceRequestUrl;
            final ContentProducer contentProducer;

            if (serverBlob != null) {
                requestMethod = HTTP_POST;
                if (nochanges) {
                    serviceRequestUrl = download;
                } else {
                    serviceRequestUrl = upload;
                    forceMoreChanges = true;
                }
                contentProducer = new SyncContentProducer(jsonFactory, db, scope, serverBlob, !nochanges,
                        notifyTableInfo, contentHelper);
                nochanges = true;
            } else {
                requestMethod = HTTP_GET;
                serviceRequestUrl = download;
                contentProducer = null;

            }
            if (moreChanges) {
                db.beginTransaction();
            }

            Result result = executeRequest(requestMethod, serviceRequestUrl, contentProducer);
            if (result.getStatus() == HttpStatus.SC_OK) {
                final JsonParser jp = jsonFactory.createParser(result.getInputStream());

                jp.nextToken(); // skip ("START_OBJECT(d) expected");
                jp.nextToken(); // skip ("FIELD_NAME(d) expected");
                if (jp.nextToken() != JsonToken.START_OBJECT)
                    throw new Exception("START_OBJECT(d - object) expected");
                while (jp.nextToken() != JsonToken.END_OBJECT) {
                    name = jp.getCurrentName();
                    if (_.__sync.equals(name)) {
                        current = jp.nextToken();
                        while (jp.nextToken() != JsonToken.END_OBJECT) {
                            name = jp.getCurrentName();
                            current = jp.nextToken();
                            if (_.serverBlob.equals(name)) {
                                serverBlob = jp.getText();
                            } else if (_.moreChangesAvailable.equals(name)) {
                                moreChanges = jp.getBooleanValue() || forceMoreChanges;
                                forceMoreChanges = false;
                            } else if (_.resolveConflicts.equals(name)) {
                                resolve = jp.getBooleanValue();
                            }
                        }
                    } else if (_.results.equals(name)) {
                        if (jp.nextToken() != JsonToken.START_ARRAY)
                            throw new Exception("START_ARRAY(results) expected");
                        while (jp.nextToken() != JsonToken.END_ARRAY) {
                            meta.isDeleted = false;
                            meta.tempId = null;
                            vals.clear();
                            while (jp.nextToken() != JsonToken.END_OBJECT) {
                                name = jp.getCurrentName();
                                current = jp.nextToken();
                                if (current == JsonToken.VALUE_STRING) {
                                    vals.put(name, jp.getText());
                                } else if (current == JsonToken.VALUE_NUMBER_INT) {
                                    vals.put(name, jp.getLongValue());
                                } else if (current == JsonToken.VALUE_NUMBER_FLOAT) {
                                    vals.put(name, jp.getDoubleValue());
                                } else if (current == JsonToken.VALUE_FALSE) {
                                    vals.put(name, 0L);
                                } else if (current == JsonToken.VALUE_TRUE) {
                                    vals.put(name, 1L);
                                } else if (current == JsonToken.VALUE_NULL) {
                                    vals.put(name, null);
                                } else {
                                    if (current == JsonToken.START_OBJECT) {
                                        if (_.__metadata.equals(name)) {
                                            while (jp.nextToken() != JsonToken.END_OBJECT) {
                                                name = jp.getCurrentName();
                                                jp.nextToken();
                                                if (_.uri.equals(name)) {
                                                    meta.uri = jp.getText();
                                                } else if (_.type.equals(name)) {
                                                    meta.type = jp.getText();
                                                } else if (_.isDeleted.equals(name)) {
                                                    meta.isDeleted = jp.getBooleanValue();
                                                } else if (_.tempId.equals(name)) {
                                                    meta.tempId = jp.getText();
                                                }
                                            }
                                        } else if (_.__syncConflict.equals(name)) {
                                            while (jp.nextToken() != JsonToken.END_OBJECT) {
                                                name = jp.getCurrentName();
                                                jp.nextToken();
                                                if (_.isResolved.equals(name)) {
                                                } else if (_.conflictResolution.equals(name)) {
                                                } else if (_.conflictingChange.equals(name)) {
                                                    while (jp.nextToken() != JsonToken.END_OBJECT) {
                                                        name = jp.getCurrentName();
                                                        current = jp.nextToken();
                                                        if (current == JsonToken.START_OBJECT) {
                                                            if (_.__metadata.equals(name)) {
                                                                while (jp.nextToken() != JsonToken.END_OBJECT) {

                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                            // resolve conf

                                        } else if (_.__syncError.equals(name)) {
                                            while (jp.nextToken() != JsonToken.END_OBJECT) {
                                                name = jp.getCurrentName();
                                                jp.nextToken();
                                            }
                                        }
                                    }
                                }
                            }
                            TableInfo tab = contentHelper.getTableFromType(meta.type);
                            if (meta.isDeleted) {
                                tab.DeleteWithUri(meta.uri, db);
                            } else {
                                tab.SyncJSON(vals, meta, db);
                            }
                            if (!notifyTableInfo.contains(tab))
                                notifyTableInfo.add(tab);
                        }
                    }
                }
                jp.close();
                if (!hasError) {
                    cv.clear();
                    cv.put(BlobsTable.C_NAME, scopeServerBlob);
                    cv.put(BlobsTable.C_VALUE, serverBlob);
                    cv.put(BlobsTable.C_DATE, Calendar.getInstance().getTimeInMillis());
                    cv.put(BlobsTable.C_STATE, 0);
                    db.replace(BlobsTable.NAME, null, cv);
                    db.setTransactionSuccessful();
                    db.endTransaction();
                    if (DEBUG) {
                        Log.d(TAG, "CP-Sync: commit changes");
                    }
                    final ContentResolver cr = getContext().getContentResolver();
                    for (TableInfo t : notifyTableInfo) {
                        final Uri nu = contentHelper.getDirUri(t.name, false);
                        cr.notifyChange(nu, null, false);
                        // false - do not force sync cause we are in sync
                        if (DEBUG) {
                            Log.d(TAG, "CP-Sync: notifyChange table: " + t.name + ", uri: " + nu);
                        }

                        for (String n : t.notifyUris) {
                            cr.notifyChange(Uri.parse(n), null, false);
                            if (DEBUG) {
                                Log.d(TAG, "+uri: " + n);
                            }
                        }
                    }
                    notifyTableInfo.clear();
                }
            } else {
                if (DEBUG) {
                    Log.e(TAG, "Server error in fetching remote contacts: " + result.getStatus());
                }
                hasError = true;
                break;
            }
        } while (moreChanges);
    } catch (final ConnectTimeoutException e) {
        hasError = true;
        if (DEBUG) {
            Log.e(TAG, "ConnectTimeoutException", e);
        }
    } catch (final IOException e) {
        hasError = true;
        if (DEBUG) {
            Log.e(TAG, Log.getStackTraceString(e));
        }
    } catch (final ParseException e) {
        hasError = true;
        if (DEBUG) {
            Log.e(TAG, "ParseException", e);
        }
    } catch (final Exception e) {
        hasError = true;
        if (DEBUG) {
            Log.e(TAG, "ParseException", e);
        }
    }
    if (hasError) {
        db.endTransaction();
        ContentValues cv = new ContentValues();
        cv.put(BlobsTable.C_NAME, scopeServerBlob);
        cv.put(BlobsTable.C_VALUE, originalBlob);
        cv.put(BlobsTable.C_DATE, Calendar.getInstance().getTimeInMillis());
        cv.put(BlobsTable.C_STATE, -1);
        db.replace(BlobsTable.NAME, null, cv);
    }
    /*-if (!hasError) {
    final ContentValues cv = new ContentValues(2);
     cv.put(BlobsTable.C_NAME, scopeServerBlob);
     cv.put(BlobsTable.C_VALUE, serverBlob);
     db.replace(BlobsTable.NAME, null, cv);
     db.setTransactionSuccessful();
    }
    db.endTransaction();
    if (!hasError) {
     for (String t : notifyTableInfo) {
    getContext().getContentResolver().notifyChange(getDirUri(t),
          null);
     }
    }*/
    if (DEBUG) {
        Helpers.LogInfo(start);
    }
    return !hasError;
}