当前位置: 首页>>代码示例>>Java>>正文


Java JSONStreamAware类代码示例

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


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

示例1: processPendingResponses

import org.json.simple.JSONStreamAware; //导入依赖的package包/类
synchronized void processPendingResponses(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    JSONArray responses = new JSONArray();
    JSONStreamAware pendingResponse;
    while ((pendingResponse = pendingResponses.poll()) != null) {
        responses.add(pendingResponse);
    }
    if (responses.size() > 0) {
        JSONObject combinedResponse = new JSONObject();
        combinedResponse.put("responses", responses);
        if (asyncContext != null) {
            asyncContext.getResponse().setContentType("text/plain; charset=UTF-8");
            try (Writer writer = asyncContext.getResponse().getWriter()) {
                combinedResponse.writeJSONString(writer);
            }
            asyncContext.complete();
            asyncContext = req.startAsync();
            asyncContext.addListener(new UserAsyncListener());
            asyncContext.setTimeout(5000);
        } else {
            resp.setContentType("text/plain; charset=UTF-8");
            try (Writer writer = resp.getWriter()) {
                combinedResponse.writeJSONString(writer);
            }
        }
    } else {
        if (asyncContext != null) {
            asyncContext.getResponse().setContentType("text/plain; charset=UTF-8");
            try (Writer writer = asyncContext.getResponse().getWriter()) {
                JSON.emptyJSON.writeJSONString(writer);
            }
            asyncContext.complete();
        }
        asyncContext = req.startAsync();
        asyncContext.addListener(new UserAsyncListener());
        asyncContext.setTimeout(5000);
    }
}
 
开发者ID:muhatzg,项目名称:burstcoin,代码行数:38,代码来源:User.java

示例2: processRequest

import org.json.simple.JSONStreamAware; //导入依赖的package包/类
@Override
JSONStreamAware processRequest(HttpServletRequest req) throws NxtException {

    DigitalGoodsStore.Purchase purchase = ParameterParser.getPurchase(req);

    Account buyerAccount = ParameterParser.getSenderAccount(req);
    if (buyerAccount.getId() != purchase.getBuyerId()) {
        return INCORRECT_PURCHASE;
    }
    if (purchase.getEncryptedGoods() == null) {
        return GOODS_NOT_DELIVERED;
    }

    Account sellerAccount = Account.getAccount(purchase.getSellerId());
    Attachment attachment = new Attachment.DigitalGoodsFeedback(purchase.getId());
    return createTransaction(req, buyerAccount, sellerAccount.getId(), 0, attachment);
}
 
开发者ID:muhatzg,项目名称:burstcoin,代码行数:18,代码来源:DGSFeedback.java

示例3: processRequest

import org.json.simple.JSONStreamAware; //导入依赖的package包/类
@Override
JSONStreamAware processRequest(JSONObject request, Peer peer) {

    try {

        if (! Nxt.getBlockchain().getLastBlock().getStringId().equals(request.get("previousBlock"))) {
            // do this check first to avoid validation failures of future blocks and transactions
            // when loading blockchain from scratch
            return NOT_ACCEPTED;
        }
        Nxt.getBlockchainProcessor().processPeerBlock(request);
        return ACCEPTED;

    } catch (NxtException|RuntimeException e) {
        if (peer != null) {
            peer.blacklist(e);
        }
        return NOT_ACCEPTED;
    }

}
 
开发者ID:muhatzg,项目名称:burstcoin,代码行数:22,代码来源:ProcessBlock.java

示例4: processRequest

import org.json.simple.JSONStreamAware; //导入依赖的package包/类
@Override
JSONStreamAware processRequest(HttpServletRequest req) {

    int firstIndex = ParameterParser.getFirstIndex(req);
    int lastIndex = ParameterParser.getLastIndex(req);

    JSONArray pollIds = new JSONArray();
    try (DbIterator<Poll> polls = Poll.getAllPolls(firstIndex, lastIndex)) {
        while (polls.hasNext()) {
            pollIds.add(Convert.toUnsignedLong(polls.next().getId()));
        }
    }
    JSONObject response = new JSONObject();
    response.put("pollIds", pollIds);
    return response;

}
 
开发者ID:muhatzg,项目名称:burstcoin,代码行数:18,代码来源:GetPollIds.java

示例5: processRequest

import org.json.simple.JSONStreamAware; //导入依赖的package包/类
@Override
JSONStreamAware processRequest(HttpServletRequest req) {
    JSONObject response = new JSONObject();
    response.put("application", Nxt.APPLICATION);
    response.put("version", Nxt.VERSION);
    response.put("time", Nxt.getEpochTime());
    Block lastBlock = Nxt.getBlockchain().getLastBlock();
    response.put("lastBlock", lastBlock.getStringId());
    response.put("cumulativeDifficulty", lastBlock.getCumulativeDifficulty().toString());
    response.put("numberOfBlocks", lastBlock.getHeight() + 1);
    BlockchainProcessor blockchainProcessor = Nxt.getBlockchainProcessor();
    Peer lastBlockchainFeeder = blockchainProcessor.getLastBlockchainFeeder();
    response.put("lastBlockchainFeeder", lastBlockchainFeeder == null ? null : lastBlockchainFeeder.getAnnouncedAddress());
    response.put("lastBlockchainFeederHeight", blockchainProcessor.getLastBlockchainFeederHeight());
    response.put("isScanning", blockchainProcessor.isScanning());
    return response;
}
 
开发者ID:muhatzg,项目名称:burstcoin,代码行数:18,代码来源:GetBlockchainStatus.java

示例6: processRequest

import org.json.simple.JSONStreamAware; //导入依赖的package包/类
@Override
JSONStreamAware processRequest(HttpServletRequest req) throws ParameterException {
    List<Account> accounts = ParameterParser.getAccounts(req);
    int firstIndex = ParameterParser.getFirstIndex(req);
    int lastIndex = ParameterParser.getLastIndex(req);

    JSONObject response = new JSONObject();
    JSONArray accountsJSONArray = new JSONArray();
    response.put("assets", accountsJSONArray);
    for (Account account : accounts) {
        JSONArray assetsJSONArray = new JSONArray();
        try (DbIterator<Asset> assets = Asset.getAssetsIssuedBy(account.getId(), firstIndex, lastIndex)) {
            while (assets.hasNext()) {
                assetsJSONArray.add(JSONData.asset(assets.next()));
            }
        }
        accountsJSONArray.add(assetsJSONArray);
    }
    return response;
}
 
开发者ID:muhatzg,项目名称:burstcoin,代码行数:21,代码来源:GetAssetsByIssuer.java

示例7: processRequest

import org.json.simple.JSONStreamAware; //导入依赖的package包/类
@Override
JSONStreamAware processRequest(HttpServletRequest req) throws NxtException {

    int firstIndex = ParameterParser.getFirstIndex(req);
    int lastIndex = ParameterParser.getLastIndex(req);
    if (lastIndex < 0 || lastIndex - firstIndex > 99) {
        lastIndex = firstIndex + 99;
    }

    boolean includeTransactions = "true".equalsIgnoreCase(req.getParameter("includeTransactions"));

    JSONArray blocks = new JSONArray();
    try (DbIterator<? extends Block> iterator = Nxt.getBlockchain().getBlocks(firstIndex, lastIndex)) {
        while (iterator.hasNext()) {
            Block block = iterator.next();
            blocks.add(JSONData.block(block, includeTransactions));
        }
    }

    JSONObject response = new JSONObject();
    response.put("blocks", blocks);

    return response;
}
 
开发者ID:muhatzg,项目名称:burstcoin,代码行数:25,代码来源:GetBlocks.java

示例8: processRequest

import org.json.simple.JSONStreamAware; //导入依赖的package包/类
@Override
JSONStreamAware processRequest(HttpServletRequest req) {

    int firstIndex = ParameterParser.getFirstIndex(req);
    int lastIndex = ParameterParser.getLastIndex(req);

    JSONObject response = new JSONObject();
    JSONArray assetsJSONArray = new JSONArray();
    response.put("assets", assetsJSONArray);
    try (DbIterator<Asset> assets = Asset.getAllAssets(firstIndex, lastIndex)) {
        while (assets.hasNext()) {
            assetsJSONArray.add(JSONData.asset(assets.next()));
        }
    }
    return response;
}
 
开发者ID:muhatzg,项目名称:burstcoin,代码行数:17,代码来源:GetAllAssets.java

示例9: processRequest

import org.json.simple.JSONStreamAware; //导入依赖的package包/类
@Override
JSONStreamAware processRequest(HttpServletRequest req) {
	JSONObject response = new JSONObject();
	
	response.put("height", Long.toString(Nxt.getBlockchain().getHeight() + 1));
	
	Block lastBlock = Nxt.getBlockchain().getLastBlock();
	byte[] lastGenSig = lastBlock.getGenerationSignature();
	Long lastGenerator = lastBlock.getGeneratorId();
	
	ByteBuffer buf = ByteBuffer.allocate(32 + 8);
	buf.put(lastGenSig);
	buf.putLong(lastGenerator);
	
	Shabal256 md = new Shabal256();
	md.update(buf.array());
	byte[] newGenSig = md.digest();
	
	response.put("generationSignature", Convert.toHexString(newGenSig));
	response.put("baseTarget", Long.toString(lastBlock.getBaseTarget()));
	
	return response;
}
 
开发者ID:muhatzg,项目名称:burstcoin,代码行数:24,代码来源:GetMiningInfo.java

示例10: processRequest

import org.json.simple.JSONStreamAware; //导入依赖的package包/类
@Override
JSONStreamAware processRequest(HttpServletRequest req) throws NxtException {

    String transactionBytes = Convert.emptyToNull(req.getParameter("transactionBytes"));
    String transactionJSON = Convert.emptyToNull(req.getParameter("transactionJSON"));
    Transaction transaction = ParameterParser.parseTransaction(transactionBytes, transactionJSON);
    JSONObject response = JSONData.unconfirmedTransaction(transaction);
    try {
        transaction.validate();
    } catch (NxtException.ValidationException|RuntimeException e) {
        Logger.logDebugMessage(e.getMessage(), e);
        response.put("validate", false);
        response.put("errorCode", 4);
        response.put("errorDescription", "Invalid transaction: " + e.toString());
        response.put("error", e.getMessage());
    }
    response.put("verify", transaction.verifySignature() && transaction.verifyPublicKey());
    return response;
}
 
开发者ID:muhatzg,项目名称:burstcoin,代码行数:20,代码来源:ParseTransaction.java

示例11: processRequest

import org.json.simple.JSONStreamAware; //导入依赖的package包/类
@Override
JSONStreamAware processRequest(HttpServletRequest req) throws NxtException {

    Asset asset = ParameterParser.getAsset(req);
    int firstIndex = ParameterParser.getFirstIndex(req);
    int lastIndex = ParameterParser.getLastIndex(req);
    int height = ParameterParser.getHeight(req);

    JSONArray accountAssets = new JSONArray();
    try (DbIterator<Account.AccountAsset> iterator = asset.getAccounts(height, firstIndex, lastIndex)) {
        while (iterator.hasNext()) {
            Account.AccountAsset accountAsset = iterator.next();
            accountAssets.add(JSONData.accountAsset(accountAsset));
        }
    }

    JSONObject response = new JSONObject();
    response.put("accountAssets", accountAssets);
    return response;

}
 
开发者ID:muhatzg,项目名称:burstcoin,代码行数:22,代码来源:GetAssetAccounts.java

示例12: processRequest

import org.json.simple.JSONStreamAware; //导入依赖的package包/类
@Override
JSONStreamAware processRequest(HttpServletRequest req) {

    JSONObject response = new JSONObject();
    JSONArray ordersData = new JSONArray();

    int firstIndex = ParameterParser.getFirstIndex(req);
    int lastIndex = ParameterParser.getLastIndex(req);

    try (DbIterator<Order.Ask> askOrders = Order.Ask.getAll(firstIndex, lastIndex)) {
        while (askOrders.hasNext()) {
            ordersData.add(JSONData.askOrder(askOrders.next()));
        }
    }

    response.put("openOrders", ordersData);
    return response;
}
 
开发者ID:muhatzg,项目名称:burstcoin,代码行数:19,代码来源:GetAllOpenAskOrders.java

示例13: processRequest

import org.json.simple.JSONStreamAware; //导入依赖的package包/类
@Override
JSONStreamAware processRequest(HttpServletRequest req) throws NxtException {

    Asset asset = ParameterParser.getAsset(req);
    long priceNQT = ParameterParser.getPriceNQT(req);
    long quantityQNT = ParameterParser.getQuantityQNT(req);
    Account account = ParameterParser.getSenderAccount(req);

    long assetBalance = account.getUnconfirmedAssetBalanceQNT(asset.getId());
    if (assetBalance < 0 || quantityQNT > assetBalance) {
        return NOT_ENOUGH_ASSETS;
    }

    Attachment attachment = new Attachment.ColoredCoinsAskOrderPlacement(asset.getId(), quantityQNT, priceNQT);
    return createTransaction(req, account, attachment);

}
 
开发者ID:muhatzg,项目名称:burstcoin,代码行数:18,代码来源:PlaceAskOrder.java

示例14: processRequest

import org.json.simple.JSONStreamAware; //导入依赖的package包/类
@Override
JSONStreamAware processRequest(HttpServletRequest req) throws NxtException {
    final int timestamp = ParameterParser.getTimestamp(req);
    final long accountId = ParameterParser.getAccount(req).getId();
    int firstIndex = ParameterParser.getFirstIndex(req);
    int lastIndex = ParameterParser.getLastIndex(req);

    JSONArray aliases = new JSONArray();
    try (FilteringIterator<Alias> aliasIterator = new FilteringIterator<>(Alias.getAliasesByOwner(accountId, 0, -1),
            new FilteringIterator.Filter<Alias>() {
                @Override
                public boolean ok(Alias alias) {
                    return alias.getTimestamp() >= timestamp;
                }
            }, firstIndex, lastIndex)) {
        while(aliasIterator.hasNext()) {
            aliases.add(JSONData.alias(aliasIterator.next()));
        }
    }

    JSONObject response = new JSONObject();
    response.put("aliases", aliases);
    return response;
}
 
开发者ID:muhatzg,项目名称:burstcoin,代码行数:25,代码来源:GetAliases.java

示例15: processRequest

import org.json.simple.JSONStreamAware; //导入依赖的package包/类
@Override
JSONStreamAware processRequest(HttpServletRequest req) throws NxtException {

    long recipient = ParameterParser.getRecipientId(req);

    Asset asset = ParameterParser.getAsset(req);
    long quantityQNT = ParameterParser.getQuantityQNT(req);
    Account account = ParameterParser.getSenderAccount(req);

    long assetBalance = account.getUnconfirmedAssetBalanceQNT(asset.getId());
    if (assetBalance < 0 || quantityQNT > assetBalance) {
        return NOT_ENOUGH_ASSETS;
    }

    Attachment attachment = new Attachment.ColoredCoinsAssetTransfer(asset.getId(), quantityQNT);
    return createTransaction(req, account, recipient, 0, attachment);

}
 
开发者ID:muhatzg,项目名称:burstcoin,代码行数:19,代码来源:TransferAsset.java


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