Java Code Examples for com.gianlu.commonutils.CommonUtils#optString()

The following examples show how to use com.gianlu.commonutils.CommonUtils#optString() . 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: DownloadWithUpdate.java    From Aria2App with GNU General Public License v3.0 6 votes vote down vote up
BigUpdate(JSONObject obj) throws JSONException {
    super(obj);

    // Optional
    bitfield = CommonUtils.optString(obj, "bitfield");
    verifiedLength = obj.optLong("verifiedLength", 0);
    verifyIntegrityPending = obj.optBoolean("verifyIntegrityPending", false);

    if (isTorrent()) {
        infoHash = obj.getString("infoHash");
        seeder = obj.optBoolean("seeder", false);
    } else {
        seeder = false;
        infoHash = null;
    }
}
 
Example 2
Source File: Domain.java    From DNSHero with GNU General Public License v3.0 5 votes vote down vote up
private Diagnostic(JSONObject obj) throws JSONException {
    JSONObject definition = obj.getJSONObject("definition");
    name = definition.getString("name");
    description = definition.getString("description");
    status = DiagnosticStatus.parse(obj.getString("status"));
    recommendation = CommonUtils.optString(obj, "recommendation");

    JSONObject sourcesObj = obj.getJSONObject("sources");
    sources = new HashMap<>();
    Iterator<String> keys = sourcesObj.keys();
    while (keys.hasNext()) {
        String key = keys.next();
        sources.put(key, sourcesObj.getBoolean(key));
    }
}
 
Example 3
Source File: Torrent.java    From Aria2App with GNU General Public License v3.0 5 votes vote down vote up
public Torrent(JSONObject obj) throws JSONException {
    engineId = obj.getString("engine");
    title = obj.getString("title");
    magnet = obj.getString("magnet");
    torrentFileUrl = CommonUtils.optString(obj, "torrent");
    size = obj.getLong("size");
    seeders = obj.getInt("seeders");
    leeches = obj.getInt("leeches");
}
 
Example 4
Source File: BitTorrent.java    From Aria2App with GNU General Public License v3.0 5 votes vote down vote up
private BitTorrent(@NonNull JSONObject obj) throws JSONException {
    comment = CommonUtils.optString(obj, "comment");
    creationDate = obj.optInt("creationDate", -1);
    mode = Mode.parse(obj.optString("mode"));
    announceList = new ArrayList<>();

    if (obj.has("announceList")) {
        JSONArray array = obj.getJSONArray("announceList");
        for (int i = 0; i < array.length(); i++)
            announceList.add(array.optJSONArray(i).optString(0));
    }

    if (obj.has("info")) name = CommonUtils.optString(obj.getJSONObject("info"), "name");
    else name = null;
}
 
Example 5
Source File: Peer.java    From Aria2App with GNU General Public License v3.0 5 votes vote down vote up
public Peer(JSONObject obj) throws JSONException {
    peerId = CommonUtils.optString(obj, "peerId");
    ip = CommonUtils.optString(obj, "ip");
    port = obj.optInt("port", -1);
    bitfield = CommonUtils.optString(obj, "bitfield");
    amChoking = obj.optBoolean("amChoking", false);
    peerChoking = obj.optBoolean("peerChoking", false);
    downloadSpeed = obj.optInt("downloadSpeed", 0);
    uploadSpeed = obj.optInt("uploadSpeed", 0);
    seeder = obj.optBoolean("seeder", false);
}
 
Example 6
Source File: DownloadWithUpdate.java    From Aria2App with GNU General Public License v3.0 5 votes vote down vote up
SmallUpdate(JSONObject obj) throws JSONException {
    length = obj.getLong("totalLength");
    pieceLength = obj.getLong("pieceLength");
    numPieces = obj.getInt("numPieces");
    dir = obj.getString("dir");
    torrent = BitTorrent.create(obj);

    try {
        status = Status.parse(obj.getString("status"));
    } catch (ParseException ex) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) throw new JSONException(ex);
        else throw new JSONException(ex.getMessage());
    }

    completedLength = obj.getLong("completedLength");
    uploadLength = obj.getLong("uploadLength");
    downloadSpeed = obj.getInt("downloadSpeed");
    uploadSpeed = obj.getInt("uploadSpeed");
    connections = obj.getInt("connections");
    files = new AriaFiles(obj.getJSONArray("files"));

    // Optional
    followedBy = CommonUtils.optString(obj, "followedBy");
    following = CommonUtils.optString(obj, "following");
    belongsTo = CommonUtils.optString(obj, "belongsTo");


    if (isTorrent()) numSeeders = obj.getInt("numSeeders");
    else numSeeders = 0;

    if (obj.has("errorCode")) {
        errorCode = obj.getInt("errorCode");
        errorMessage = CommonUtils.optString(obj, "errorMessage");
    } else {
        errorCode = -1;
        errorMessage = null;
    }
}
 
Example 7
Source File: MultiProfile.java    From Aria2App with GNU General Public License v3.0 5 votes vote down vote up
public DirectDownload(JSONObject obj) throws JSONException {
    address = obj.getString("addr");
    auth = obj.getBoolean("auth");
    username = CommonUtils.optString(obj, "username");
    password = CommonUtils.optString(obj, "password");
    hostnameVerifier = obj.optBoolean("hostnameVerifier", false);
    serverSsl = obj.optBoolean("serverSsl", false);

    String base64 = CommonUtils.optString(obj, "certificate");
    if (base64 == null) certificate = null;
    else certificate = CertUtils.decodeCertificate(base64);
}
 
Example 8
Source File: MultiProfile.java    From Aria2App with GNU General Public License v3.0 5 votes vote down vote up
public UserProfile(@NonNull JSONObject obj, @Nullable ConnectivityCondition condition) throws JSONException {
    if (obj.has("serverAuth"))
        authMethod = AbstractClient.AuthMethod.TOKEN;
    else
        authMethod = AbstractClient.AuthMethod.valueOf(obj.optString("authMethod", "NONE"));

    serverUsername = CommonUtils.optString(obj, "serverUsername");
    serverPassword = CommonUtils.optString(obj, "serverPassword");
    serverToken = CommonUtils.optString(obj, "serverToken");
    serverSsl = obj.optBoolean("serverSsl", false);

    serverAddr = obj.getString("serverAddr");
    serverPort = obj.getInt("serverPort");
    serverEndpoint = obj.getString("serverEndpoint");
    hostnameVerifier = obj.optBoolean("hostnameVerifier", false);

    if (obj.has("directDownload"))
        directDownload = new DirectDownload(obj.getJSONObject("directDownload"));
    else
        directDownload = null;

    connectionMethod = ConnectionMethod.valueOf(obj.optString("connectionMethod", ConnectionMethod.HTTP.name()));

    if (obj.isNull("connectivityCondition")) {
        if (condition != null) connectivityCondition = condition;
        else connectivityCondition = ConnectivityCondition.newUniqueCondition();
    } else {
        connectivityCondition = new ConnectivityCondition(obj.getJSONObject("connectivityCondition"));
    }

    if (obj.isNull("certificatePath")) {
        String base64 = CommonUtils.optString(obj, "certificate");
        if (base64 == null) certificate = null;
        else certificate = CertUtils.decodeCertificate(base64);
    } else {
        certificate = CertUtils.loadCertificateFromFile(obj.getString("certificatePath"));
    }

    status = new TestStatus(Status.UNKNOWN, null);
}
 
Example 9
Source File: PollMessage.java    From PretendYoureXyzzyAndroid with GNU General Public License v3.0 5 votes vote down vote up
private PollMessage(JSONObject obj) throws JSONException {
    event = Event.parse(obj.getString("E"));
    sender = CommonUtils.optString(obj, "f");
    message = CommonUtils.optString(obj, "m");
    gid = obj.optInt("gid", -1);
    timestamp = obj.optLong("ts", -1);
    emote = obj.optBoolean("me", false);
    wall = obj.optBoolean("wall", false);

    this.obj = obj;
}
 
Example 10
Source File: Game.java    From PretendYoureXyzzyAndroid with GNU General Public License v3.0 5 votes vote down vote up
Options(@NonNull JSONObject obj) throws JSONException {
    timerMultiplier = obj.getString("tm");
    spectatorsLimit = obj.getInt("vL");
    playersLimit = obj.getInt("pL");
    scoreLimit = obj.getInt("sl");
    blanksLimit = obj.getInt("bl");
    password = CommonUtils.optString(obj, "pw");

    JSONArray cardsSetsArray = obj.getJSONArray("css");
    cardSets = new ArrayList<>();
    for (int i = 0; i < cardsSetsArray.length(); i++)
        cardSets.add(cardsSetsArray.getInt(i));
}
 
Example 11
Source File: User.java    From PretendYoureXyzzyAndroid with GNU General Public License v3.0 5 votes vote down vote up
public User(@NonNull String sessionId, JSONObject obj) throws JSONException {
    super(obj);
    this.sessionId = sessionId;
    this.persistentId = obj.getString("pid");
    this.userPermalink = CommonUtils.optString(obj, "up");
    this.sessionPermalink = CommonUtils.optString(obj, "sP");
}
 
Example 12
Source File: IPDetails.java    From Aria2App with GNU General Public License v3.0 4 votes vote down vote up
@Nullable
private static String parseStupidNull(@NonNull JSONObject obj, @NonNull String key) throws JSONException {
    String str = CommonUtils.optString(obj, key);
    if (Objects.equals(str, "null")) return null;
    else return str;
}
 
Example 13
Source File: GamePermalink.java    From PretendYoureXyzzyAndroid with GNU General Public License v3.0 4 votes vote down vote up
public GamePermalink(JSONObject obj) throws JSONException {
    this.gid = obj.getInt("gid");
    this.gamePermalink = CommonUtils.optString(obj, "gp");
}
 
Example 14
Source File: GamePermalink.java    From PretendYoureXyzzyAndroid with GNU General Public License v3.0 4 votes vote down vote up
public GamePermalink(int gid, JSONObject obj) {
    this.gid = gid;
    this.gamePermalink = CommonUtils.optString(obj, "gp");
}