This class is a buffered stream parser that is capable of receiving a stream of text and splitting it into lines up to a configurable max length. If its buffer fills up without receiving a newline, the entire buffer is discarded.
Create a new instance.
@param max_line_length [Integer] maximum line length @param line_handler [process] a line handler
# File lib/openshift-origin-node/model/application_container_ext/metrics.rb, line 43 def initialize(max_line_length, line_handler) @buf = "" @max_line_length = max_line_length @discard_current = false @line_handler = line_handler end
Receive stream input.
If the input contains a newline, invoke the line_handler's `process` method, passing it the complete line.
If the input does not contain a newline:
if the buffer's length + the input's length > maximum line length, discard the buffer's contents.
otherwise, append the input to the buffer and wait to be invoked again.
# File lib/openshift-origin-node/model/application_container_ext/metrics.rb, line 60 def <<(input) s = StringScanner.new(input) loop do line = s.scan_until(NEWLINE_REGEX) if line @discard_current = true if @buf.length + line.length > @max_line_length else if @buf.length + s.rest.length > @max_line_length @discard_current = true else @buf += s.rest end break end unless @discard_current @line_handler.process(@buf + line.chomp) end @discard_current = false @buf = "" end end
Generated with the Darkfish Rdoc Generator 2.