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


Java JsonReader.close方法代码示例

本文整理汇总了Java中javax.json.JsonReader.close方法的典型用法代码示例。如果您正苦于以下问题:Java JsonReader.close方法的具体用法?Java JsonReader.close怎么用?Java JsonReader.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.json.JsonReader的用法示例。


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

示例1: readMessages

import javax.json.JsonReader; //导入方法依赖的package包/类
private JsonArray readMessages(JsonReader reader) throws Exception {
           JsonArrayBuilder b = Json.createArrayBuilder();
           JsonObject obj;
                   try{
           obj = reader.readObject();
           } finally {
               reader.close();
           }
           obj.entrySet().forEach(e -> 
           {
               Message msg=new Message();
               JsonObject m;
               m = msg.generate(e.getValue().toString(), "@id", "http://inbox.rerum.io/id/" + e.getKey() + "");
               if(MOTIVATION.length()==0 || MOTIVATION.contains(m.getJsonString("motivation").toString())){
                   b.add(m);
               }
               });
           JsonArray messages = b.build();
           return messages;
}
 
开发者ID:CenterForDigitalHumanities,项目名称:inbox,代码行数:21,代码来源:MessagesResource.java

示例2: doPost

import javax.json.JsonReader; //导入方法依赖的package包/类
/**
 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
 */
protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {

  JsonReader jsonReader = null;
  JsonObject jsonObject = null;
  try {
    jsonReader = Json.createReader(request.getReader());
    jsonObject = jsonReader.readObject();
    if (log.isDebugEnabled())
      log.debug("in->jsonObject: " + jsonObject);
    System.out.println("Json object data->"+jsonObject);
    DataCenterQueueManager.getInstance().queue.put(jsonObject);
  } catch (JsonException | IllegalStateException | InterruptedException e) {
    log.error("adding to queue", e);
  } finally {
    if (jsonReader != null)
      jsonReader.close();
  }
}
 
开发者ID:webrtc,项目名称:KITE,代码行数:23,代码来源:DataCenterServlet.java

示例3: postMessage

import javax.json.JsonReader; //导入方法依赖的package包/类
private JsonObject postMessage(JsonObject content) throws Exception {
        URL noteUrl = new URL("https://rerum-inbox.firebaseio.com/messages.json");
        HttpURLConnection conn = (HttpURLConnection) noteUrl.openConnection();
        conn.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
        
conn.setDoOutput(true);
conn.setDoInput(true);
        OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
        wr.write(content.toString());
        wr.close();
        
        StringBuilder response;
        try (BufferedReader in = new BufferedReader(
                new InputStreamReader(conn.getInputStream()))) {
            String inputLine;
            response = new StringBuilder();
            while ((inputLine = in.readLine()) != null) {
                response.append(inputLine);
            }
            in.close();
        } 
        JsonReader reader = Json.createReader(new StringReader(response.toString()));
        JsonObject source = reader.readObject();
        Logger.getLogger(Message.class.getName()).log(Level.INFO, "Created: "+source.getJsonString("name").toString());
        reader.close();
        return source;
    }
 
开发者ID:CenterForDigitalHumanities,项目名称:inbox,代码行数:28,代码来源:MessagesResource.java

示例4: verify

import javax.json.JsonReader; //导入方法依赖的package包/类
@Override
public void verify(String gRecaptchaResponse) throws RecaptchaException {
	if (gRecaptchaResponse == null || "".equals(gRecaptchaResponse)) {
		throw new RecaptchaException("Recapcha failed");
	}

	try {
		URL obj = new URL(url);
		HttpsURLConnection con = (HttpsURLConnection) obj.openConnection();

		// add request header
		con.setRequestMethod("POST");
		con.setRequestProperty("User-Agent", USER_AGENT);
		con.setRequestProperty("Accept-Language", "en-US,en;q=0.5");

		String postParams = "secret=" + secret + "&response="
				+ gRecaptchaResponse;

		// Send post request
		con.setDoOutput(true);
		DataOutputStream wr = new DataOutputStream(con.getOutputStream());
		wr.writeBytes(postParams);
		wr.flush();
		wr.close();

		int responseCode = con.getResponseCode();
		System.out.println("\nSending 'POST' request to URL : " + url);
		System.out.println("Post parameters : " + postParams);
		System.out.println("Response Code : " + responseCode);

		BufferedReader in = new BufferedReader(new InputStreamReader(
				con.getInputStream()));
		String inputLine;
		StringBuffer response = new StringBuffer();

		while ((inputLine = in.readLine()) != null) {
			response.append(inputLine);
		}
		in.close();

		// print result
		System.out.println(response.toString());

		//parse JSON response and return 'success' value
		JsonReader jsonReader = Json.createReader(new StringReader(response.toString()));
		JsonObject jsonObject = jsonReader.readObject();
		jsonReader.close();

		if (!jsonObject.getBoolean("success")) {
			throw new RecaptchaException("Recapcha failed");
		}

	} catch (Exception e) {
		throw new RecaptchaException("Recaptcha failed", e);
	}
}
 
开发者ID:howma03,项目名称:sporticus,代码行数:57,代码来源:ServiceRecapchaImpl.java

示例5: loadJsonString

import javax.json.JsonReader; //导入方法依赖的package包/类
public JsonObject loadJsonString(){

        JsonReader jsonReader = Json.createReader(new StringReader(JSON));
        JsonObject jsonObject = jsonReader.readObject();
        jsonReader.close();

        return jsonObject;
    }
 
开发者ID:readlearncode,项目名称:JSON-Processing-with-Java-EE,代码行数:9,代码来源:ObjectExample1.java

示例6: stringToJsonObj

import javax.json.JsonReader; //导入方法依赖的package包/类
private JsonObject stringToJsonObj(String input) {
  try {
    JsonReader jsonReader = Json.createReader(new StringReader(input));
    JsonObject output = jsonReader.readObject();
    jsonReader.close();
    return output;
  } catch (JsonParsingException e) {
    return null;
  }
}
 
开发者ID:OpenLiberty,项目名称:sample-acmegifts,代码行数:11,代码来源:Orchestrator.java

示例7: stringToJsonObj

import javax.json.JsonReader; //导入方法依赖的package包/类
public static JsonObject stringToJsonObj(String input) {
  try {
    JsonReader jsonReader = Json.createReader(new StringReader(input));
    JsonObject output = jsonReader.readObject();
    jsonReader.close();
    return output;
  } catch (JsonParsingException e) {
    return null;
  }
}
 
开发者ID:OpenLiberty,项目名称:sample-acmegifts,代码行数:11,代码来源:Group.java

示例8: createBinary

import javax.json.JsonReader; //导入方法依赖的package包/类
/**
 * Create a binary from a collection of uploaded parts.
 *
 * <p>Note: The structure should be like this:</p>
 * <pre>{
 *   "1": "somehash",
 *   "2": "otherhash",
 *   "3": "anotherhash"
 * }</pre>
 *
 * @param id the identifier
 * @param input the input value
 * @return a response
 */
@POST
@Timed
@Consumes("application/json")
public Response createBinary(@PathParam("id") final String id, final InputStream input) {

    final JsonReader reader = Json.createReader(input);
    final JsonObject obj = reader.readObject();
    reader.close();
    final Map<Integer, String> partDigests = obj.keySet().stream()
        .collect(toMap(Integer::parseInt, obj::getString));

    if (!binaryService.uploadSessionExists(id)) {
        throw new NotFoundException();
    }

    final BinaryService.MultipartUpload upload = binaryService.completeUpload(id, partDigests);

    try (final TrellisDataset dataset = TrellisDataset.createDataset()) {
        final IRI identifier = rdf.createIRI(TRELLIS_PREFIX + upload.getPath());

        // Add Audit quads
        audit.creation(identifier, upload.getSession()).stream()
            .map(skolemizeQuads(resourceService, upload.getBaseUrl())).forEachOrdered(dataset::add);
        dataset.add(rdf.createQuad(PreferServerManaged, identifier, type, NonRDFSource));
        dataset.add(rdf.createQuad(PreferServerManaged, identifier, DC.hasPart,
                    upload.getBinary().getIdentifier()));
        dataset.add(rdf.createQuad(PreferServerManaged, upload.getBinary().getIdentifier(), DC.format,
                    rdf.createLiteral(upload.getBinary().getMimeType().orElse(APPLICATION_OCTET_STREAM))));
        upload.getBinary().getSize().ifPresent(size -> dataset.add(rdf.createQuad(PreferServerManaged,
                        upload.getBinary().getIdentifier(), DC.extent,
                        rdf.createLiteral(size.toString(), XSD.long_))));

        if (resourceService.put(identifier, NonRDFSource, dataset.asDataset()).get()) {
            return created(create(upload.getBaseUrl() + upload.getPath())).build();
        }
    } catch (final InterruptedException | ExecutionException ex) {
        LOGGER.error("Error persisting data: {}", ex.getMessage());
    }
    LOGGER.error("Could not persist data");
    return serverError().entity("Could not persist data internally").build();
}
 
开发者ID:trellis-ldp,项目名称:trellis,代码行数:56,代码来源:MultipartUploader.java

示例9: generate

import javax.json.JsonReader; //导入方法依赖的package包/类
/**
 *
 * @param parsable
 * @param key
 * @param value
 * @return
 */
public JsonObject generate(String parsable, String key, String value) {
    JsonReader reader = Json.createReader(new StringReader(parsable));
    JsonObject source = reader.readObject();
    reader.close();
    return generate(source, key, value);
}
 
开发者ID:CenterForDigitalHumanities,项目名称:inbox,代码行数:14,代码来源:Message.java


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