diff options
author | Charles Oliver Nutter <headius@headius.com> | 2021-02-25 14:34:11 -0600 |
---|---|---|
committer | Charles Oliver Nutter <headius@headius.com> | 2021-02-25 14:55:39 -0600 |
commit | 5d734aab8fad9d42b80bff3ba0a76254c3509a66 (patch) | |
tree | 5f7b217d997b142f022859cb64325fb8af1135f4 | |
parent | d2f5e1d18040ddfa6a4e7f746b29d4d8a78c3ebf (diff) | |
download | psych-5d734aab8fad9d42b80bff3ba0a76254c3509a66.zip |
Flush writer after each emit
OutputStreamWriter from JDK buffers outgoing bytes with a 8k
buffer, which causes some small document emits to never make it
into the outgoing stream unless that stream gets flushed or
closed.
-rw-r--r-- | ext/java/org/jruby/ext/psych/PsychEmitter.java | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/ext/java/org/jruby/ext/psych/PsychEmitter.java b/ext/java/org/jruby/ext/psych/PsychEmitter.java index ecaf2e5..ec71b93 100644 --- a/ext/java/org/jruby/ext/psych/PsychEmitter.java +++ b/ext/java/org/jruby/ext/psych/PsychEmitter.java @@ -336,6 +336,9 @@ public class PsychEmitter extends RubyObject { if (emitter == null) throw context.runtime.newRuntimeError("uninitialized emitter"); emitter.emit(event); + + // flush writer after each emit + writer.flush(); } catch (IOException ioe) { throw context.runtime.newIOErrorFromException(ioe); } catch (EmitterException ee) { @@ -349,10 +352,12 @@ public class PsychEmitter extends RubyObject { Encoding encoding = PsychLibrary.YAMLEncoding.values()[(int)_encoding.convertToInteger().getLongValue()].encoding; Charset charset = context.runtime.getEncodingService().charsetForEncoding(encoding); - emitter = new Emitter(new OutputStreamWriter(new IOOutputStream(io, encoding), charset), options); + writer = new OutputStreamWriter(new IOOutputStream(io, encoding), charset); + emitter = new Emitter(writer, options); } Emitter emitter; + Writer writer; DumperOptions options = new DumperOptions(); IRubyObject io; |