Changeset 13231 in josm for trunk/src/javax/json/Json.java
- Timestamp:
- 2017-12-23T02:40:43+01:00 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/javax/json/Json.java
r6756 r13231 2 2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 3 * 4 * Copyright (c) 2011-201 3Oracle and/or its affiliates. All rights reserved.4 * Copyright (c) 2011-2017 Oracle and/or its affiliates. All rights reserved. 5 5 * 6 6 * The contents of this file are subject to the terms of either the GNU … … 9 9 * may not use this file except in compliance with the License. You can 10 10 * obtain a copy of the License at 11 * https:// glassfish.dev.java.net/public/CDDL+GPL_1_1.html12 * or packager/legal/LICENSE.txt. See the License for the specific11 * https://oss.oracle.com/licenses/CDDL+GPL-1.1 12 * or LICENSE.txt. See the License for the specific 13 13 * language governing permissions and limitations under the License. 14 14 * 15 15 * When distributing the software, include this License Header Notice in each 16 * file and include the License file at packager/legal/LICENSE.txt.16 * file and include the License file at LICENSE.txt. 17 17 * 18 18 * GPL Classpath Exception: … … 41 41 package javax.json; 42 42 43 import java.io.InputStream; 44 import java.io.OutputStream; 45 import java.io.Reader; 46 import java.io.Writer; 47 import java.math.BigDecimal; 48 import java.math.BigInteger; 49 import java.util.Collection; 50 import java.util.Map; 51 import java.util.Optional; 43 52 import javax.json.spi.JsonProvider; 44 53 import javax.json.stream.JsonGenerator; … … 46 55 import javax.json.stream.JsonParser; 47 56 import javax.json.stream.JsonParserFactory; 48 import java.io.*;49 import java.util.Map;50 57 51 58 /** … … 73 80 * All the methods in this class are safe for use by multiple concurrent 74 81 * threads. 75 *76 * @author Jitendra Kotamraju77 82 */ 78 public class Json {83 public final class Json { 79 84 80 85 private Json() { … … 93 98 /** 94 99 * Creates a JSON parser from a byte stream. 95 * The character encoding of the stream is determined as specified in 96 * <a href="http://tools.ietf.org/rfc/rfc 4627.txt">RFC 4627</a>.100 * The character encoding of the stream is determined as specified in 101 * <a href="http://tools.ietf.org/rfc/rfc7159.txt">RFC 7159</a>. 97 102 * 98 103 * @param in i/o stream from which JSON is to be read … … 212 217 * Creates a JSON reader from a byte stream. The character encoding of 213 218 * the stream is determined as described in 214 * <a href="http://tools.ietf.org/rfc/rfc 4627.txt">RFC 4627</a>.219 * <a href="http://tools.ietf.org/rfc/rfc7159.txt">RFC 7159</a>. 215 220 * 216 221 * @param in a byte stream from which JSON is to be read … … 259 264 260 265 /** 266 * Creates a JSON array builder, initialized with the specified array 267 * 268 * @param array the initial array in the builder 269 * @return a JSON array builder 270 * 271 * @since 1.1 272 */ 273 public static JsonArrayBuilder createArrayBuilder(JsonArray array) { 274 return JsonProvider.provider().createArrayBuilder(array); 275 } 276 277 /** 278 * Creates a JSON array builder, initialized with the content of specified {@code collection}. 279 * If the @{code collection} contains {@link Optional}s then resulting JSON array builder 280 * contains the value from the {@code collection} only if the {@link Optional} is not empty. 281 * 282 * @param collection the initial data for the builder 283 * @return a JSON array builder 284 * @exception IllegalArgumentException if the value from the {@code collection} cannot be converted 285 * to the corresponding {@link JsonValue} 286 * 287 * @since 1.1 288 */ 289 public static JsonArrayBuilder createArrayBuilder(Collection<?> collection) { 290 return JsonProvider.provider().createArrayBuilder(collection); 291 } 292 293 /** 261 294 * Creates a JSON object builder 262 295 * … … 265 298 public static JsonObjectBuilder createObjectBuilder() { 266 299 return JsonProvider.provider().createObjectBuilder(); 300 } 301 302 /** 303 * Creates a JSON object builder, initialized with the specified object. 304 * 305 * @param object the initial object in the builder 306 * @return a JSON object builder 307 * 308 * @since 1.1 309 */ 310 public static JsonObjectBuilder createObjectBuilder(JsonObject object) { 311 return JsonProvider.provider().createObjectBuilder(object); 312 } 313 314 /** 315 * Creates a JSON object builder, initialized with the data from specified {@code map}. 316 * If the @{code map} contains {@link Optional}s then resulting JSON object builder 317 * contains the key from the {@code map} only if the {@link Optional} is not empty. 318 * 319 * @param map the initial object in the builder 320 * @return a JSON object builder 321 * @exception IllegalArgumentException if the value from the {@code map} cannot be converted 322 * to the corresponding {@link JsonValue} 323 * 324 * @since 1.1 325 */ 326 public static JsonObjectBuilder createObjectBuilder(Map<String, Object> map) { 327 return JsonProvider.provider().createObjectBuilder(map); 328 } 329 330 /** 331 * Creates JSON Pointer (<a href="http://tools.ietf.org/html/rfc6901">RFC 6901</a>) 332 * from given {@code jsonPointer} string. 333 * <ul> 334 * <li>An empty {@code jsonPointer} string defines a reference to the target itself.</li> 335 * <li>If the {@code jsonPointer} string is non-empty, it must be a sequence of '{@code /}' prefixed tokens.</li> 336 * </ul> 337 * 338 * @param jsonPointer the valid escaped JSON Pointer string 339 * @throws NullPointerException if {@code jsonPointer} is {@code null} 340 * @throws JsonException if {@code jsonPointer} is not a valid JSON Pointer 341 * @return a JSON Pointer 342 * 343 * @since 1.1 344 */ 345 public static JsonPointer createPointer(String jsonPointer) { 346 return JsonProvider.provider().createPointer(jsonPointer); 347 } 348 349 /** 350 * Creates a JSON Patch builder (<a href="http://tools.ietf.org/html/rfc6902">RFC 6902</a>). 351 * 352 * @return a JSON Patch builder 353 * 354 * @since 1.1 355 */ 356 public static JsonPatchBuilder createPatchBuilder() { 357 return JsonProvider.provider().createPatchBuilder(); 358 } 359 360 /** 361 * Creates a JSON Patch builder 362 * (<a href="http://tools.ietf.org/html/rfc6902">RFC 6902</a>), 363 * initialized with the specified operations. 364 * 365 * @param array the initial patch operations 366 * @return a JSON Patch builder 367 * 368 * @since 1.1 369 */ 370 public static JsonPatchBuilder createPatchBuilder(JsonArray array) { 371 return JsonProvider.provider().createPatchBuilder(array); 372 } 373 374 /** 375 * Creates a JSON Patch (<a href="http://tools.ietf.org/html/rfc6902">RFC 6902</a>) 376 * from the specified operations. 377 * 378 * @param array patch operations 379 * @return a JSON Patch 380 * 381 * @since 1.1 382 */ 383 public static JsonPatch createPatch(JsonArray array) { 384 return JsonProvider.provider().createPatch(array); 385 } 386 387 /** 388 * Generates a JSON Patch (<a href="http://tools.ietf.org/html/rfc6902">RFC 6902</a>) 389 * from the source and target {@code JsonStructure}. 390 * The generated JSON Patch need not be unique. 391 * 392 * @param source the source 393 * @param target the target, must be the same type as the source 394 * @return a JSON Patch which when applied to the source, yields the target 395 * 396 * @since 1.1 397 */ 398 public static JsonPatch createDiff(JsonStructure source, JsonStructure target) { 399 return JsonProvider.provider().createDiff(source, target); 400 } 401 402 /** 403 * Creates JSON Merge Patch (<a href="http://tools.ietf.org/html/rfc7396">RFC 7396</a>) 404 * from specified {@code JsonValue}. 405 * 406 * @param patch the patch 407 * @return a JSON Merge Patch 408 * 409 * @since 1.1 410 */ 411 public static JsonMergePatch createMergePatch(JsonValue patch) { 412 return JsonProvider.provider().createMergePatch(patch); 413 } 414 415 /** 416 * Generates a JSON Merge Patch (<a href="http://tools.ietf.org/html/rfc7396">RFC 7396</a>) 417 * from the source and target {@code JsonValue}s 418 * which when applied to the {@code source}, yields the {@code target}. 419 * 420 * @param source the source 421 * @param target the target 422 * @return a JSON Merge Patch 423 * 424 * @since 1.1 425 */ 426 public static JsonMergePatch createMergeDiff(JsonValue source, JsonValue target) { 427 return JsonProvider.provider().createMergeDiff(source, target); 267 428 } 268 429 … … 283 444 } 284 445 446 /** 447 * Creates a JsonString. 448 * 449 * @param value a JSON string 450 * @return the JsonString for the string 451 * 452 * @since 1.1 453 */ 454 public static JsonString createValue(String value) { 455 return JsonProvider.provider().createValue(value); 456 } 457 458 /** 459 * Creates a JsonNumber. 460 * 461 * @param value a JSON number 462 * @return the JsonNumber for the number 463 * 464 * @since 1.1 465 */ 466 public static JsonNumber createValue(int value) { 467 return JsonProvider.provider().createValue(value); 468 } 469 470 /** 471 * Creates a JsonNumber. 472 * 473 * @param value a JSON number 474 * @return the JsonNumber for the number 475 * 476 * @since 1.1 477 */ 478 public static JsonNumber createValue(long value) { 479 return JsonProvider.provider().createValue(value); 480 } 481 482 /** 483 * Creates a JsonNumber. 484 * 485 * @param value a JSON number 486 * @return the JsonNumber for the number 487 * 488 * @since 1.1 489 */ 490 public static JsonNumber createValue(double value) { 491 return JsonProvider.provider().createValue(value); 492 } 493 494 /** 495 * Creates a JsonNumber. 496 * 497 * @param value a JSON number 498 * @return the JsonNumber for the number 499 * 500 * @since 1.1 501 */ 502 public static JsonNumber createValue(BigDecimal value) { 503 return JsonProvider.provider().createValue(value); 504 } 505 506 /** 507 * Creates a JsonNumber. 508 * 509 * @param value a JSON number 510 * @return the JsonNumber for the number 511 * 512 * @since 1.1 513 */ 514 public static JsonNumber createValue(BigInteger value) { 515 return JsonProvider.provider().createValue(value); 516 } 517 518 /** 519 * Encodes (escapes) a passed string as defined by <a href="http://tools.ietf.org/html/rfc6901">RFC 6901</a>. 520 * This method doesn't validate the passed JSON-pointer string. 521 * 522 * @param pointer the JSON-pointer string to encode 523 * @return encoded JSON-pointer string 524 * 525 * @since 1.1 526 */ 527 public static String encodePointer(String pointer) { 528 return pointer.replace("~", "~0").replace("/", "~1"); 529 } 530 531 /** 532 * Decodes a passed JSON-pointer string as defined by <a href="http://tools.ietf.org/html/rfc6901">RFC 6901</a>. 533 * This method doesn't validate the passed JSON-pointer string. 534 * 535 * @param escaped the JSON-pointer string to decode 536 * @return decoded JSON-pointer string 537 * 538 * @since 1.1 539 */ 540 public static String decodePointer(String escaped) { 541 return escaped.replace("~1", "/").replace("~0", "~"); 542 } 543 285 544 }
Note:
See TracChangeset
for help on using the changeset viewer.