[英]Jruby unzip class with each method
I am trying to write a JRuby script to unzip and parse bunch of archived log files (each log is a zip file). 我试图编写一个JRuby脚本来解压缩和解析一堆归档日志文件(每个日志都是一个zip文件)。 it can be easily implemented like this.
这样可以很容易地实现。
zipfile = java.util.zip::ZipFile.new(java.io::File.new(@zipfile))
entries = zipfile.entries
while entries.hasMoreElements
entry = entries.nextElement
is = zipfile.getInputStream(entry)
bis = java.io::BufferedInputStream.new(is)
br = java.io::BufferedReader.new(java.io::InputStreamReader.new(bis))
while (line = br.readLine()) != nil
/parsing line here/
end
end
end
but the code looks really messy. 但是代码看起来真的很乱。 what I really want is a unzipper class which can be used like, btw the log file can be huge, so loading them all in memory is not a good option.
我真正想要的是一个可以使用的解压缩类,但日志文件可能很大,因此将它们全部加载到内存中并不是一个好选择。 ideally it only pull the next line whenever each is triggered
理想情况下,它仅在每次触发时才拉下一行
unzipped = Unzipper.new(zipped_log_file_name)
unzipped.each do |x|
/parsing line here/
end
尝试gem rubyzip
具有更多ruby-sh API http://rubydoc.info/gems/rubyzip/1.1.0/frames
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.