21
21
package org .logstash .common ;
22
22
23
23
import org .jruby .Ruby ;
24
- import org .jruby .RubyArray ;
25
24
import org .jruby .RubyClass ;
26
25
import org .jruby .RubyEncoding ;
27
26
import org .jruby .RubyObject ;
@@ -41,16 +40,6 @@ public class BufferedTokenizerExt extends RubyObject {
41
40
42
41
private static final long serialVersionUID = 1L ;
43
42
44
- // private static final RubyString NEW_LINE = (RubyString) RubyUtil.RUBY.newString("\n").
45
- // freeze(RubyUtil.RUBY.getCurrentContext());
46
-
47
- // private @SuppressWarnings("rawtypes") RubyArray input = RubyUtil.RUBY.newArray();
48
- // private StringBuilder headToken = new StringBuilder();
49
- // private RubyString delimiter = NEW_LINE;
50
- // private int sizeLimit;
51
- // private boolean hasSizeLimit;
52
- // private int inputSize;
53
- // private boolean bufferFullErrorNotified = false;
54
43
private String encodingName ;
55
44
private transient BufferedTokenizer tokenizer ;
56
45
@@ -60,19 +49,6 @@ public BufferedTokenizerExt(final Ruby runtime, final RubyClass metaClass) {
60
49
61
50
@ JRubyMethod (name = "initialize" , optional = 2 )
62
51
public IRubyObject init (final ThreadContext context , IRubyObject [] args ) {
63
- // if (args.length >= 1) {
64
- // this.delimiter = args[0].convertToString();
65
- // }
66
- // if (args.length == 2) {
67
- // final int sizeLimit = args[1].convertToInteger().getIntValue();
68
- // if (sizeLimit <= 0) {
69
- // throw new IllegalArgumentException("Size limit must be positive");
70
- // }
71
- // this.sizeLimit = sizeLimit;
72
- // this.hasSizeLimit = true;
73
- // }
74
- // this.inputSize = 0;
75
-
76
52
String delimiter = "\n " ;
77
53
if (args .length >= 1 ) {
78
54
delimiter = args [0 ].convertToString ().asJavaString ();
@@ -106,7 +82,7 @@ public IRubyObject extract(final ThreadContext context, IRubyObject data) {
106
82
107
83
Iterable <String > extractor = tokenizer .extract (data .asJavaString ());
108
84
109
-
85
+ // return an iterator that does the encoding conversion
110
86
IRubyObject rubyIterable = RubyUtil .toRubyObject (new Iterable <CharSequence >() {
111
87
@ Override
112
88
public Iterator <CharSequence > iterator () {
@@ -120,68 +96,6 @@ public CharSequence next() {
120
96
});
121
97
122
98
return rubyIterable ;
123
-
124
- // final RubyArray entities = data.convertToString().split(delimiter, -1);
125
- // if (!bufferFullErrorNotified) {
126
- // input.clear();
127
- // input.concat(entities);
128
- // } else {
129
- // // after a full buffer signal
130
- // if (input.isEmpty()) {
131
- // // after a buffer full error, the remaining part of the line, till next delimiter,
132
- // // has to be consumed, unless the input buffer doesn't still contain fragments of
133
- // // subsequent tokens.
134
- // entities.shift(context);
135
- // input.concat(entities);
136
- // } else {
137
- // // merge last of the input with first of incoming data segment
138
- // if (!entities.isEmpty()) {
139
- // RubyString last = ((RubyString) input.pop(context));
140
- // RubyString nextFirst = ((RubyString) entities.shift(context));
141
- // entities.unshift(last.concat(nextFirst));
142
- // input.concat(entities);
143
- // }
144
- // }
145
- // }
146
- //
147
- // if (hasSizeLimit) {
148
- // if (bufferFullErrorNotified) {
149
- // bufferFullErrorNotified = false;
150
- // if (input.isEmpty()) {
151
- // return RubyUtil.RUBY.newArray();
152
- // }
153
- // }
154
- // final int entitiesSize = ((RubyString) input.first()).size();
155
- // if (inputSize + entitiesSize > sizeLimit) {
156
- // bufferFullErrorNotified = true;
157
- // headToken = new StringBuilder();
158
- // String errorMessage = String.format("input buffer full, consumed token which exceeded the sizeLimit %d; inputSize: %d, entitiesSize %d", sizeLimit, inputSize, entitiesSize);
159
- // inputSize = 0;
160
- // input.shift(context); // consume the token fragment that generates the buffer full
161
- // throw new IllegalStateException(errorMessage);
162
- // }
163
- // this.inputSize = inputSize + entitiesSize;
164
- // }
165
- //
166
- // if (input.getLength() < 2) {
167
- // // this is a specialization case which avoid adding and removing from input accumulator
168
- // // when it contains just one element
169
- // headToken.append(input.shift(context)); // remove head
170
- // return RubyUtil.RUBY.newArray();
171
- // }
172
- //
173
- // if (headToken.length() > 0) {
174
- // // if there is a pending token part, merge it with the first token segment present
175
- // // in the accumulator, and clean the pending token part.
176
- // headToken.append(input.shift(context)); // append buffer to first element and
177
- // // create new RubyString with the data specified encoding
178
- // RubyString encodedHeadToken = toEncodedRubyString(context, headToken.toString());
179
- // input.unshift(encodedHeadToken); // reinsert it into the array
180
- // headToken = new StringBuilder();
181
- // }
182
- // headToken.append(input.pop(context)); // put the leftovers in headToken for later
183
- // inputSize = headToken.length();
184
- // return input;
185
99
}
186
100
187
101
private RubyString toEncodedRubyString (ThreadContext context , String input ) {
@@ -214,31 +128,10 @@ public IRubyObject flush(final ThreadContext context) {
214
128
}
215
129
return RubyUtil .toRubyObject (s );
216
130
}
217
-
218
- // final IRubyObject buffer = RubyUtil.toRubyObject(headToken.toString());
219
- // headToken = new StringBuilder();
220
- // inputSize = 0;
221
- //
222
- // // create new RubyString with the last data specified encoding, if exists
223
- // RubyString encodedHeadToken;
224
- // if (encodingName != null) {
225
- // encodedHeadToken = toEncodedRubyString(context, buffer.toString());
226
- // } else {
227
- // // When used with TCP input it could be that on socket connection the flush method
228
- // // is invoked while no invocation of extract, leaving the encoding name unassigned.
229
- // // In such case also the headToken must be empty
230
- // if (!buffer.toString().isEmpty()) {
231
- // throw new IllegalStateException("invoked flush with unassigned encoding but not empty head token, this shouldn't happen");
232
- // }
233
- // encodedHeadToken = (RubyString) buffer;
234
- // }
235
- //
236
- // return encodedHeadToken;
237
131
}
238
132
239
133
@ JRubyMethod (name = "empty?" )
240
134
public IRubyObject isEmpty (final ThreadContext context ) {
241
- // return RubyUtil.RUBY.newBoolean(headToken.toString().isEmpty() && (inputSize == 0));
242
135
return RubyUtil .RUBY .newBoolean (tokenizer .isEmpty ());
243
136
}
244
137
0 commit comments