@Override 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(f, true); ctxt.setEncoding(enc); return _createGenerator(_createWriter(_decorate(out, ctxt), enc, ctxt), ctxt); }
@Override public YAMLGenerator createGenerator(OutputStream out, JsonEncoding enc) throws IOException { // false -> we won't manage the stream unless explicitly directed to IOContext ctxt = _createContext(out, false); ctxt.setEncoding(enc); return _createGenerator(_createWriter(_decorate(out, ctxt), enc, ctxt), ctxt); }
@Override 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(f, true); ctxt.setEncoding(enc); return _createGenerator(_createWriter(_decorate(out, ctxt), enc, ctxt), ctxt); }
/** * Creates a {@link UTF8JsonGenerator} for the outputstream with the supplied buf {@code outBuffer} to use. */ static UTF8JsonGenerator newJsonGenerator(OutputStream out, byte[] buf, int offset, boolean bufferRecyclable, IOContext context) { context.setEncoding(JsonEncoding.UTF8); return new UTF8JsonGenerator(context, DEFAULT_JSON_FACTORY.getGeneratorFeatures(), DEFAULT_JSON_FACTORY.getCodec(), out, buf, offset, bufferRecyclable); }
@Override public YAMLGenerator createGenerator(OutputStream out, JsonEncoding enc) throws IOException { // false -> we won't manage the stream unless explicitly directed to IOContext ctxt = _createContext(out, false); ctxt.setEncoding(enc); return _createGenerator(_createWriter(_decorate(out, ctxt), enc, 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); }
_context.setEncoding(enc); return enc;
ctxt.setEncoding(enc); if (enc == JsonEncoding.UTF8) { return _createUTF8Generator(_decorate(out, ctxt), ctxt);
_context.setEncoding(enc); return enc;
@Override public BsonGenerator createGenerator(File f, JsonEncoding enc) throws IOException { OutputStream out = new FileOutputStream(f); IOContext ctxt = _createContext(out, true); ctxt.setEncoding(enc); if (enc == JsonEncoding.UTF8 && _outputDecorator != null) { out = _outputDecorator.decorate(ctxt, out); } return createGenerator(out, enc); }
@Override public BsonGenerator createGenerator(File f, JsonEncoding enc) throws IOException { OutputStream out = new FileOutputStream(f); IOContext ctxt = _createContext(out, true); ctxt.setEncoding(enc); if (enc == JsonEncoding.UTF8 && _outputDecorator != null) { out = _outputDecorator.decorate(ctxt, out); } return createGenerator(out, enc); }
@Override public BsonGenerator createGenerator(File f, JsonEncoding enc) throws IOException { OutputStream out = new FileOutputStream(f); IOContext ctxt = _createContext(out, true); ctxt.setEncoding(enc); if (enc == JsonEncoding.UTF8 && _outputDecorator != null) { out = _outputDecorator.decorate(ctxt, out); } return createGenerator(out, enc); }
@SuppressWarnings("resource") @Override public ToXmlGenerator 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); return new ToXmlGenerator(ctxt, _generatorFeatures, _xmlGeneratorFeatures, _objectCodec, _createXmlWriter(out)); }
@Override public CsvGenerator createGenerator(File f, JsonEncoding enc) throws IOException { OutputStream out = new FileOutputStream(f); // Important: make sure that we always auto-close stream we create: IOContext ctxt = _createContext(out, false); ctxt.setEncoding(enc); return _createGenerator(ctxt, _createWriter(_decorate(out, ctxt), enc, ctxt)); }
@Override public ProtobufGenerator createGenerator(OutputStream out, JsonEncoding enc) throws IOException { IOContext ctxt = _createContext(out, false); ctxt.setEncoding(enc); return _createProtobufGenerator(ctxt, _generatorFeatures, _objectCodec, _decorate(out, ctxt)); }
@Override public JsonGenerator createGenerator(OutputStream out, JsonEncoding enc) throws IOException { IOContext ctxt = _createContext(out, false); ctxt.setEncoding(enc); return _createJavaPropsGenerator(ctxt, _generatorFeatures, _objectCodec, _decorate(out, ctxt)); }
@Override public ToXmlGenerator createGenerator(OutputStream out, JsonEncoding enc) throws IOException { // false -> we won't manage the stream unless explicitly directed to IOContext ctxt = _createContext(out, false); ctxt.setEncoding(enc); return new ToXmlGenerator(ctxt, _generatorFeatures, _xmlGeneratorFeatures, _objectCodec, _createXmlWriter(out)); }
/** * Creates a {@link UTF8JsonGenerator} for the outputstream with the supplied buf {@code outBuffer} to use. */ static UTF8JsonGenerator newJsonGenerator(OutputStream out, byte[] buf, int offset, boolean bufferRecyclable, IOContext context) { context.setEncoding(JsonEncoding.UTF8); return new UTF8JsonGenerator(context, DEFAULT_JSON_FACTORY.getGeneratorFeatures(), DEFAULT_JSON_FACTORY.getCodec(), out, buf, offset, bufferRecyclable); }
@Override public CsvGenerator createGenerator(OutputStream out, JsonEncoding enc) throws IOException { // false -> we won't manage the stream unless explicitly directed to IOContext ctxt = _createContext(out, false); ctxt.setEncoding(enc); return _createGenerator(ctxt, _createWriter(_decorate(out, ctxt), JsonEncoding.UTF8, ctxt)); }
@Override public BsonGenerator createGenerator(OutputStream out, JsonEncoding enc) throws IOException { IOContext ctxt = _createContext(out, true); ctxt.setEncoding(enc); if (enc == JsonEncoding.UTF8 && _outputDecorator != null) { out = _outputDecorator.decorate(ctxt, out); } BsonGenerator g = new BsonGenerator(_generatorFeatures, _bsonGeneratorFeatures, out); ObjectCodec codec = getCodec(); if (codec != null) { g.setCodec(codec); } if (_characterEscapes != null) { g.setCharacterEscapes(_characterEscapes); } return g; }