/** * Method for constructing parser for parsing contents of given char array. * * @since 2.4 */ public JsonParser createParser(char[] content, int offset, int len) throws IOException { if (_inputDecorator != null) { // easier to just wrap in a Reader than extend InputDecorator return createParser(new CharArrayReader(content, offset, len)); } return _createParser(content, offset, len, _createContext(content, true), // important: buffer is NOT recyclable, as it's from caller false); }
/** * Optional method for constructing parser for reading contents from specified {@link DataInput} * instance. *<p> * If this factory does not support {@link DataInput} as source, * will throw {@link UnsupportedOperationException} * * @since 2.8 */ public JsonParser createParser(DataInput in) throws IOException { IOContext ctxt = _createContext(in, false); return _createParser(_decorate(in, ctxt), ctxt); }
/** * Method for constructing parser for parsing * contents of given String. * * @since 2.1 */ public JsonParser createParser(String content) throws IOException, JsonParseException { final int strLen = content.length(); // Actually, let's use this for medium-sized content, up to 64kB chunk (32kb char) if ((_inputDecorator != null) || (strLen > 0x8000) || !canUseCharArrays()) { // easier to just wrap in a Reader than extend InputDecorator; or, if content // is too long for us to copy it over return createParser(new StringReader(content)); } IOContext ctxt = _createContext(content, true); char[] buf = ctxt.allocTokenBuffer(strLen); content.getChars(0, strLen, buf, 0); return _createParser(buf, 0, strLen, ctxt, true); }
/** * Method for constructing JSON parser instance to parse * contents of specified file. * *<p> * Encoding is auto-detected from contents according to JSON * specification recommended mechanism. Json specification * supports only UTF-8, UTF-16 and UTF-32 as valid encodings, * so auto-detection implemented only for this charsets. * For other charsets use {@link #createParser(java.io.Reader)}. * *<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 */ 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); return _createParser(_decorate(in, ctxt), ctxt); }
/** * 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); return _createParser(_decorate(r, ctxt), ctxt); }
/** * Method for constructing JSON generator for writing JSON content * using specified Writer. *<p> * Underlying stream <b>is NOT owned</b> by the generator constructed, * so that generator will NOT close the Reader when * {@link JsonGenerator#close} is called (unless auto-closing * feature, * {@link com.fasterxml.jackson.core.JsonGenerator.Feature#AUTO_CLOSE_TARGET} is enabled). * Using application needs to close it explicitly. * * @since 2.1 * * @param w Writer to use for writing JSON content */ public JsonGenerator createGenerator(Writer w) throws IOException { IOContext ctxt = _createContext(w, false); return _createGenerator(_decorate(w, ctxt), ctxt); }
/** * 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. Json specification * supports only UTF-8, UTF-16 and UTF-32 as valid encodings, * so auto-detection implemented only for this charsets. * For other charsets use {@link #createParser(java.io.Reader)}. * * @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); return _createParser(_decorate(in, ctxt), ctxt); }
/** * 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); 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); }
/** * Method for constructing parser for parsing * the contents of given byte array. * * @param data Buffer that contains data to parse * @param offset Offset of the first data byte within buffer * @param len Length of contents to parse within buffer * * @since 2.1 */ public JsonParser createParser(byte[] data, int offset, int len) throws IOException, JsonParseException { IOContext ctxt = _createContext(data, true); // [JACKSON-512]: allow wrapping with InputDecorator if (_inputDecorator != null) { InputStream in = _inputDecorator.decorate(ctxt, data, offset, len); if (in != null) { return _createParser(in, ctxt); } } return _createParser(data, offset, len, ctxt); }
/** * Method for constructing JSON parser instance to parse * contents of resource reference by given URL. * *<p> * Encoding is auto-detected from contents according to JSON * specification recommended mechanism. Json specification * supports only UTF-8, UTF-16 and UTF-32 as valid encodings, * so auto-detection implemented only for this charsets. * For other charsets use {@link #createParser(java.io.Reader)}. * *<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); return _createParser(_decorate(in, ctxt), ctxt); }
/** * Method for constructing JSON generator for writing JSON content * to specified file, overwriting contents it might have (or creating * it if such file does not yet exist). * Encoding to use must be specified, and needs to be one of available * types (as per JSON specification). *<p> * Underlying stream <b>is owned</b> by the generator constructed, * i.e. generator will handle closing of file when * {@link JsonGenerator#close} is called. * * @param f File to write contents to * @param enc Character encoding to use * * @since 2.1 */ public JsonGenerator createGenerator(File f, JsonEncoding enc) throws IOException { OutputStream out = new FileOutputStream(f); // true -> yes, we have to manage the stream since we created it IOContext ctxt = _createContext(out, true); ctxt.setEncoding(enc); if (enc == JsonEncoding.UTF8) { return _createUTF8Generator(_decorate(out, ctxt), ctxt); } Writer w = _createWriter(out, enc, ctxt); return _createGenerator(_decorate(w, ctxt), ctxt); }
IOContext ctxt = _createContext(out, false); ctxt.setEncoding(enc); if (enc == JsonEncoding.UTF8) {
@Override protected IOContext _createContext(Object srcRef, boolean resourceManaged) { return super._createContext(srcRef, resourceManaged); }
@Override protected IOContext _createContext(Object srcRef, boolean resourceManaged) { return super._createContext(srcRef, resourceManaged); }
/** * Method for constructing parser for parsing contents of given char array. * * @since 2.4 */ public JsonParser createParser(char[] content, int offset, int len) throws IOException { if (_inputDecorator != null) { // easier to just wrap in a Reader than extend InputDecorator return createParser(new CharArrayReader(content, offset, len)); } return _createParser(content, offset, len, _createContext(content, true), // important: buffer is NOT recyclable, as it's from caller false); }
/** * Method for constructing parser for parsing contents of given char array. * * @since 2.4 */ public JsonParser createParser(char[] content, int offset, int len) throws IOException { if (_inputDecorator != null) { // easier to just wrap in a Reader than extend InputDecorator return createParser(new CharArrayReader(content, offset, len)); } return _createParser(content, offset, len, _createContext(content, true), // important: buffer is NOT recyclable, as it's from caller false); }
/** * Method for constructing parser for parsing contents of given char array. * * @since 2.4 */ public JsonParser createParser(char[] content, int offset, int len) throws IOException { if (_inputDecorator != null) { // easier to just wrap in a Reader than extend InputDecorator return createParser(new CharArrayReader(content, offset, len)); } return _createParser(content, offset, len, _createContext(content, true), // important: buffer is NOT recyclable, as it's from caller false); }
/** * Method for constructing parser for parsing contents of given char array. * * @since 2.4 */ public JsonParser createParser(char[] content, int offset, int len) throws IOException { if (_inputDecorator != null) { // easier to just wrap in a Reader than extend InputDecorator return createParser(new CharArrayReader(content, offset, len)); } return _createParser(content, offset, len, _createContext(content, true), // important: buffer is NOT recyclable, as it's from caller false); }
/** * @since 2.8 */ public JsonParser createParser(DataInput in) throws IOException { IOContext ctxt = _createContext(in, false); return _createParser(_decorate(in, ctxt), ctxt); }
/** * Optional method for constructing parser for reading contents from specified {@link DataInput} * instance. *<p> * If this factory does not support {@link DataInput} as source, * will throw {@link UnsupportedOperationException} * * @since 2.8 */ public JsonParser createParser(DataInput in) throws IOException { IOContext ctxt = _createContext(in, false); return _createParser(_decorate(in, ctxt), ctxt); }