lib/scout/open/stream.rb in scout-gear-7.2.0 vs lib/scout/open/stream.rb in scout-gear-7.3.0
- old
+ new
@@ -52,15 +52,13 @@
into_path, into = into, File.open(into, 'w')
end
into_close = false unless into.respond_to? :close
- begin
- while c = io.readpartial(BLOCK_SIZE)
- into << c if into
- end
- rescue EOFError
+ while c = io.read(BLOCK_SIZE)
+ into << c if into
+ break if io.closed?
end
io.join if io.respond_to? :join
io.close unless io.closed?
into.join if into and into_close and into.respond_to?(:joined?) and not into.joined?
@@ -118,16 +116,14 @@
when String === content
File.open(tmp_path, 'wb') do |f| f.write content end
when (IO === content or StringIO === content or File === content)
Open.write(tmp_path) do |f|
#f.sync = true
- begin
- while block = content.readpartial(BLOCK_SIZE)
- f.write block
- end
- rescue EOFError
- end
+ while block = content.read(BLOCK_SIZE)
+ f.write block
+ break if content.closed?
+ end
end
else
File.open(tmp_path, 'wb') do |f| end
end
@@ -288,26 +284,24 @@
begin
Thread.current.report_on_exception = false
Thread.current["name"] = "Splitter #{Log.fingerprint stream}"
skip = [false] * num
- begin
- while block = stream.readpartial(BLOCK_SIZE)
+ while block = stream.read(BLOCK_SIZE)
- in_pipes.each_with_index do |sin,i|
- begin
- sin.write block
- rescue IOError
- Log.warn("Tee stream #{i} #{Log.fingerprint stream} IOError: #{$!.message} (#{Log.fingerprint sin})");
- skip[i] = true
- rescue
- Log.warn("Tee stream #{i} #{Log.fingerprint stream} Exception: #{$!.message} (#{Log.fingerprint sin})");
- raise $!
- end unless skip[i]
- end
+ in_pipes.each_with_index do |sin,i|
+ begin
+ sin.write block
+ rescue IOError
+ Log.warn("Tee stream #{i} #{Log.fingerprint stream} IOError: #{$!.message} (#{Log.fingerprint sin})");
+ skip[i] = true
+ rescue
+ Log.warn("Tee stream #{i} #{Log.fingerprint stream} Exception: #{$!.message} (#{Log.fingerprint sin})");
+ raise $!
+ end unless skip[i]
end
- rescue IOError
+ break if stream.closed?
end
stream.join if stream.respond_to? :join
stream.close unless stream.closed?
in_pipes.first.close unless in_pipes.first.closed?
@@ -395,10 +389,10 @@
more = stream.read(missing)
str << more
end
str
end
-
+
def self.sort_stream(stream, header_hash = "#", cmd_args = "-u")
Open.open_pipe do |sin|
line = stream.gets
while line =~ /^#{header_hash}/ do
sin.puts line