From 5d734aab8fad9d42b80bff3ba0a76254c3509a66 Mon Sep 17 00:00:00 2001 From: Charles Oliver Nutter Date: Thu, 25 Feb 2021 14:34:11 -0600 Subject: 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. --- ext/java/org/jruby/ext/psych/PsychEmitter.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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; -- cgit v1.2.3