本文整理汇总了Java中org.mozilla.gecko.sync.NonObjectJSONException类的典型用法代码示例。如果您正苦于以下问题:Java NonObjectJSONException类的具体用法?Java NonObjectJSONException怎么用?Java NonObjectJSONException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
NonObjectJSONException类属于org.mozilla.gecko.sync包,在下文中一共展示了NonObjectJSONException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: fromJSONObject
import org.mozilla.gecko.sync.NonObjectJSONException; //导入依赖的package包/类
public static State fromJSONObject(StateLabel stateLabel, ExtendedJSONObject o) throws InvalidKeySpecException, NoSuchAlgorithmException, NonObjectJSONException {
Long version = o.getLong("version");
if (version == null) {
throw new IllegalStateException("version must not be null");
}
final int v = version.intValue();
if (v == 3) {
// The most common case is the most recent version.
return fromJSONObjectV3(stateLabel, o);
}
if (v == 2) {
return fromJSONObjectV2(stateLabel, o);
}
if (v == 1) {
final State state = fromJSONObjectV1(stateLabel, o);
return migrateV1toV2(stateLabel, state);
}
throw new IllegalStateException("version must be in {1, 2}");
}
示例2: fromJSONObjectV2
import org.mozilla.gecko.sync.NonObjectJSONException; //导入依赖的package包/类
/**
* Exactly the same as {@link fromJSONObjectV1}, except that all key pairs are DSA key pairs.
*/
protected static State fromJSONObjectV2(StateLabel stateLabel, ExtendedJSONObject o) throws InvalidKeySpecException, NoSuchAlgorithmException, NonObjectJSONException {
switch (stateLabel) {
case Cohabiting:
return new Cohabiting(
o.getString("email"),
o.getString("uid"),
Utils.hex2Byte(o.getString("sessionToken")),
Utils.hex2Byte(o.getString("kA")),
Utils.hex2Byte(o.getString("kB")),
keyPairFromJSONObjectV2(o.getObject("keyPair")));
case Married:
return new Married(
o.getString("email"),
o.getString("uid"),
Utils.hex2Byte(o.getString("sessionToken")),
Utils.hex2Byte(o.getString("kA")),
Utils.hex2Byte(o.getString("kB")),
keyPairFromJSONObjectV2(o.getObject("keyPair")),
o.getString("certificate"));
default:
return fromJSONObjectV1(stateLabel, o);
}
}
示例3: jsonObjectBody
import org.mozilla.gecko.sync.NonObjectJSONException; //导入依赖的package包/类
/**
* Return the body as a <b>non-null</b> <code>ExtendedJSONObject</code>.
*
* @return A non-null <code>ExtendedJSONObject</code>.
*
* @throws IllegalStateException
* @throws IOException
* @throws NonObjectJSONException
*/
public ExtendedJSONObject jsonObjectBody() throws IllegalStateException, IOException, NonObjectJSONException {
if (body != null) {
// Do it from the cached String.
return new ExtendedJSONObject(body);
}
HttpEntity entity = this.response.getEntity();
if (entity == null) {
throw new IOException("no entity");
}
InputStream content = entity.getContent();
try {
Reader in = new BufferedReader(new InputStreamReader(content, "UTF-8"));
return new ExtendedJSONObject(in);
} finally {
content.close();
}
}
示例4: onConflict
import org.mozilla.gecko.sync.NonObjectJSONException; //导入依赖的package包/类
@Override
public void onConflict(ClientReadingListRecord up, ReadingListResponse response) {
ExtendedJSONObject body;
try {
body = response.jsonObjectBody();
String conflicting = body.getString("id");
Logger.warn(LOG_TAG, "Conflict detected: remote ID is " + conflicting);
// TODO: When an operation implies that a server record is a replacement
// of what we uploaded, we should ensure that we have a local copy of
// that server record!
} catch (IllegalStateException | NonObjectJSONException | IOException |
ParseException e) {
// Oops.
// But our workaround is the same either way.
}
// Either the record exists locally, in which case we need to merge,
// or it doesn't, and we'll download it shortly.
// The simplest thing to do in both cases is to simply delete the local
// record we tried to upload. Yes, we might lose some annotations, but
// we can leave doing better to a follow-up.
// Issues here are so unlikely that we don't do anything sophisticated
// (like moving the record to a holding area) -- just delete it ASAP.
acc.addDeletion(up);
}
示例5: unpickleV1
import org.mozilla.gecko.sync.NonObjectJSONException; //导入依赖的package包/类
private void unpickleV1(final ExtendedJSONObject json)
throws NonObjectJSONException, NoSuchAlgorithmException, InvalidKeySpecException {
this.accountVersion = json.getIntegerSafely(KEY_ACCOUNT_VERSION);
this.email = json.getString(KEY_EMAIL);
this.profile = json.getString(KEY_PROFILE);
this.authServerURI = json.getString(KEY_IDP_SERVER_URI);
this.tokenServerURI = json.getString(KEY_TOKEN_SERVER_URI);
this.profileServerURI = json.getString(KEY_PROFILE_SERVER_URI);
// Fallback to default value when profile server URI was not pickled.
if (this.profileServerURI == null) {
this.profileServerURI = FxAccountConstants.DEFAULT_AUTH_SERVER_ENDPOINT.equals(this.authServerURI)
? FxAccountConstants.DEFAULT_PROFILE_SERVER_ENDPOINT
: FxAccountConstants.STAGE_PROFILE_SERVER_ENDPOINT;
}
// We get the default value for everything except syncing browser data.
this.authoritiesToSyncAutomaticallyMap.put(BrowserContract.AUTHORITY, json.getBoolean(KEY_IS_SYNCING_ENABLED));
this.bundle = json.getObject(KEY_BUNDLE);
if (bundle == null) {
throw new IllegalStateException("Pickle bundle is null.");
}
this.state = getState(bundle);
}
示例6: unpickleV3
import org.mozilla.gecko.sync.NonObjectJSONException; //导入依赖的package包/类
private void unpickleV3(final ExtendedJSONObject json)
throws NonObjectJSONException, NoSuchAlgorithmException, InvalidKeySpecException {
// We'll overwrite the extracted sync automatically map.
unpickleV1(json);
// Extract the map of authorities to sync automatically.
authoritiesToSyncAutomaticallyMap.clear();
final ExtendedJSONObject o = json.getObject(KEY_AUTHORITIES_TO_SYNC_AUTOMATICALLY_MAP);
if (o == null) {
return;
}
for (String key : o.keySet()) {
final Boolean enabled = o.getBoolean(key);
if (enabled != null) {
authoritiesToSyncAutomaticallyMap.put(key, enabled);
}
}
}
示例7: getState
import org.mozilla.gecko.sync.NonObjectJSONException; //导入依赖的package包/类
private State getState(final ExtendedJSONObject bundle) throws InvalidKeySpecException,
NonObjectJSONException, NoSuchAlgorithmException {
// TODO: Should copy-pasta BUNDLE_KEY_STATE & LABEL to this file to ensure we maintain
// old versions?
final StateLabel stateLabelString = StateLabel.valueOf(
bundle.getString(AndroidFxAccount.BUNDLE_KEY_STATE_LABEL));
final String stateString = bundle.getString(AndroidFxAccount.BUNDLE_KEY_STATE);
if (stateLabelString == null || stateString == null) {
throw new IllegalStateException("stateLabel and stateString must not be null, but: " +
"(stateLabel == null) = " + (stateLabelString == null) +
" and (stateString == null) = " + (stateString == null));
}
try {
return StateFactory.fromJSONObject(stateLabelString, new ExtendedJSONObject(stateString));
} catch (Exception e) {
throw new IllegalStateException("could not get state", e);
}
}
示例8: jsonObjectBody
import org.mozilla.gecko.sync.NonObjectJSONException; //导入依赖的package包/类
/**
* Return the body as a <b>non-null</b> <code>ExtendedJSONObject</code>.
*
* @return A non-null <code>ExtendedJSONObject</code>.
*
* @throws IllegalStateException
* @throws IOException
* @throws ParseException
* @throws NonObjectJSONException
*/
public ExtendedJSONObject jsonObjectBody() throws IllegalStateException, IOException,
ParseException, NonObjectJSONException {
if (body != null) {
// Do it from the cached String.
return ExtendedJSONObject.parseJSONObject(body);
}
HttpEntity entity = this.response.getEntity();
if (entity == null) {
throw new IOException("no entity");
}
InputStream content = entity.getContent();
try {
Reader in = new BufferedReader(new InputStreamReader(content, "UTF-8"));
return ExtendedJSONObject.parseJSONObject(in);
} finally {
content.close();
}
}
示例9: testStoreFetch
import org.mozilla.gecko.sync.NonObjectJSONException; //导入依赖的package包/类
public void testStoreFetch() throws NullCursorException, NonObjectJSONException, IOException, ParseException {
String guid = Utils.generateGuid();
extender.store(Utils.generateGuid(), null);
extender.store(guid, null);
extender.store(Utils.generateGuid(), null);
Cursor cur = null;
try {
cur = extender.fetch(guid);
assertEquals(1, cur.getCount());
assertTrue(cur.moveToFirst());
assertEquals(guid, cur.getString(0));
} finally {
if (cur != null) {
cur.close();
}
}
}
示例10: createDefaultGlobalSession
import org.mozilla.gecko.sync.NonObjectJSONException; //导入依赖的package包/类
private GlobalSession createDefaultGlobalSession(final GlobalSessionCallback callback) throws SyncConfigurationException, IllegalArgumentException, NonObjectJSONException, IOException, ParseException, CryptoException {
final KeyBundle keyBundle = new KeyBundle(TEST_USERNAME, TEST_SYNC_KEY);
final AuthHeaderProvider authHeaderProvider = new BasicAuthHeaderProvider(TEST_USERNAME, TEST_PASSWORD);
final SharedPreferences prefs = new MockSharedPreferences();
final SyncConfiguration config = new SyncConfiguration(TEST_USERNAME, authHeaderProvider, prefs);
config.syncKeyBundle = keyBundle;
return new GlobalSession(config, callback, getApplicationContext(), null, callback) {
@Override
public boolean isEngineRemotelyEnabled(String engineName,
EngineSettings engineSettings)
throws MetaGlobalException {
return true;
}
@Override
public void advance() {
// So we don't proceed and run other stages.
}
};
}
示例11: loadSession
import org.mozilla.gecko.sync.NonObjectJSONException; //导入依赖的package包/类
/**
* @throws FailedToLoadSessionException if we're unable to load the account.
* @return a FirefoxAccount.
*/
@NonNull
@AnyThread
FirefoxAccountSession loadSession() throws FailedToLoadSessionException {
if (sharedPrefs.getInt(KEY_VERSION, -1) < 0) { throw new FailedToLoadSessionException("account does not exist"); }
final State state;
try {
final StateLabel stateLabel = State.StateLabel.valueOf(sharedPrefs.getString(KEY_STATE_LABEL, null));
final ExtendedJSONObject stateJSON = new ExtendedJSONObject(sharedPrefs.getString(KEY_STATE_JSON, null));
state = StateFactory.fromJSONObject(stateLabel, stateJSON);
} catch (final NoSuchAlgorithmException | IOException | NonObjectJSONException | InvalidKeySpecException | IllegalArgumentException e) {
throw new FailedToLoadSessionException("unable to restore account state", e);
}
final String endpointConfigLabel = sharedPrefs.getString(KEY_ENDPOINT_CONFIG_LABEL, "");
final FirefoxAccountEndpointConfig endpointConfig;
switch (endpointConfigLabel) { // We should probably use enums over Strings, but it wasn't worth my time.
case LABEL_STABLE_DEV: endpointConfig = FirefoxAccountEndpointConfig.getStableDev(); break;
case LABEL_LATEST_DEV: endpointConfig = FirefoxAccountEndpointConfig.getLatestDev(); break;
case LABEL_STAGE: endpointConfig = FirefoxAccountEndpointConfig.getStage(); break;
case LABEL_PRODUCTION: endpointConfig = FirefoxAccountEndpointConfig.getProduction(); break;
default: throw new FailedToLoadSessionException("unable to restore account - unknown endpoint label: " + endpointConfigLabel);
}
final String email = sharedPrefs.getString(KEY_EMAIL, null);
final String uid = sharedPrefs.getString(KEY_UID, null);
final FirefoxAccount firefoxAccount = new FirefoxAccount(email, uid, state, endpointConfig);
final String applicationName = sharedPrefs.getString(KEY_APPLICATION_NAME, null);
return new FirefoxAccountSession(firefoxAccount, applicationName);
}
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:37,代码来源:FirefoxAccountSessionSharedPrefsStore.java
示例12: getAndDecryptRecord
import org.mozilla.gecko.sync.NonObjectJSONException; //导入依赖的package包/类
private static <R> R getAndDecryptRecord(final RecordFactory recordFactory, final KeyBundle keyBundle,
final JSONObject json) throws NonObjectJSONException, IOException, CryptoException, JSONException {
final Record recordToWrap = new HistoryRecord(json.getString("id")); // Not the most correct but this can be any record since we just init id.
final CryptoRecord cryptoRecord = new CryptoRecord(recordToWrap);
cryptoRecord.payload = new ExtendedJSONObject(json.getString("payload"));
cryptoRecord.setKeyBundle(keyBundle);
cryptoRecord.decrypt();
return (R) recordFactory.createRecord(cryptoRecord); // We should rm this cast. To save time, I didn't generify RecordFactory.
}
示例13: createFromParcel
import org.mozilla.gecko.sync.NonObjectJSONException; //导入依赖的package包/类
@Override
public FirefoxAccount createFromParcel(final Parcel source) {
final String email = source.readString();
final String uid = source.readString();
final State.StateLabel stateLabel = State.StateLabel.valueOf(source.readString());
final State state;
try {
state = StateFactory.fromJSONObject(stateLabel, new ExtendedJSONObject(source.readString()));
} catch (final InvalidKeySpecException | NoSuchAlgorithmException | NonObjectJSONException | IOException e) {
throw new IllegalStateException("Parcelled state JSON should be retrievable");
}
final FirefoxAccountEndpointConfig endpointConfig = FirefoxAccountEndpointConfig.CREATOR.createFromParcel(source);
return new FirefoxAccount(email, uid, state, endpointConfig);
}
示例14: fromJSONObject
import org.mozilla.gecko.sync.NonObjectJSONException; //导入依赖的package包/类
public static BrowserIDKeyPair fromJSONObject(ExtendedJSONObject o) throws InvalidKeySpecException, NoSuchAlgorithmException {
try {
ExtendedJSONObject privateKey = o.getObject(BrowserIDKeyPair.JSON_KEY_PRIVATEKEY);
ExtendedJSONObject publicKey = o.getObject(BrowserIDKeyPair.JSON_KEY_PUBLICKEY);
if (privateKey == null) {
throw new InvalidKeySpecException("privateKey must not be null");
}
if (publicKey == null) {
throw new InvalidKeySpecException("publicKey must not be null");
}
return new BrowserIDKeyPair(createPrivateKey(privateKey), createPublicKey(publicKey));
} catch (NonObjectJSONException e) {
throw new InvalidKeySpecException("privateKey and publicKey must be JSON objects");
}
}
示例15: getCertificatePayloadString
import org.mozilla.gecko.sync.NonObjectJSONException; //导入依赖的package包/类
protected static String getCertificatePayloadString(VerifyingPublicKey publicKeyToSign, String email) throws NonObjectJSONException, IOException {
ExtendedJSONObject payload = new ExtendedJSONObject();
ExtendedJSONObject principal = new ExtendedJSONObject();
principal.put("email", email);
payload.put("principal", principal);
payload.put("public-key", publicKeyToSign.toJSONObject());
return payload.toJSONString();
}