• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java JsonUtil类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中cn.nukkit.timings.JsonUtil的典型用法代码示例。如果您正苦于以下问题:Java JsonUtil类的具体用法?Java JsonUtil怎么用?Java JsonUtil使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



JsonUtil类属于cn.nukkit.timings包,在下文中一共展示了JsonUtil类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: export

import cn.nukkit.timings.JsonUtil; //导入依赖的package包/类
JsonObject export() {
    JsonObject json = new JsonObject();
    json.addProperty("s", this.startTime);
    json.addProperty("e", this.endTime);
    json.addProperty("tk", this.totalTicks);
    json.addProperty("tm", this.totalTime);
    json.add("w", this.levels);
    json.add("h", JsonUtil.mapToArray(this.entries, (entry) -> {
        if (entry.data.count == 0) {
            return null;
        }
        return entry.export();
    }));
    json.add("mp", JsonUtil.mapToArray(this.minuteReports, MinuteReport::export));
    return json;
}
 
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:17,代码来源:TimingsHistory.java


示例2: run

import cn.nukkit.timings.JsonUtil; //导入依赖的package包/类
@Override
public void run() {
    this.sender.sendMessage(new TranslationContainer("nukkit.command.timings.uploadStart"));
    this.out.add("data", JsonUtil.mapToArray(this.history, TimingsHistory::export));

    String response = null;
    try {
        HttpURLConnection con = (HttpURLConnection) new URL("http://timings.aikar.co/post").openConnection();
        con.setDoOutput(true);
        con.setRequestProperty("User-Agent", "Nukkit/" + Server.getInstance().getName() + "/" + InetAddress.getLocalHost().getHostName());
        con.setRequestMethod("POST");
        con.setInstanceFollowRedirects(false);

        OutputStream request = new GZIPOutputStream(con.getOutputStream()) {
            {
                this.def.setLevel(7);
            }
        };

        request.write(new Gson().toJson(this.out).getBytes("UTF-8"));
        request.close();

        response = getResponse(con);

        if (con.getResponseCode() != 302) {
            this.sender.sendMessage(new TranslationContainer("nukkit.command.timings.uploadError", new String[]{String.valueOf(con.getResponseCode()), con.getResponseMessage()}));
            if (response != null) {
                Server.getInstance().getLogger().alert(response);
            }
            return;
        }

        String location = con.getHeaderField("Location");
        this.sender.sendMessage(new TranslationContainer("nukkit.command.timings.timingsLocation", location));
        if (!(this.sender instanceof ConsoleCommandSender)) {
            Server.getInstance().getLogger().info(Server.getInstance().getLanguage().translateString("nukkit.command.timings.timingsLocation", location));
        }

        if (response != null && !response.isEmpty()) {
            Server.getInstance().getLogger().info(Server.getInstance().getLanguage().translateString("nukkit.command.timings.timingsResponse", response));
        }

        File timingFolder = new File(Server.getInstance().getDataPath() + File.separator + "timings");
        timingFolder.mkdirs();
        String fileName = timingFolder + File.separator + new SimpleDateFormat("'timings-'yyyy-MM-dd-hh-mm'.txt'").format(new Date());

        FileWriter writer = new FileWriter(fileName);
        writer.write(Server.getInstance().getLanguage().translateString("nukkit.command.timings.timingsLocation", location) + "\n\n");
        writer.write(new GsonBuilder().setPrettyPrinting().create().toJson(this.out));
        writer.close();

        Server.getInstance().getLogger().info(Server.getInstance().getLanguage().translateString("nukkit.command.timings.timingsWrite", fileName));
    } catch (IOException exception) {
        this.sender.sendMessage(TextFormat.RED + "" + new TranslationContainer("nukkit.command.timings.reportError"));
        if (response != null) {
            Server.getInstance().getLogger().alert(response);
        }
        Server.getInstance().getLogger().logException(exception);
    }
}
 
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:61,代码来源:TimingsExport.java


示例3: export

import cn.nukkit.timings.JsonUtil; //导入依赖的package包/类
JsonArray export() {
    JsonArray json = JsonUtil.toArray(this.id, this.count, this.totalTime);
    if (this.lagCount > 0) {
        json.add(this.lagCount);
        json.add(this.lagTotalTime);
    }
    return json;
}
 
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:9,代码来源:TimingData.java


示例4: TimingsHistory

import cn.nukkit.timings.JsonUtil; //导入依赖的package包/类
TimingsHistory() {
    this.endTime = System.currentTimeMillis() / 1000;
    this.startTime = TimingsManager.historyStart / 1000;

    if (timedTicks % 1200 != 0 || MINUTE_REPORTS.isEmpty()) {
        this.minuteReports = MINUTE_REPORTS.toArray(new MinuteReport[MINUTE_REPORTS.size() + 1]);
        this.minuteReports[this.minuteReports.length - 1] = new MinuteReport();
    } else {
        this.minuteReports = MINUTE_REPORTS.toArray(new MinuteReport[MINUTE_REPORTS.size()]);
    }

    long ticks = 0;
    for (MinuteReport mr : this.minuteReports) {
        ticks += mr.ticksRecord.timed;
    }

    this.totalTicks = ticks;
    this.totalTime = fullServerTickTimer.record.totalTime;
    this.entries = new TimingsHistoryEntry[TimingsManager.TIMINGS.size()];

    int i = 0;
    for (Timing timing : TimingsManager.TIMINGS) {
        this.entries[i++] = new TimingsHistoryEntry(timing);
    }

    final Map<Integer, AtomicInteger> entityCounts = new HashMap<>();
    final Map<Integer, AtomicInteger> blockEntityCounts = new HashMap<>();
    final Gson GSON = new Gson();
    // Information about all loaded entities/block entities
    for (Level level : Server.getInstance().getLevels().values()) {
        JsonArray jsonLevel = new JsonArray();
        for (BaseFullChunk chunk : level.getChunks().values()) {
            entityCounts.clear();
            blockEntityCounts.clear();

            //count entities
            for (Entity entity : chunk.getEntities().values()) {
                if (!entityCounts.containsKey(entity.getNetworkId()))
                    entityCounts.put(entity.getNetworkId(), new AtomicInteger(0));
                entityCounts.get(entity.getNetworkId()).incrementAndGet();
                entityMap.put(entity.getNetworkId(), entity.getClass().getSimpleName());
            }

            //count block entities
            for (BlockEntity blockEntity : chunk.getBlockEntities().values()) {
                if (!blockEntityCounts.containsKey(blockEntity.getBlock().getId()))
                    blockEntityCounts.put(blockEntity.getBlock().getId(), new AtomicInteger(0));
                blockEntityCounts.get(blockEntity.getBlock().getId()).incrementAndGet();
                blockEntityMap.put(blockEntity.getBlock().getId(), blockEntity.getClass().getSimpleName());
            }

            if (blockEntityCounts.isEmpty() && entityCounts.isEmpty()) {
                continue;
            }

            JsonArray jsonChunk = new JsonArray();
            jsonChunk.add(chunk.getX());
            jsonChunk.add(chunk.getZ());
            jsonChunk.add(GSON.toJsonTree(JsonUtil.mapToObject(entityCounts.entrySet(), (entry) -> new JsonUtil.JSONPair(entry.getKey(), entry.getValue().get()))).getAsJsonObject());
            jsonChunk.add(GSON.toJsonTree(JsonUtil.mapToObject(blockEntityCounts.entrySet(), (entry) -> new JsonUtil.JSONPair(entry.getKey(), entry.getValue().get()))).getAsJsonObject());
            jsonLevel.add(jsonChunk);
        }

        if (!levelMap.containsKey(level.getName())) levelMap.put(level.getName(), levelIdPool++);
        levels.add(String.valueOf(levelMap.get(level.getName())), jsonLevel);
    }
}
 
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:68,代码来源:TimingsHistory.java


示例5: export

import cn.nukkit.timings.JsonUtil; //导入依赖的package包/类
JsonArray export() {
    JsonArray json = this.data.export();
    if (this.children.length > 0) json.add(JsonUtil.mapToArray(this.children, TimingData::export));
    return json;
}
 
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:6,代码来源:TimingsHistoryEntry.java



注:本文中的cn.nukkit.timings.JsonUtil类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java StringVector类代码示例发布时间:2022-05-22
下一篇:
Java Series类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap