Package com.google.gson

Examples of com.google.gson.JsonElement


        pivotSpecification.addColumnSplit("has_boris", "is_true", "is_false");

        Assert.assertEquals(1, pivotSpecification.getColumnSplits().size());
        for (PivotColumnSplit prs : pivotSpecification.getColumnSplits()) {
            Assert.assertTrue(prs instanceof BooleanPivotColumnSplit);
            JsonElement obj = prs.toJson();

            Assert.assertTrue(obj instanceof JsonObject);
            JsonObject o = (JsonObject)obj;

            JsonObject expected = new JsonObject();
View Full Code Here


            double choice = r.nextDouble();
            try { // Super catch-all to ensure the launcher always renders
                try {
                    // Fetch the percentage json first
                    String json = IOUtils.toString(new URL(Locations.masterRepo + "/FTB2/static/balance.json"));
                    JsonElement element = new JsonParser().parse(json);

                    if (element != null && element.isJsonObject()) {
                        JsonObject jso = element.getAsJsonObject();
                        if (jso != null && jso.get("minUsableLauncherVersion") != null) {
                            LaunchFrame.getInstance().minUsable = jso.get("minUsableLauncherVersion").getAsInt();
                        }
                        if (jso != null && jso.get("chEnabled") != null) {
                            Locations.chEnabled = jso.get("chEnabled").getAsBoolean();
                        }
                        if (jso != null && jso.get("repoSplitCurse") != null) {
                            JsonElement e = jso.get("repoSplitCurse");
                            Logger.logDebug("Balance Settings: " + e.getAsDouble() + " > " + choice);
                            if (e != null && e.getAsDouble() > choice) {
                                Logger.logInfo("Balance has selected Automatic:CurseCDN");
                            } else {
                                Logger.logInfo("Balance has selected Automatic:CreeperRepo");
                                Locations.masterRepoNoHTTP = Locations.chRepo.replaceAll("http://", "");
                                Locations.masterRepo = Locations.chRepo;
                                Locations.primaryCH = true;
                                downloadServers.remove("Automatic");
                                downloadServers.put("Automatic", Locations.masterRepoNoHTTP);
                            }
                        }
                    }
                    Benchmark.logBenchAs("DlUtils", "Download Utils Bal");
                    if (Locations.chEnabled) {
                        // Fetch servers from creeperhost using edges.json first
                        parseJSONtoMap(new URL(Locations.chRepo + "/edges.json"), "CH", downloadServers, false, "edges.json");
                        Benchmark.logBenchAs("DlUtils", "Download Utils CH");
                    }
                    // Fetch servers list from curse using edges.json second
                    parseJSONtoMap(new URL(Locations.curseRepo + "/edges.json"), "Curse", downloadServers, false, "edges.json");
                    Benchmark.logBenchAs("DlUtils", "Download Utils Curse");
                } catch (IOException e) {
                    int i = 10;

                    // If fetching edges.json failed, assume new. is inaccessible
                    // Try alternate mirrors from the cached server list in resources
                    downloadServers.clear();

                    Logger.logInfo("Primary mirror failed, Trying alternative mirrors");
                    parseJSONtoMap(this.getClass().getResource("/edges.json"), "Backup", downloadServers, true, "edges.json");
                }

                if (downloadServers.size() == 0) {
                    Logger.logError("Could not find any working mirrors! If you are running a software firewall please allow the FTB Launcher permission to use the internet.");

                    // Fall back to new. (old system) on critical failure
                    downloadServers.put("Automatic", Locations.masterRepoNoHTTP);
                } else if (!downloadServers.containsKey("Automatic")) {
                    // Use a random server from edges.json as the Automatic server
                    int index = (int) (Math.random() * downloadServers.size());
                    List<String> keys = Lists.newArrayList(downloadServers.keySet());
                    String defaultServer = downloadServers.get(keys.get(index));
                    downloadServers.put("Automatic", defaultServer);
                    Logger.logInfo("Selected " + keys.get(index) + " mirror for Automatic assignment");
                }
            } catch (Exception e) {
                Logger.logError("Error while selecting server", e);
                downloadServers.clear();
                downloadServers.put("Automatic", Locations.masterRepoNoHTTP);
            }

            Locations.serversLoaded = true;

            // This line absolutely must be hit, or the console will not be shown
            // and the user/we will not even know why an error has occurred.
            Logger.logInfo("DL ready");

            String selectedMirror = Settings.getSettings().getDownloadServer();
            String selectedHost = downloadServers.get(selectedMirror);
            String resolvedIP = "UNKNOWN";
            String resolvedHost = "UNKNOWN";
            String resolvedMirror = "UNKNOWN";

            try {
                InetAddress ipAddress = InetAddress.getByName(selectedHost);
                resolvedIP = ipAddress.getHostAddress();
            } catch (UnknownHostException e) {
                Logger.logError("Failed to resolve selected mirror: " + e.getMessage());
            }

            try {
                for (String key : downloadServers.keySet()) {
                    if (key.equals("Automatic")) {
                        continue;
                    }

                    InetAddress host = InetAddress.getByName(downloadServers.get(key));

                    if (resolvedIP.equalsIgnoreCase(host.getHostAddress())) {
                        resolvedMirror = key;
                        resolvedHost = downloadServers.get(key);
                        break;
                    }
                }
            } catch (UnknownHostException e) {
                Logger.logError("Failed to resolve mirror: " + e.getMessage());
            }

            Logger.logInfo("Using download server " + selectedMirror + ":" + resolvedMirror + " on host " + resolvedHost + " (" + resolvedIP + ")");
            Benchmark.logBenchAs("DlUtils", "Download Utils Init");
        }
View Full Code Here

     */
    @NonNull
    public void parseJSONtoMap (URL u, String name, HashMap<String, String> h, boolean testEntries, String location) {
        try {
            String json = IOUtils.toString(u);
            JsonElement element = new JsonParser().parse(json);
            int i = 10;
            if (element.isJsonObject()) {
                JsonObject jso = element.getAsJsonObject();
                for (Entry<String, JsonElement> e : jso.entrySet()) {
                    if (testEntries) {
                        try {
                            Logger.logInfo("Testing Server:" + e.getKey());
                            //test that the server will properly handle file DL's if it doesn't throw an error the web daemon should be functional
View Full Code Here

        }
        try {
            if (parser.hasNext() == false) {
                return null;
            }
            JsonElement element = parser.next();
            return JsonObjectDriver.convert(definition, element);
        } catch (JsonParseException e) {
            throw new IOException(MessageFormat.format(
                    "Malformed JSON object (id={0})",
                    id), e);
View Full Code Here

    private JsonElement property(JsonObject context, PropertyName name) {
        assert context != null;
        assert name != null;
        String jsName = toJsName(name);
        JsonElement element = context.get(jsName);
        return element;
    }
View Full Code Here

        return buf.toString();
    }

    @Override
    public void booleanProperty(PropertyName name, JsonObject context) throws IOException {
        JsonElement prop = property(context, name);
        if (prop == null) {
            return;
        }
        builder.add(name, prop.getAsBoolean());
    }
View Full Code Here

        builder.add(name, prop.getAsBoolean());
    }

    @Override
    public void byteProperty(PropertyName name, JsonObject context) throws IOException {
        JsonElement prop = property(context, name);
        if (prop == null) {
            return;
        }
        builder.add(name, prop.getAsByte());
    }
View Full Code Here

        builder.add(name, prop.getAsByte());
    }

    @Override
    public void shortProperty(PropertyName name, JsonObject context) throws IOException {
        JsonElement prop = property(context, name);
        if (prop == null) {
            return;
        }
        builder.add(name, prop.getAsShort());
    }
View Full Code Here

        builder.add(name, prop.getAsShort());
    }

    @Override
    public void intProperty(PropertyName name, JsonObject context) throws IOException {
        JsonElement prop = property(context, name);
        if (prop == null) {
            return;
        }
        builder.add(name, prop.getAsInt());
    }
View Full Code Here

        builder.add(name, prop.getAsInt());
    }

    @Override
    public void longProperty(PropertyName name, JsonObject context) throws IOException {
        JsonElement prop = property(context, name);
        if (prop == null) {
            return;
        }
        builder.add(name, prop.getAsLong());
    }
View Full Code Here

TOP

Related Classes of com.google.gson.JsonElement

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.