Class: Splunk::XMLDTDFilter
- Inherits:
-
IO
- Object
- IO
- Splunk::XMLDTDFilter
- Defined in:
- lib/splunk-sdk-ruby/resultsreader.rb
Overview
Stream transformer that filters out XML DTD definitions.
XMLDTDFilter takes anything between <? and > to be a DTD. It does no escaping of quoted text.
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(stream) ⇒ XMLDTDFilter
constructor
A new instance of XMLDTDFilter.
- #read(n = nil) ⇒ Object
Constructor Details
#initialize(stream) ⇒ XMLDTDFilter
Returns a new instance of XMLDTDFilter.
678 679 680 681 |
# File 'lib/splunk-sdk-ruby/resultsreader.rb', line 678 def initialize(stream) @stream = stream @peeked_char = nil end |
Instance Method Details
#close ⇒ Object
683 684 685 |
# File 'lib/splunk-sdk-ruby/resultsreader.rb', line 683 def close() @stream.close() end |
#read(n = nil) ⇒ Object
687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 |
# File 'lib/splunk-sdk-ruby/resultsreader.rb', line 687 def read(n=nil) response = "" while n.nil? or n > 0 # First use any element we already peeked at. if !@peeked_char.nil? response << @peeked_char @peeked_char = nil if !n.nil? n -= 1 end next end c = @stream.read(1) if c.nil? # We've reached the end of the stream break elsif c == "<" # We might have a DTD definition d = @stream.read(1) || "" if d == "?" # It's a DTD. Skip until we've consumed a >. while true q = @stream.read(1) if q == ">" break end end else # It's not a DTD. Push that ? into lookahead. @peeked_char = d response << c if !n.nil? n = n-1 end end else # No special behavior response << c if !n.nil? n -= 1 end end end return response end |