示例#1
0
 /**
  * Method for constructing JSON parser instance to parse the contents accessed via specified input
  * stream.
  *
  * <p>The input stream will <b>not be owned</b> by the parser, it will still be managed (i.e.
  * closed if end-of-stream is reacher, or parser close method called) if (and only if) {@link
  * com.fasterxml.jackson.core.JsonParser.Feature#AUTO_CLOSE_SOURCE} is enabled.
  *
  * <p>Note: no encoding argument is taken since it can always be auto-detected as suggested by
  * JSON RFC.
  *
  * @param in InputStream to use for reading JSON content to parse
  * @since 2.1
  */
 public JsonParser createParser(InputStream in) throws IOException, JsonParseException {
   IOContext ctxt = _createContext(in, false);
   // [JACKSON-512]: allow wrapping with InputDecorator
   if (_inputDecorator != null) {
     in = _inputDecorator.decorate(ctxt, in);
   }
   return _createParser(in, ctxt);
 }
示例#2
0
 /**
  * Method for constructing parser for parsing the contents accessed via specified Reader.
  *
  * <p>The read stream will <b>not be owned</b> by the parser, it will still be managed (i.e.
  * closed if end-of-stream is reacher, or parser close method called) if (and only if) {@link
  * com.fasterxml.jackson.core.JsonParser.Feature#AUTO_CLOSE_SOURCE} is enabled.
  *
  * @param r Reader to use for reading JSON content to parse
  * @since 2.1
  */
 public JsonParser createParser(Reader r) throws IOException, JsonParseException {
   // false -> we do NOT own Reader (did not create it)
   IOContext ctxt = _createContext(r, false);
   // [JACKSON-512]: allow wrapping with InputDecorator
   if (_inputDecorator != null) {
     r = _inputDecorator.decorate(ctxt, r);
   }
   return _createParser(r, ctxt);
 }
示例#3
0
 /**
  * Method for constructing parser for parsing contents of given String.
  *
  * @since 2.1
  */
 public JsonParser createParser(String content) throws IOException, JsonParseException {
   Reader r = new StringReader(content);
   // true -> we own the Reader (and must close); not a big deal
   IOContext ctxt = _createContext(r, true);
   // [JACKSON-512]: allow wrapping with InputDecorator
   if (_inputDecorator != null) {
     r = _inputDecorator.decorate(ctxt, r);
   }
   return _createParser(r, ctxt);
 }
示例#4
0
 /**
  * Method for constructing JSON parser instance to parse contents of resource reference by given
  * URL. Encoding is auto-detected from contents according to JSON specification recommended
  * mechanism.
  *
  * <p>Underlying input stream (needed for reading contents) will be <b>owned</b> (and managed,
  * i.e. closed as need be) by the parser, since caller has no access to it.
  *
  * @param url URL pointing to resource that contains JSON content to parse
  * @since 2.1
  */
 public JsonParser createParser(URL url) throws IOException, JsonParseException {
   // true, since we create InputStream from URL
   IOContext ctxt = _createContext(url, true);
   InputStream in = _optimizedStreamFromURL(url);
   // [JACKSON-512]: allow wrapping with InputDecorator
   if (_inputDecorator != null) {
     in = _inputDecorator.decorate(ctxt, in);
   }
   return _createParser(in, ctxt);
 }
示例#5
0
 /**
  * Method for constructing parser for parsing the contents of given byte array.
  *
  * @since 2.1
  */
 public JsonParser createParser(byte[] data) throws IOException, JsonParseException {
   IOContext ctxt = _createContext(data, true);
   // [JACKSON-512]: allow wrapping with InputDecorator
   if (_inputDecorator != null) {
     InputStream in = _inputDecorator.decorate(ctxt, data, 0, data.length);
     if (in != null) {
       return _createParser(in, ctxt);
     }
   }
   return _createParser(data, 0, data.length, ctxt);
 }
示例#6
0
 /**
  * Method for constructing JSON parser instance to parse contents of specified file. Encoding is
  * auto-detected from contents according to JSON specification recommended mechanism.
  *
  * <p>Underlying input stream (needed for reading contents) will be <b>owned</b> (and managed,
  * i.e. closed as need be) by the parser, since caller has no access to it.
  *
  * @param f File that contains JSON content to parse
  * @since 2.1
  */
 @SuppressWarnings("resource")
 public JsonParser createParser(File f) throws IOException, JsonParseException {
   // true, since we create InputStream from File
   IOContext ctxt = _createContext(f, true);
   InputStream in = new FileInputStream(f);
   // [JACKSON-512]: allow wrapping with InputDecorator
   if (_inputDecorator != null) {
     in = _inputDecorator.decorate(ctxt, in);
   }
   return _createParser(in, ctxt);
 }