Esempio n. 1
0
  /** Creates a smile pipe from an {@link InputStream}. */
  public static Pipe newPipe(InputStream in, boolean numeric) throws IOException {
    final IOContext context = new IOContext(DEFAULT_SMILE_FACTORY._getBufferRecycler(), in, false);
    final SmileParser parser = newSmileParser(in, context.allocReadIOBuffer(), 0, 0, true, context);

    return JsonIOUtil.newPipe(parser, numeric);
    // return JsonIOUtil.newPipe(DEFAULT_SMILE_FACTORY.createJsonParser(in), numeric);
  }
Esempio n. 2
0
  /** Parses the {@code messages} from the stream using the given {@code schema}. */
  public static <T> List<T> parseListFrom(InputStream in, Schema<T> schema, boolean numeric)
      throws IOException {
    final IOContext context = new IOContext(DEFAULT_SMILE_FACTORY._getBufferRecycler(), in, false);
    final SmileParser parser = newSmileParser(in, context.allocReadIOBuffer(), 0, 0, true, context);

    // final SmileParser parser = DEFAULT_SMILE_FACTORY.createJsonParser(in);
    try {
      return JsonIOUtil.parseListFrom(parser, schema, numeric);
    } finally {
      parser.close();
    }
  }
Esempio n. 3
0
  /** Serializes the {@code messages} into the stream using the given schema. */
  public static <T> void writeListTo(
      OutputStream out, List<T> messages, Schema<T> schema, boolean numeric) throws IOException {
    final IOContext context = new IOContext(DEFAULT_SMILE_FACTORY._getBufferRecycler(), out, false);

    final SmileGenerator generator =
        newSmileGenerator(out, context.allocWriteEncodingBuffer(), 0, true, context);

    // final SmileGenerator generator = DEFAULT_SMILE_FACTORY.createJsonGenerator(out);
    try {
      JsonIOUtil.writeListTo(generator, messages, schema, numeric);
    } finally {
      generator.close();
    }
  }
 /**
  * Method called to close this generator, so that no more content can be written.
  *
  * <p>Whether the underlying target (stream, writer) gets closed depends on whether this generator
  * either manages the target (i.e. is the only one with access to the target -- case if caller
  * passes a reference to the resource such as File, but not stream); or has feature {@link
  * Feature#AUTO_CLOSE_TARGET} enabled. If either of above is true, the target is also closed.
  * Otherwise (not managing, feature not enabled), target is not closed.
  */
 @Override
 public void close() throws IOException {
   if (!closed) {
     closed = true;
     if (ioContext.isResourceManaged()) outputStream.close();
     else outputStream.flush();
   }
 }
Esempio n. 5
0
 @Override
 protected void _releaseBuffers() {
   char[] buf = _outputBuffer;
   if (buf != null) {
     _outputBuffer = null;
     _ioContext.releaseConcatBuffer(buf);
   }
 }
  @Override
  public void close() throws IOException {
    super.close();

    // Let's mark row as closed, if we had any...
    finishRow();
    _writer.close(
        _ioContext.isResourceManaged() || isEnabled(JsonGenerator.Feature.AUTO_CLOSE_TARGET));
  }
Esempio n. 7
0
 public RisonGenerator(
     IOContext ctxt, int jsonFeatures, int risonFeatures, ObjectCodec codec, Writer w) {
   super(jsonFeatures, codec);
   _ioContext = ctxt;
   _writer = w;
   _risonFeatures = risonFeatures;
   _outputBuffer = ctxt.allocConcatBuffer();
   _outputEnd = _outputBuffer.length;
 }
 public ByteSourceJsonBootstrapper(IOContext iocontext, InputStream inputstream)
 {
     _bigEndian = true;
     _bytesPerChar = 0;
     _context = iocontext;
     _in = inputstream;
     _inputBuffer = iocontext.allocReadIOBuffer();
     _inputPtr = 0;
     _inputEnd = 0;
     _inputProcessed = 0;
     _bufferRecyclable = true;
 }
Esempio n. 9
0
  @Override
  public void close() throws IOException {
    super.close();

    /* 05-Dec-2008, tatu: To add [JACKSON-27], need to close open
     *   scopes.
     */
    // First: let's see that we still have buffers...
    if (_outputBuffer != null && isEnabled(JsonGenerator.Feature.AUTO_CLOSE_JSON_CONTENT)) {
      while (true) {
        JsonStreamContext ctxt = getOutputContext();
        if (ctxt.inArray()) {
          writeEndArray();
        } else if (ctxt.inObject()) {
          writeEndObject();
        } else {
          break;
        }
      }
    }
    _flushBuffer();

    /* 25-Nov-2008, tatus: As per [JACKSON-16] we are not to call close()
     *   on the underlying Reader, unless we "own" it, or auto-closing
     *   feature is enabled.
     *   One downside: when using UTF8Writer, underlying buffer(s)
     *   may not be properly recycled if we don't close the writer.
     */
    if (_writer != null) {
      if (_ioContext.isResourceManaged() || isEnabled(JsonGenerator.Feature.AUTO_CLOSE_TARGET)) {
        _writer.close();
      } else if (isEnabled(JsonGenerator.Feature.FLUSH_PASSED_TO_STREAM)) {
        // If we can't close it, we should at least flush
        _writer.flush();
      }
    }
    // Internal buffer(s) generator has can now be released as well
    _releaseBuffers();
  }