Skip to content

Commit ca2c4dd

Browse files
committed
Fixed flush behavior
1 parent 5a98b0b commit ca2c4dd

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

logstash-core/src/main/java/org/logstash/common/BufferedTokenizer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public void append(String data) {
8484
}
8585

8686
public String flush() {
87-
return accumulator.toString();
87+
return accumulator.substring(currentIdx);
8888
}
8989

9090
@Override

logstash-core/src/main/java/org/logstash/common/BufferedTokenizerExt.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,20 @@ private RubyString toEncodedRubyString(ThreadContext context, String input) {
201201
@JRubyMethod
202202
public IRubyObject flush(final ThreadContext context) {
203203
String s = tokenizer.flush();
204-
return RubyUtil.toRubyObject(s);
204+
205+
// create new RubyString with the last data specified encoding, if exists
206+
if (encodingName != null) {
207+
return toEncodedRubyString(context, s);
208+
} else {
209+
// When used with TCP input it could be that on socket connection the flush method
210+
// is invoked while no invocation of extract, leaving the encoding name unassigned.
211+
// In such case also the headToken must be empty
212+
if (!s.isEmpty()) {
213+
throw new IllegalStateException("invoked flush with unassigned encoding but not empty head token, this shouldn't happen");
214+
}
215+
return RubyUtil.toRubyObject(s);
216+
}
217+
205218
// final IRubyObject buffer = RubyUtil.toRubyObject(headToken.toString());
206219
// headToken = new StringBuilder();
207220
// inputSize = 0;

0 commit comments

Comments
 (0)