當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。